Clone in a terminal:
Commit fd432a8
Johan Mattsson - 2012-12-29T18:33:03+00:00
fd432a83ea77e80b64133d182a1b820761130008johan.mattsson.m@gmail.com

color and line width

Changed files (14)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 5b7cefe..f4a261d 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -235,6 +235,29 @@ public class GtkWindow : Gtk.Window, NativeWindow { 		show_all (); 	} 	+	public void color_selection (ColorTool color_tool) {+		ColorWindow c = new ColorWindow (color_tool);+	}+	+	class ColorWindow : Gtk.Window {+		ColorSelection color_selection = new ColorSelection ();++		public ColorWindow (ColorTool color_tool) {			+			color_selection.color_changed.connect (() => {+				Color c;+				color_selection.get_current_color (out c);+				color_tool.color_r = (double) c.red / uint16.MAX;+				color_tool.color_g = (double) c.green / uint16.MAX;+				color_tool.color_b = (double) c.blue / uint16.MAX;+				color_tool.color_a = (double) color_selection.get_current_alpha () / uint16.MAX; +				color_tool.color_updated ();+			});+			+			add (color_selection);+			show_all ();+		}	+	}+	 	public string get_clipboard () { 		SelectionData selection_data; 		Atom target;diff --git a/icons/active_edit_point.png b/icons/active_edit_point.pngindex 798215d..3d649c8 100644Binary files a/icons/active_edit_point.png and b/icons/active_edit_point.png differdiff --git a/icons/active_edit_point_handle.png b/icons/active_edit_point_handle.pngindex 30c9186..62ea2f9 100644Binary files a/icons/active_edit_point_handle.png and b/icons/active_edit_point_handle.png differdiff --git a/icons/active_selected_edit_point.png b/icons/active_selected_edit_point.pngindex 61bfcd2..0d70664 100644Binary files a/icons/active_selected_edit_point.png and b/icons/active_selected_edit_point.png differdiff --git a/icons/edit_point.png b/icons/edit_point.pngindex 098bace..15e6414 100644Binary files a/icons/edit_point.png and b/icons/edit_point.png differdiff --git a/icons/edit_point_handle.png b/icons/edit_point_handle.pngindex 9688a84..f588bbe 100644Binary files a/icons/edit_point_handle.png and b/icons/edit_point_handle.png differdiff --git a/icons/selected_edit_point.png b/icons/selected_edit_point.pngindex a2cd4c7..3d649c8 100644Binary files a/icons/selected_edit_point.png and b/icons/selected_edit_point.png differdiff --git a/libbirdfont/Birdfont.vala b/libbirdfont/Birdfont.valaindex 60c15b5..e0f858a 100644--- a/libbirdfont/Birdfont.vala+++ b/libbirdfont/Birdfont.vala@@ -94,10 +94,10 @@ public static int run_export (string[] arg) { 		LogLevelFlags levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING; 		Log.set_handler (null, levels, supplement.fatal_warning);		 	}-+	 	Preferences preferences = new Preferences (); 	preferences.load ();-		+			 	supplement.args = new Argument (""); 	supplement.current_font = new Font (); 	supplement.current_glyph = new Glyph ("");diff --git a/libbirdfont/ColorTool.vala b/libbirdfont/ColorTool.valanew file mode 100644index 0000000..8c9fd51--- /dev/null+++ b/libbirdfont/ColorTool.vala@@ -0,0 +1,74 @@+/*+    Copyright (C) 2012 Johan Mattsson++    This program is free software: you can redistribute it and/or modify+    it under the terms of the GNU General Public License as published by+    the Free Software Foundation, either version 3 of the License, or+    (at your option) any later version.++    This program is distributed in the hope that it will be useful,+    but WITHOUT ANY WARRANTY; without even the implied warranty of+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the+    GNU General Public License for more details.++    You should have received a copy of the GNU General Public License+    along with this program.  If not, see <http://www.gnu.org/licenses/>.+*/++using Cairo;++namespace Supplement {++public class ColorTool : Tool {+	+	public double color_r = 0;+	public double color_g = 0;+	public double color_b = 0;+	public double color_a = 0;+	+	public signal void color_updated ();+	+	public ColorTool (string tool_tip) {+		base ("color_selection", tool_tip);++		select_action.connect((self) => {+			MainWindow.native_window.color_selection (this);+		});+		+		color_updated.connect (() => {+			MainWindow.get_toolbox ().redraw ((int)x, (int)y, (int)x + 20, (int)y + 20);+		});+	}+	+	public override void draw (Context cr) {+		double xt = x + 4 + w;+		double yt = y + h + 16;+		+		base.draw (cr);+		+		cr.save ();+		cr.set_source_rgba (color_r, color_g, color_b, 1);+		cr.rectangle (xt, yt, 16, 16);+		cr.fill ();+		cr.restore ();+	}+	+	public void set_r (double c) {+		color_r = c;+	}++	public void set_g (double c) {+		color_g = c;+	}++	public void set_b (double c) {+		color_b = c;+	}++	public void set_a (double c) {+		color_a = c;+	}++}++}diff --git a/libbirdfont/NativeWindow.vala b/libbirdfont/NativeWindow.valaindex 09d089c..3086e1e 100644--- a/libbirdfont/NativeWindow.vala+++ b/libbirdfont/NativeWindow.vala@@ -30,6 +30,8 @@ public interface NativeWindow : GLib.Object { 	public abstract void set_clipboard (string data); 	public abstract void set_inkscape_clipboard (string data); +	public abstract void color_selection (ColorTool color_tool);+ 	protected void webkit_callback (string s) { 		FontDisplay fd = MainWindow.get_current_display (); 		fd.process_property (s);diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex ad7494c..505be02 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -60,7 +60,16 @@ public class Path { 	 	Path quadratic_path; // quadratic points for TrueType export 	+	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 stroke_width = 1;+	 	public Path () {+		string width;+		 		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");@@ -68,6 +77,16 @@ public class Path { 			active_edit_point_handle_image = Icons.get_icon ("active_edit_point_handle.png"); 			selected_edit_point_image  = Icons.get_icon ("selected_edit_point.png"); 			active_selected_edit_point_image = Icons.get_icon ("active_selected_edit_point.png");+		+			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"));+			} 		} 	} @@ -178,8 +197,8 @@ 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 (0, 0, 0, alpha);-		cr.set_line_width (1 / g.view_zoom);+		cr.set_source_rgba (line_color_r, line_color_g, line_color_b, line_color_a);+		cr.set_line_width (stroke_width / g.view_zoom); 		 		cr.line_to (xa, ya); // this point makes sense only if it is the first or last position, the other points are meaning less don't export them @@ -241,8 +260,8 @@ public class Path {  		get_line_points (e, en, out ax, out ay, out bx, out by); 	-		cr.set_source_rgba (0/255.0, 0/255.0, 0/255.0, 1);-		cr.set_line_width (1.7 * (1/g.view_zoom));+		cr.set_source_rgba (line_color_r, line_color_g, line_color_b, line_color_a);+		cr.set_line_width (1.7 * (stroke_width / g.view_zoom));  		cr.line_to (ax, ay); 		cr.line_to (bx, by);@@ -294,22 +313,24 @@ public class Path { 	 	public static void draw_img_center (Context cr, ImageSurface img, double x, double y) { 		Glyph g = MainWindow.get_current_glyph ();+		double r = 1.0 / 10.0;+		+		double width = Math.sqrt (stroke_width); 		 		double ivz = 1 / g.view_zoom;+		double ivs = 1 / width;  		double xc = g.allocation.width / 2.0; 		double yc = g.allocation.height / 2.0;  		cr.save ();--		cr.scale (ivz, ivz);+		cr.scale (ivz * width * r, ivz * width * r); 		-		x = xc + x - (img.get_width () / 2.0) * ivz; -		y = yc - y - (img.get_height () / 2.0) * ivz;+		x = xc + x - (width * r * img.get_width () / 2.0) * ivz; +		y = yc - y - (width * r * img.get_height () / 2.0) * ivz; 		-		cr.set_source_surface (img, x * g.view_zoom, y * g.view_zoom);+		cr.set_source_surface (img, x * g.view_zoom * ivs * 1/r, y * g.view_zoom * ivs * 1/r); 		cr.paint ();-		 		cr.restore ();		 	} 	diff --git a/libbirdfont/Supplement.vala b/libbirdfont/Supplement.valaindex 157d35e..da5f123 100644--- a/libbirdfont/Supplement.vala+++ b/libbirdfont/Supplement.vala@@ -59,6 +59,9 @@ public class Supplement { 			Process.exit (0);
 		}
 
+		Preferences preferences = new Preferences ();
+		preferences.load ();
+		
 		current_font = new Font ();
 		current_glyph = new Glyph ("");
 
@@ -80,10 +83,7 @@ public class Supplement { 		} else {
 			exec_path = "./";
 		}
-		
-		Preferences preferences = new Preferences ();
-		preferences.load ();
-		
+
 		if (args.get_file () != "") {
 			font_file = File.new_for_path (args.get_file ());
 			
diff --git a/libbirdfont/Tool.vala b/libbirdfont/Tool.valaindex 6d3e31f..aeb9700 100644--- a/libbirdfont/Tool.vala+++ b/libbirdfont/Tool.vala@@ -140,7 +140,7 @@ public class Tool : GLib.Object { 	}  	public bool is_selected () {-			return selected;+		return selected; 	} 		 	public virtual void set_properties (double tx, double ty, double tw, double th) {diff --git a/libbirdfont/Toolbox.vala b/libbirdfont/Toolbox.valaindex 1d1e256..429e206 100644--- a/libbirdfont/Toolbox.vala+++ b/libbirdfont/Toolbox.vala@@ -68,6 +68,7 @@ public class Toolbox : GLib.Object  { 		Expander view_tools = new Expander (); 		Expander grid = new Expander (); 		Expander background_tools = new Expander ();+		Expander style_tools = new Expander (); 		 		grid_expander = grid; @@ -172,7 +173,7 @@ public class Toolbox : GLib.Object  { 		precision.set_max (1); 		 		draw_tool_modifiers.add_tool (precision);-				+		 		// path tools 		Tool union_paths_tool = new MergeTool ("union_paths"); 		path_tool_modifiers.add_tool (union_paths_tool);@@ -243,7 +244,7 @@ public class Toolbox : GLib.Object  { 			MainWindow.get_tab_bar ().select_tab_name ("Overview"); 		}); 		characterset_tools.add_tool (delete_glyph);-						+ 		if (Supplement.has_argument ("--test")) { 			Tool test_case = new Tool ("test_case"); 			test_case.select_action.connect((self) => {@@ -472,9 +473,49 @@ public class Toolbox : GLib.Object  { 				b.set_contrast (background_contrast.get_value ()); 			} 		});++		// color and style+		ColorTool stroke_color = new ColorTool (_("Stroke color"));+		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;++			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);+		}); 		-		// Fixa: background_tools.add_tool (background_contrast);+		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"))); 		+		style_tools.add_tool (stroke_color);+		+		SpinButton stroke_width;+		stroke_width = new SpinButton ("stroke_width", _("Stroke width"));+		+		if (Preferences.get ("stroke_width") == "") {+			stroke_width.set_value_round (1);+		} else {+			stroke_width.set_value (Preferences.get ("stroke_width"));+		}+		+		stroke_width.new_value_action.connect((self) => {+			Glyph g = MainWindow.get_current_glyph ();+			Path.stroke_width = stroke_width.get_value ();+			g.redraw_area (0, 0, g.allocation.width, g.allocation.height);+			Preferences.set ("stroke_width", @"$(Path.stroke_width)");+			redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70);+		});+		style_tools.add_tool (stroke_width);+ 		draw_tools.set_open (true); 		draw_tool_modifiers.set_open (true); 		path_tool_modifiers.set_open (true);@@ -484,6 +525,7 @@ public class Toolbox : GLib.Object  { 		test_tools.set_open (true); 		guideline_tools.set_open (true); 		background_tools.set_open (true);+		style_tools.set_open (true); 		 		add_expander (draw_tools); 		add_expander (draw_tool_modifiers);@@ -494,6 +536,7 @@ public class Toolbox : GLib.Object  { 		add_expander (grid); 		add_expander (view_tools); 		add_expander (background_tools);+		add_expander (style_tools); 		 		// Fixa: add_expander (trace); 		

Contact

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