Clone in a terminal:
Commit 8af0fcb
Johan Mattsson - 2015-03-14T13:12:53+00:00
8af0fcb01842dc00bef7a057ef230a7179623c63johan.mattsson.m@gmail.com

Move stroke color settings to the theme

Changed files (4)

Diff

diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex dc55686..889686b 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -1517,7 +1517,7 @@ public class Glyph : FontDisplay { 	} 	 	private Color get_path_fill_color () {-		return new Color (Path.fill_color_r, Path.fill_color_g, Path.fill_color_b, Path.fill_color_a);+		return Theme.get_color ("Fill Color"); 	} 	 	private void draw_outline_for_paths (PathList pl, Context cr) {diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 419924e..ca40808 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -80,21 +80,6 @@ public class Path { 	public static ImageSurface? cubic_selected_edit_point_image = null; 	public static ImageSurface? cubic_active_selected_edit_point_image = null; 	-	public static double line_color_r = 0;-	public static double line_color_g = 0;-	public static double line_color_b = 0;-	public static double line_color_a = 1;--	public static double handle_color_r = 0;-	public static double handle_color_g = 0;-	public static double handle_color_b = 0;-	public static double handle_color_a = 1;--	public static double fill_color_r = 0;-	public static double fill_color_g = 0;-	public static double fill_color_b = 0;-	public static double fill_color_a = 1;-	 	/** The stroke of an outline when the path is not filled. */ 	public static double stroke_width = 1; 	public static bool show_all_line_handles = true;@@ -127,21 +112,6 @@ public class Path { 			width = Preferences.get ("stroke_width"); 			if (width != "") { 				stroke_width = double.parse (width);--				line_color_r = double.parse (Preferences.get ("line_color_r"));-				line_color_g = double.parse (Preferences.get ("line_color_g"));-				line_color_b = double.parse (Preferences.get ("line_color_b"));-				line_color_a = double.parse (Preferences.get ("line_color_a"));--				handle_color_r = double.parse (Preferences.get ("handle_color_r"));-				handle_color_g = double.parse (Preferences.get ("handle_color_g"));-				handle_color_b = double.parse (Preferences.get ("handle_color_b"));-				handle_color_a = double.parse (Preferences.get ("handle_color_a"));--				fill_color_r = double.parse (Preferences.get ("fill_color_r"));-				fill_color_g = double.parse (Preferences.get ("fill_color_g"));-				fill_color_b = double.parse (Preferences.get ("fill_color_b"));-				fill_color_a = double.parse (Preferences.get ("fill_color_a")); 			} 		} 	}@@ -265,18 +235,8 @@ public class Path {  		// draw highlighted segment			 		if (highlight_last_segment && points.size >= 2) {-			line_color_r = 0.5;-			line_color_g = 0.5;-			line_color_b = 0.8;-			line_color_a = 1;-			-			draw_next (points.get (points.size - 2), points.get (points.size - 1), cr);+			draw_next (points.get (points.size - 2), points.get (points.size - 1), cr, true); 			cr.stroke ();-			-			line_color_r = 0;-			line_color_g = 0;-			line_color_b = 0;-			line_color_a = 1; 		} 	} 	@@ -352,18 +312,18 @@ public class Path { 		} 	} -	private void draw_next (EditPoint e, EditPoint en, Context cr) {+	private void draw_next (EditPoint e, EditPoint en, Context cr, bool highlighted = false) { 		PointType r = e.get_right_handle ().type; 		PointType l = en.get_left_handle ().type; 		 		if (r == PointType.DOUBLE_CURVE || l == PointType.DOUBLE_CURVE) {-			draw_double_curve (e, en, cr);+			draw_double_curve (e, en, cr, highlighted); 		} else {-			draw_curve (e, en, cr);+			draw_curve (e, en, cr, highlighted); 		} 	} 	-	private static void draw_double_curve (EditPoint e, EditPoint en, Context cr) {+	private static void draw_double_curve (EditPoint e, EditPoint en, Context cr, bool highlighted) { 		EditPoint middle; 		double x, y; 		@@ -376,11 +336,11 @@ public class Path { 		middle.right_handle.type = PointType.DOUBLE_CURVE; 		middle.left_handle.type = PointType.DOUBLE_CURVE; 		-		draw_curve (e, middle, cr);-		draw_curve (middle, en, cr);		+		draw_curve (e, middle, cr, highlighted);+		draw_curve (middle, en, cr, highlighted);		 	} 		-	private static void draw_curve (EditPoint e, EditPoint en, Context cr, double alpha = 1) {+	private static void draw_curve (EditPoint e, EditPoint en, Context cr, bool highlighted = false, double alpha = 1) { 		Glyph g = MainWindow.get_current_glyph (); 		double xa, ya, xb, yb, xc, yc, xd, yd; 		PointType t = e.get_right_handle ().type;@@ -388,7 +348,12 @@ public class Path { 		 		get_bezier_points (e, en, out xa, out ya, out xb, out yb, out xc, out yc, out xd, out yd); -		cr.set_source_rgba (line_color_r, line_color_g, line_color_b, line_color_a);+		if (!highlighted) {+			Theme.color (cr, "Stroke Color");+		} else {+			Theme.color (cr, "Highlighted Guide");+		}+		 		cr.set_line_width (stroke_width / g.view_zoom); 		 		cr.line_to (xa, ya); // this point makes sense only if it is in the first or last position@@ -454,8 +419,8 @@ public class Path { 		double ax, ay, bx, by;  		get_line_points (e, en, out ax, out ay, out bx, out by);-	-		cr.set_source_rgba (handle_color_r, handle_color_g, handle_color_b, handle_color_a);+		+		Theme.color (cr, "Handle Color"); 		cr.set_line_width (1.7 * (stroke_width / g.view_zoom));  		cr.line_to (ax, ay);diff --git a/libbirdfont/SettingsDisplay.vala b/libbirdfont/SettingsDisplay.valaindex 2354041..826ff5b 100644--- a/libbirdfont/SettingsDisplay.vala+++ b/libbirdfont/SettingsDisplay.vala@@ -37,31 +37,6 @@ public class SettingsDisplay : FontDisplay { 		// setting items 		tools.add (new SettingsItem.head_line (t_("Settings"))); 		-		ColorTool stroke_color = new ColorTool ();-		stroke_color.color_updated.connect (() => {-			Path.line_color_r = stroke_color.color_r;-			Path.line_color_g = stroke_color.color_g;-			Path.line_color_b = stroke_color.color_b;-			Path.line_color_a = stroke_color.color_a;--			if (Path.line_color_a == 0) {-				Path.line_color_a = 1;-			}--			Preferences.set ("line_color_r", @"$(Path.line_color_r)");-			Preferences.set ("line_color_g", @"$(Path.line_color_g)");-			Preferences.set ("line_color_b", @"$(Path.line_color_b)");-			Preferences.set ("line_color_a", @"$(Path.line_color_a)");--			Glyph g = MainWindow.get_current_glyph ();-			g.redraw_area (0, 0, g.allocation.width, g.allocation.height);-		});-		stroke_color.set_r (double.parse (Preferences.get ("line_color_r")));-		stroke_color.set_g (double.parse (Preferences.get ("line_color_g")));-		stroke_color.set_b (double.parse (Preferences.get ("line_color_b")));-		stroke_color.set_a (double.parse (Preferences.get ("line_color_a")));-		tools.add (new SettingsItem (stroke_color, t_("Stroke color")));-		 		SpinButton stroke_width = new SpinButton ("stroke_width"); 		tools.add (new SettingsItem (stroke_width, t_("Stroke width"))); 		@@ -83,28 +58,6 @@ public class SettingsDisplay : FontDisplay { 		 		Path.stroke_width = stroke_width.get_value (); 		-		ColorTool handle_color = new ColorTool ();-		handle_color.color_updated.connect (() => {-			Path.handle_color_r = handle_color.color_r;-			Path.handle_color_g = handle_color.color_g;-			Path.handle_color_b = handle_color.color_b;-			Path.handle_color_a = handle_color.color_a;--			Preferences.set ("handle_color_r", @"$(Path.handle_color_r)");-			Preferences.set ("handle_color_g", @"$(Path.handle_color_g)");-			Preferences.set ("handle_color_b", @"$(Path.handle_color_b)");-			Preferences.set ("handle_color_a", @"$(Path.handle_color_a)");--			Glyph g = MainWindow.get_current_glyph ();-			g.redraw_area (0, 0, g.allocation.width, g.allocation.height);-		});-		handle_color.set_r (double.parse (Preferences.get ("handle_color_r")));-		handle_color.set_g (double.parse (Preferences.get ("handle_color_g")));-		handle_color.set_b (double.parse (Preferences.get ("handle_color_b")));-		handle_color.set_a (double.parse (Preferences.get ("handle_color_a")));-		-		tools.add (new SettingsItem (handle_color, t_("Handle color")));- 		// adjust precision 		string precision_value = Preferences.get ("precision"); 		precision = new SpinButton ("precision");@@ -142,28 +95,6 @@ public class SettingsDisplay : FontDisplay { 		}); 		tools.add (new SettingsItem (show_all_line_handles, t_("Show or hide control point handles"))); -		// fill color-		ColorTool fill_color = new ColorTool ();-		fill_color.color_updated.connect (() => {-			Path.fill_color_r = fill_color.color_r;-			Path.fill_color_g = fill_color.color_g;-			Path.fill_color_b = fill_color.color_b;-			Path.fill_color_a = fill_color.color_a;--			Preferences.set ("fill_color_r", @"$(Path.fill_color_r)");-			Preferences.set ("fill_color_g", @"$(Path.fill_color_g)");-			Preferences.set ("fill_color_b", @"$(Path.fill_color_b)");-			Preferences.set ("fill_color_a", @"$(Path.fill_color_a)");--			Glyph g = MainWindow.get_current_glyph ();-			g.redraw_area (0, 0, g.allocation.width, g.allocation.height);-		});-		fill_color.set_r (double.parse (Preferences.get ("fill_color_r")));-		fill_color.set_g (double.parse (Preferences.get ("fill_color_g")));-		fill_color.set_b (double.parse (Preferences.get ("fill_color_b")));-		fill_color.set_a (double.parse (Preferences.get ("fill_color_a")));-		tools.add (new SettingsItem (fill_color, t_("Object color")));- 		Tool fill_open_path = new Tool ("fill_open_path"); 		fill_open_path.select_action.connect((self) => { 			Path.fill_open_path = !Path.fill_open_path;diff --git a/libbirdfont/Theme.vala b/libbirdfont/Theme.valaindex 6995829..df56212 100644--- a/libbirdfont/Theme.vala+++ b/libbirdfont/Theme.vala@@ -84,6 +84,10 @@ public class Theme : GLib.Object { 		color_list = new Gee.ArrayList<string> (); 		colors = new Gee.HashMap<string, Color> (); 		+		Theme.set_default_color ("Stroke Color", 0, 0, 0, 1);+		Theme.set_default_color ("Handle Color", 0, 0, 0, 1);+		Theme.set_default_color ("Fill Color", 0.5, 0.5, 0.5, 1);+		 		Theme.set_default_color ("Background 1", 1, 1, 1, 1); 		Theme.set_default_color ("Background 2", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 		Theme.set_default_color ("Background 3", 38 / 255.0, 39 / 255.0, 43 / 255.0, 1);@@ -125,6 +129,10 @@ public class Theme : GLib.Object { 		 		Theme.set_default_color ("Button Foreground", 101 / 255.0, 108 / 255.0, 116 / 255.0, 1); 		+		N_("Stroke Color");+		N_("Handle Color");+		N_("Fill Color");+		 		N_("Background 1"); 		N_("Background 2"); 		N_("Background 3");

Contact

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