Clone in a terminal:
Commit be51db8
Johan Mattsson - 2015-12-28T17:47:25+00:00
be51db8795f50914a4324ccea79c1b11d72681e6johan.mattsson.m@gmail.com

Move drawing code to the new path class

Changed files (3)

Diff

diff --git a/libbirdfont/FastPath.vala b/libbirdfont/FastPath.valaindex 4a66476..f1e45b3 100644--- a/libbirdfont/FastPath.vala+++ b/libbirdfont/FastPath.vala@@ -19,7 +19,17 @@ namespace BirdFont { public class FastPath : Object {  	Path path;+	+	public override double stroke {+		get {+			return path.stroke;+		} +		set {+			path.stroke = value;+		}+	}+	 	public FastPath () { 		path = new Path (); 		update_region_boundaries ();@@ -38,9 +48,50 @@ public class FastPath : Object { 		return path.is_over (x, y); 	} 			-	public override void draw (Context cr) {+	public override void draw (Context cr, Color? c = null) {+		PathList path_stroke;+		Color path_color;+		bool open;+		+		cr.save ();+		cr.new_path ();+		+		if (c != null) {+			path_color = (!) c;+		} else if (color != null) {+			path_color = (!) color;+		} else {+			path_color = Color.black ();+		}++		if (path.stroke > 0) {+			path_stroke = path.get_stroke_fast ();+			draw_path_list (path_stroke, cr, path_color);+		} else {+			open = path.is_open ();+			+			if (open) {+				path.close ();+				path.recalculate_linear_handles ();+			}+			+			path.draw_path (cr, path_color);+			+			if (open) {+				path.reopen ();+			}+		}++		cr.fill ();+		cr.restore (); 	}-	++	public static void draw_path_list (PathList pl, Context cr, Color? c = null) {+		foreach (Path p in pl.paths) {+			p.draw_path (cr, c);+		}+	}+		 	public override void move (double dx, double dy) { 		path.move (dx, dy); 		path.reset_stroke ();diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex f00e9b2..a154184 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -1677,41 +1677,9 @@ public class Glyph : FontDisplay {  	/** Draw filled paths. */ 	public void draw_paths (Context cr, Color? c = null) {-		PathList stroke;-		Color color;-		bool open;-		-		cr.save ();-		cr.new_path ();-		foreach (Path p in get_visible_paths ()) {-			if (c != null) {-				color = (!) c;-			} else if (p.color != null) {-				color = (!) p.color;-			} else {-				color = Color.black ();-			}--			if (p.stroke > 0) {-				stroke = p.get_stroke_fast ();-				draw_path_list (stroke, cr, color);-			} else {-				open = p.is_open ();-				-				if (open) {-					p.close ();-					p.recalculate_linear_handles ();-				}-				-				p.draw_path (cr, color);-				-				if (open) {-					p.reopen ();-				}-			}+		foreach (Object o in get_visible_objects ()) {+			o.draw (cr, c); 		}-		cr.fill ();-		cr.restore (); 	}  	public void draw_path (Context cr) {@@ -1731,7 +1699,7 @@ public class Glyph : FontDisplay { 					color = Color.black (); 				} -				draw_path_list (stroke, cr, color);+				FastPath.draw_path_list (stroke, cr, color); 			} 		} 		cr.fill ();@@ -1749,7 +1717,7 @@ public class Glyph : FontDisplay { 					if (p.stroke > 0) { 						stroke = p.get_stroke_fast (); 						color = Theme.get_color ("Selected Objects");-						draw_path_list (stroke, cr, color);+						FastPath.draw_path_list (stroke, cr, color); 					} 				} 			}@@ -1829,12 +1797,6 @@ public class Glyph : FontDisplay { 		return Theme.get_color ("Fill Color"); 	} -	public void draw_path_list (PathList pl, Context cr, Color? c = null) {-		foreach (Path p in pl.paths) {-			p.draw_path (cr, c);-		}-	}- 	public void draw_background_color (Context cr, double opacity) { 		if (opacity > 0) { 			cr.save ();diff --git a/libbirdfont/Object.vala b/libbirdfont/Object.valaindex c91b659..bdc2447 100644--- a/libbirdfont/Object.vala+++ b/libbirdfont/Object.vala@@ -31,7 +31,7 @@ public abstract class Object : GLib.Object { 	public double ymin = Glyph.CANVAS_MAX; 	 	public double rotation = 0;-	public double stroke = 0;+	public virtual double stroke { get; set; } 	public LineCap line_cap = LineCap.BUTT; 	 	public Object () {	@@ -77,7 +77,7 @@ public abstract class Object : GLib.Object {  	public abstract void update_region_boundaries (); 	public abstract bool is_over (double x, double y);-	public abstract void draw (Context cr);+	public abstract void draw (Context cr, Color? c = null); 	public abstract Object copy (); 	public abstract void move (double dx, double dy); 	public abstract void rotate (double theta, double xc, double yc);

Contact

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