Commit be51db8
Move drawing code to the new path class
Changed files (3)
Diff
@@ -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 ();@@ -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 ();@@ -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);