The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Move drawing code to the new path class

These changes was commited to the Birdfont repository Mon, 28 Dec 2015 17:47:25 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 28 Dec 2015 17:47:25 +0000]

Updated Files

libbirdfont/FastPath.vala
libbirdfont/Glyph.vala
libbirdfont/Object.vala
--- a/libbirdfont/FastPath.vala +++ b/libbirdfont/FastPath.vala @@ -19,7 +19,17 @@ 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 @@ 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 ();
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -1677,41 +1677,9 @@ /** 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 @@ color = Color.black (); } - draw_path_list (stroke, cr, color); + FastPath.draw_path_list (stroke, cr, color); } } cr.fill (); @@ -1749,7 +1717,7 @@ 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); } } } @@ -1827,12 +1795,6 @@ private Color get_path_fill_color () { 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) {
--- a/libbirdfont/Object.vala +++ b/libbirdfont/Object.vala @@ -31,7 +31,7 @@ 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 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);