Clone in a terminal:
Commit dea37d0
Johan Mattsson - 2012-07-15T17:41:58+00:00
dea37d060c832705277c41bae21b44bf7c4725a8johan.mattsson.m@gmail.com

new symbols for bezier control points

Changed files (7)

Diff

diff --git a/icons/active_edit_point_handle.png b/icons/active_edit_point_handle.pngnew file mode 100644index 0000000..0e82bc2Binary files /dev/null and b/icons/active_edit_point_handle.png differdiff --git a/icons/edit_point.png b/icons/edit_point.pngnew file mode 100644index 0000000..8da5bffBinary files /dev/null and b/icons/edit_point.png differdiff --git a/icons/edit_point_handle.png b/icons/edit_point_handle.pngnew file mode 100644index 0000000..5c58f4eBinary files /dev/null and b/icons/edit_point_handle.png differdiff --git a/src/EditPointHandle.vala b/src/EditPointHandle.valaindex 2d2625d..640b381 100644--- a/src/EditPointHandle.vala+++ b/src/EditPointHandle.vala@@ -35,11 +35,14 @@ class EditPointHandle  {  	static EditPoint none = new EditPoint (); +	public bool active;+ 	public EditPointHandle.empty() { 		this.parent = none; 		this.angle = 0; 		this.length = 10; 		this.type = PointType.LINE;+		this.active = false; 	} 	 	public EditPointHandle (EditPoint parent, double angle, double length) {@@ -47,6 +50,7 @@ class EditPointHandle  { 		this.angle = angle; 		this.length = length; 		this.type = PointType.LINE;+		this.active = false; 	}  	public void set_point_type (PointType point_type) {diff --git a/src/Path.vala b/src/Path.valaindex dcfb868..05ab4f7 100644--- a/src/Path.vala+++ b/src/Path.vala@@ -57,7 +57,18 @@ class Path { 	 	bool selected = false; 	+	private static ImageSurface? edit_point_image = null;+	private static ImageSurface? active_edit_point_image = null;+	private static ImageSurface? edit_point_handle_image = null;+	private static ImageSurface? active_edit_point_handle_image = null;+	 	public Path () {+		if (edit_point_image == null) {+			edit_point_image = Icons.get_icon ("edit_point.png");+			active_edit_point_image = Icons.get_icon ("active_edit_point.png");+			edit_point_handle_image = Icons.get_icon ("edit_point_handle.png");+			active_edit_point_handle_image = Icons.get_icon ("active_edit_point_handle.png");+		} 	}  	public void set_color (double r, double g, double b, double a) {@@ -119,8 +130,8 @@ class Path { 			draw_next (em, en, cr); 		} -		if (is_selected ()) {-			// fill path+		// fill path+		if (is_selected ()) {	 			cr.close_path (); 			cr.set_source_rgba (r, g, b, a); 			cr.fill ();@@ -143,7 +154,7 @@ class Path { 	} 	 	private void draw_next (EditPoint e, EditPoint en, Context cr) {-		if (en.right_handle.type == PointType.LINE && e.right_handle.type == PointType.LINE) {+		if (en.right_handle.type == PointType.LINE && e.left_handle.type == PointType.LINE) { 			draw_line (e, en, cr); 		} else { 			draw_curve (e, en, cr);@@ -260,7 +271,11 @@ class Path { 		draw_edit_point_center (e, cr); 	} 	-	public void draw_edit_point_handles (EditPoint e, Context cr) {+	public void draw_edit_point_handles (EditPoint e, Context cr)+		requires (active_edit_point_handle_image != null && edit_point_handle_image != null)+	{+		ImageSurface img_right, img_left;+ 		EditPoint handle_right = e.get_right_handle ().get_point (); 		EditPoint handle_left = e.get_left_handle ().get_point (); 			@@ -269,12 +284,42 @@ class Path { 		 		cr.stroke (); 		-		draw_edit_point_center (handle_right, cr);-		draw_edit_point_center (handle_left, cr);+		img_right = (e.get_right_handle ().active) ? (!) active_edit_point_handle_image : (!) edit_point_handle_image;+		img_left = (e.get_left_handle ().active) ? (!) active_edit_point_handle_image : (!) edit_point_handle_image;+		+		draw_img_center (cr, img_right, e.get_right_handle ().x (), e.get_right_handle ().y ());+		draw_img_center (cr, img_left, e.get_left_handle ().x (), e.get_left_handle ().y ());+	}++	public static void draw_edit_point_center (EditPoint e, Context cr) +		requires (active_edit_point_image != null && edit_point_image != null)+	{	+		ImageSurface img = (e.active) ? (!) active_edit_point_image : (!) edit_point_image;+		draw_img_center (cr, img, e.x, e.y); 	} 	+	public static void draw_img_center (Context cr, ImageSurface img, double x, double y) {+		Glyph g = MainWindow.get_current_glyph ();+		+		double ivz = 1 / g.view_zoom;++		double xc = g.allocation.width / 2.0;+		double yc = g.allocation.height / 2.0;++		cr.save ();++		cr.scale (ivz, ivz);+		+		x = xc + x - (img.get_width () / 2.0) * ivz; +		y = yc - y - (img.get_height () / 2.0) * ivz;+		+		cr.set_source_surface (img, x * g.view_zoom, y * g.view_zoom);+		cr.paint ();+		+		cr.restore ();		+	} 	-	public static void draw_edit_point_center (EditPoint e, Context cr) {+	public static void draw_edit_point_center_testing (EditPoint e, Context cr) { 		Glyph g = MainWindow.get_current_glyph (); 		 		double ivz = 1 / g.view_zoom;@@ -283,7 +328,7 @@ class Path { 		double yc = g.allocation.height / 2.0;  		double x = xc + e.x;-		double y = yc - e.y + 0.5;+		double y = yc - e.y;  		double thickness = (e.active) ? 5 * ivz : 4 * ivz; @@ -293,19 +338,20 @@ class Path { 			cr.set_source_rgba (e.r, e.g, e.b, e.a);  		cr.set_line_width (thickness);-		+ 		cr.new_path (); 		-		cr.move_to (x - 0.7 * ivz, y - 0.7 * ivz - 0.5);-		cr.line_to (x + 0.7 * ivz, y + 0.7 * ivz - 0.5);+		cr.move_to (x - 0.7 * ivz, y - 0.7 * ivz);+		cr.line_to (x + 0.7 * ivz, y + 0.7 * ivz); 		-		cr.move_to (x + 0.7 * ivz, y - 0.7 * ivz - 0.5);-		cr.line_to (x - 0.7 * ivz, y + 0.7 * ivz - 0.5);+		cr.move_to (x + 0.7 * ivz, y - 0.7 * ivz);+		cr.line_to (x - 0.7 * ivz, y + 0.7 * ivz); 		 		cr.close_path ();  		cr.stroke (); +		cr.save ();	 	} 	 	/** Returns true if there is an edit point at (p.x, p.y). */diff --git a/src/PenTool.vala b/src/PenTool.valaindex b6f1712..f98757f 100644--- a/src/PenTool.vala+++ b/src/PenTool.vala@@ -85,6 +85,7 @@ class PenTool : Tool { 		EditPoint ep; 		 		control_point_event (x, y);+		curve_active_corner_event (x, y);  		// show new point on path 		move_current_point_on_path (x, y);@@ -452,6 +453,24 @@ class PenTool : Tool { 		|| selected_corner.get_right_handle ().get_point ().is_close (x, y); 	} +	private void curve_active_corner_event (double x, double y) {+		EditPointHandle eh;+		+		active_handle.active = false;+		+		eh = selected_corner.get_left_handle ();+		if (eh.get_point ().is_close (x, y)) {+			eh.active = true;+			active_handle = eh;+		}+		+		eh = selected_corner.get_right_handle ();+		if (eh.get_point ().is_close (x, y)) {+			eh.active = true;+			active_handle = eh;	+		}+	}+ 	private void curve_corner_event (double x, double y) { 		EditPointHandle eh; 		diff --git a/src/Svg.vala b/src/Svg.valaindex ec9bc60..c41ad6b 100644--- a/src/Svg.vala+++ b/src/Svg.vala@@ -82,17 +82,22 @@ class Svg { 		close_path (svg); 	} -	private static void add_abs_next (EditPoint m, EditPoint e, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) {-		if (e.right_handle.type == PointType.LINE && m.left_handle.type == PointType.LINE) {-			add_abs_line_to (e, m, svg, g, do_glyph, scale);+	private static void add_abs_next (EditPoint start, EditPoint end, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) {+		if (start.right_handle.type == PointType.LINE && end.left_handle.type == PointType.LINE) {+			add_abs_line_to (end, start, svg, g, do_glyph, scale); 		} else {-			add_abs_path (e, m, svg, g, do_glyph, scale);+			add_abs_path (end, start, svg, g, do_glyph, scale); 		} 	}  	private static void add_abs_start (EditPoint ep, StringBuilder svg, Glyph g, bool do_glyph, double scale = 1) {		-		svg.append ("M");-		svg.append_printf ("0 0 ");+		double left = g.left_limit;+		double baseline = Supplement.get_current_font ().base_line;+		+		svg.append_printf ("M");++		svg.append_printf ("%s ",  round ((ep.x - left) * scale));+		svg.append_printf ("%s ",  round ((ep.y + baseline) * scale)); 	} 		 	private static void close_path (StringBuilder svg) {@@ -113,7 +118,6 @@ class Svg { 		double center_y = Glyph.yc (); 	 		if (!to_glyph) {-			print ("!to_glyph\n"); 			svg.append ("L"); 						 			svg.append_printf ("%s ", round ((xa - center_x - left) * scale));@@ -152,11 +156,6 @@ class Svg { 		double center_y = Glyph.yc (); 		 		if (!to_glyph) {-			svg.append_printf ("L");-			-			svg.append_printf ("%s ",  round ((xa - center_x - left) * scale));-			svg.append_printf ("%s ",  round ((ya - center_y - baseline + height) * scale));-			 			svg.append_printf ("C");  			svg.append_printf ("%s ", round ((xb - center_x - left) * scale));@@ -168,12 +167,7 @@ class Svg { 			svg.append_printf ("%s ", round ((xd - center_x - left) * scale)); 			svg.append_printf ("%s ", round ((yd - center_y - baseline + height) * scale));	 -		} else {-			svg.append_printf ("L");-			-			svg.append_printf ("%s ",  round ((xa - center_x - left) * scale));-			svg.append_printf ("%s ",  round ((-ya + center_y + baseline) * scale));	-			+		} else {		 			svg.append_printf ("C");  			svg.append_printf ("%s ", round ((xb - center_x - left) * scale));

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112