Clone in a terminal:
Commit d8f331d
Johan Mattsson - 2012-09-01T18:17:51+00:00
d8f331db3409baa7a6a7f9446185e56d2b0f524ajohan.mattsson.m@gmail.com

right shift in glyph view adjusts precision

Changed files (11)

Diff

diff --git a/src/BackgroundSelection.vala b/src/BackgroundSelection.valaindex 2463483..834eecf 100644--- a/src/BackgroundSelection.vala+++ b/src/BackgroundSelection.vala@@ -275,10 +275,10 @@ class BackgroundSelection : FontDisplay { 		} 	} 	-	public override void key_press (EventKey e) {+	public override void key_press (uint e) { 	} -	public override void key_release (EventKey e) {+	public override void key_release (uint e) { 	} 	 	public override void motion_notify (EventMotion e) {diff --git a/src/Context.vala b/src/Context.valaindex 630c90d..918a614 100644--- a/src/Context.vala+++ b/src/Context.vala@@ -207,14 +207,14 @@ class ContextDisplay : FontDisplay { 		}					 	} 	-	public override void key_press (EventKey e) {-		unichar c = (unichar) e.keyval;+	public override void key_press (uint keyval) {+		unichar c = (unichar) keyval; 		Font f = Supplement.get_current_font (); 		string name; 		-		if (e.type == EventType.KEY_PRESS && (KeyBindings.singleton.modifier == NONE || KeyBindings.singleton.modifier == SHIFT)) {+		if (KeyBindings.singleton.modifier == NONE || KeyBindings.singleton.modifier == SHIFT) { 					-			if (e.keyval == Key.BACK_SPACE && row.length () > 0) {	+			if (keyval == Key.BACK_SPACE && row.length () > 0) {	 				row.first ().data.glyph.remove_link (row.first ().data.glyph.last ()); 			} 			diff --git a/src/FontDisplay.vala b/src/FontDisplay.valaindex 07e9a09..f35f44d 100644--- a/src/FontDisplay.vala+++ b/src/FontDisplay.vala@@ -86,10 +86,10 @@ public abstract class FontDisplay : GLib.Object { 	public virtual void selected_canvas () { 	} 	-	public virtual void key_press (EventKey e) {+	public virtual void key_press (uint keyval) { 	} 	-	public virtual void key_release (EventKey e) {+	public virtual void key_release (uint keyval) { 	} 	 	public virtual void motion_notify (EventMotion e) {diff --git a/src/Glyph.vala b/src/Glyph.valaindex b0f909c..0b190d2 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -495,8 +495,16 @@ class Glyph : FontDisplay { 		} 	} -	public override void key_press (EventKey e) {	-		if (e.keyval == Key.DEL) {+	public override void key_release (uint keyval) {	+		Tool t;+		t = MainWindow.get_toolbox ().get_current_tool ();+		t.key_release_action (t, keyval);		+	}++	public override void key_press (uint keyval) {	+		Tool t;+		+		if (keyval == Key.DEL) { 			if (active_paths.length () != 0) { 				 				foreach (Path p in active_paths) {@@ -510,8 +518,10 @@ class Glyph : FontDisplay { 			if (selected_point != null) { 				delete_edit_point ((!) selected_point); 			}-			 		}+		+		t = MainWindow.get_toolbox ().get_current_tool ();+		t.key_press_action (t, keyval); 	} 	 	/** Delete edit point from path. */@@ -527,13 +537,13 @@ class Glyph : FontDisplay { 	 	public override void motion_notify (EventMotion e) { 		Tool t;+		t = MainWindow.get_toolbox ().get_current_tool (); 		-		if (KeyBindings.has_ctrl ()) {+		if (move_view && KeyBindings.has_ctrl ()) { 			move_view_offset  (e.x, e.y); 			return; 		}-		-		t = MainWindow.get_toolbox ().get_current_tool ();+ 		t.move_action (t, (int) e.x, (int) e.y);  		if (Supplement.show_coordinates) {@@ -1548,11 +1558,9 @@ class Glyph : FontDisplay { 	} 	 	private void move_view_offset (double x, double y) {-		if (move_view) {-			view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom);-			view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom);-			redraw_area (0, 0, allocation.width, allocation.height);-		}+		view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom);+		view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom);+		redraw_area (0, 0, allocation.width, allocation.height); 	}  	public void store_undo_state () {diff --git a/src/GlyphCanvas.vala b/src/GlyphCanvas.valaindex 556010b..98d05b8 100644--- a/src/GlyphCanvas.vala+++ b/src/GlyphCanvas.vala@@ -106,16 +106,6 @@ class GlyphCanvas : DrawingArea  { 			return true;
 		});
 		
-		key_press_event.connect ((t, e)=> {
-			key_press (e);
-			return true;
-		});
-
-		key_release_event.connect ((t, e)=> {
-			key_release (e);
-			return true;
-		});
-		
 		scroll_event.connect ((t, e)=> {
 			if (e.direction == Gdk.ScrollDirection.UP) {
 				current_display.scroll_wheel_up (e);
@@ -128,11 +118,11 @@ class GlyphCanvas : DrawingArea  { 		
 	}
 	
-	public void key_release (EventKey e) {
+	public void key_release (uint e) {
 		current_display.key_release (e);
 	}
 	
-	public void key_press (EventKey e) {
+	public void key_press (uint e) {
 		current_display.key_press (e);
 	}
 	
diff --git a/src/KeyBindings.vala b/src/KeyBindings.valaindex e25110d..6600c9b 100644--- a/src/KeyBindings.vala+++ b/src/KeyBindings.vala@@ -564,16 +564,15 @@ class KeyBindings { 		return singleton.modifier_ctrl; 	} 	-	public void key_press (EventKey event) {-		bool press = (event.type == EventType.KEY_PRESS);-		uint key = event.keyval;+	public void key_release (uint keyval) {+		set_modifier (keyval, false);+	}+	+	public void key_press (uint keyval) {+		uint key = keyval; 		ShortCut? short_cut; 		-		set_modifier (key, press);-		-		if (!press) {-			return;-		}+		set_modifier (keyval, true); 	 		if (get_short_cut (modifier, key, out short_cut)) { 			if (short_cut != null)@@ -584,21 +583,13 @@ class KeyBindings { 			foreach (Tool t in exp.tool) { 				t.set_active (false); 				-				if (t.key == event.keyval && t.modifier_flag == modifier) {+				if (t.key == keyval && t.modifier_flag == modifier) { 					if (!(require_modifier && (modifier == NONE || modifier == SHIFT))) { 						MainWindow.get_toolbox ().select_tool (t); 					} 				} 			} 		}-		-		/* // FIXA-		foreach (Tool t in MainWindow.get_content_display ().tools) {	-			if (t.key == event.keyval && t.modifier_flag == modifier) {-				t.select_action (t);-			}-		}-		* */ 	} } diff --git a/src/MainWindow.vala b/src/MainWindow.valaindex ce196ff..a53ba8c 100644--- a/src/MainWindow.vala+++ b/src/MainWindow.vala@@ -43,6 +43,8 @@ public class MainWindow : Gtk.Window { 	static DrawingArea margin_right;
 
 	static OverView over_view;
+
+	static List<uint> key_pressed = new List<uint> ();
 	
 	public MainWindow (string title) {
 		singleton = this;
@@ -285,8 +287,18 @@ public class MainWindow : Gtk.Window { 	public static int global_key_bindings (Widget grab_widget, EventKey event, void* data) {		
 		MainWindow window = get_singleton ();
 		
-		window.glyph_canvas.key_press (event);
-		window.key_bindings.key_press (event);
+		foreach (uint k in key_pressed) {
+			if (k == event.keyval) {
+				key_pressed.remove_all (k);
+				window.glyph_canvas.key_release (event.keyval);
+				window.key_bindings.key_release (event.keyval);
+				return 0;
+			}
+		}
+		
+		key_pressed.append (event.keyval);
+		window.glyph_canvas.key_press (event.keyval);
+		window.key_bindings.key_press (event.keyval);
 		
 		return 0;
 	}
diff --git a/src/OverView.vala b/src/OverView.valaindex 35a9eca..0c43c82 100644--- a/src/OverView.vala+++ b/src/OverView.vala@@ -703,17 +703,11 @@ class OverView : FontDisplay { 	}	 	 	public void open_current_glyph () {-		EventKey e = { 0 };-		e.type = EventType.KEY_PRESS;-		e.keyval = Key.ENTER;-		key_press (e);+		key_press (Key.ENTER); 	}  	public void select_next_glyph () {-		EventKey e = { 0 };-		e.type = EventType.KEY_PRESS;-		e.keyval = Key.RIGHT;-		key_press (e);+		key_press (Key.RIGHT); 	}  	public void key_right () {		@@ -765,19 +759,15 @@ class OverView : FontDisplay { 		return glyph_range.get_char (selected); 	} 	-	public override void key_press (EventKey e) {+	public override void key_press (uint keyval) { 		redraw_area (0, 0, allocation.width, allocation.height); 		close_menus ();-	-		if (e.type != EventType.KEY_PRESS) {-			return;-		}  		if (KeyBindings.modifier == CTRL) { 			return; 		} -		switch (e.keyval) {+		switch (keyval) { 			case Key.ENTER: 				open_glyph_signal (get_selected_char ()); 				return;@@ -815,7 +805,7 @@ class OverView : FontDisplay { 				return; 		} -		scroll_to_char (e.keyval);+		scroll_to_char (keyval); 	}  	public void delete_selected_glyph () {diff --git a/src/Path.vala b/src/Path.valaindex 16b3851..b1247e2 100644--- a/src/Path.vala+++ b/src/Path.vala@@ -745,7 +745,7 @@ class Path { 		return is_over_coordinate_var (x, y, 0.1); 	} 	-	public double distance (double ax, double bx, double ay, double by) {+	public static double distance (double ax, double bx, double ay, double by) { 		return Math.fabs (Math.sqrt (Math.pow (ax - bx, 2) + Math.pow (ay - by, 2))); 	} 	diff --git a/src/PenTool.vala b/src/PenTool.valaindex d0d0c52..a701708 100644--- a/src/PenTool.vala+++ b/src/PenTool.vala@@ -41,10 +41,15 @@ class PenTool : Tool { 	private static double last_point_x = 0; 	private static double last_point_y = 0; +	private static bool adjust_precision = false;+	private static double adjust_precision_begin_x = 0;+	private static double adjust_precision_begin_y = 0;+	private static double precision = 1;+	 	public PenTool (string name) {-		base (name, "Edit path", 'p', CTRL);+		base (name, "Edit path", ',', CTRL); 						-		select_action.connect((self) => {+		select_action.connect ((self) => { 		});  		deselect_action.connect ((self) => {@@ -53,21 +58,23 @@ class PenTool : Tool { 			CutTool.force_direction (); 			glyph.close_path (); 			-			move_point_on_path = false; 		// Fixa: this might be better as toggle buttons+			move_point_on_path = false; 			begin_new_point_on_path = false; 		}); 		-		press_action.connect((self, b, x, y) => {+		press_action.connect ((self, b, x, y) => { 			last_point_x = x; 			last_point_y = y;+			+			precision = 1;  			press (b, x, y); 		}); 		-		double_click_action.connect((self, b, x, y) => {+		double_click_action.connect ((self, b, x, y) => { 		}); -		release_action.connect((self, b, ix, iy) => {+		release_action.connect ((self, b, ix, iy) => { 			double x = ix; 			double y = iy; 			Glyph g = MainWindow.get_current_glyph ();@@ -82,18 +89,46 @@ class PenTool : Tool { 			edit_active_corner = false; 			 			selected_handle = new EditPointHandle.empty ();-			active_handle = new EditPointHandle.empty ();			+			active_handle = new EditPointHandle.empty (); 		}); -		move_action.connect((self, x, y) => {+		move_action.connect ((self, x, y) => { 			move (x, y); 		});+		+		key_press_action.connect ((self, keyval) => {+			if (keyval == Key.SHIFT_LEFT) {+				adjust_precision = true;+				+				adjust_precision_begin_x = last_point_x;+				adjust_precision_begin_y = last_point_y;+			}+		});+		+		key_release_action.connect ((self, keyval) => {+			if (keyval == Key.SHIFT_LEFT) {+				adjust_precision = false;+				precision = 1.0 / Path.distance (adjust_precision_begin_x, last_point_x, adjust_precision_begin_y, last_point_y);+				+				precision *= 30;+				+				if (precision > 1) {+					precision = 1;+				}				+			}+		}); 	} 		 	public void move (double x, double y) { 		Glyph glyph = MainWindow.get_current_glyph (); 		EditPoint ep; 		+		if (adjust_precision) {+			last_point_x = x;+			last_point_y = y;+			return;+		}+		 		control_point_event (x, y); 		curve_active_corner_event (x, y); 		set_default_handle_positions ();@@ -119,7 +154,7 @@ class PenTool : Tool { 				selected_handle.move_to (x, y); 			} else { 				selected_handle.set_point_type (PointType.CURVE);-				selected_handle.move_delta (x - last_point_x, y - last_point_y);+				selected_handle.move_delta ((x - last_point_x) * precision, (y - last_point_y) * precision); 			} 			 			selected_handle.parent.recalculate_linear_handles ();@@ -135,7 +170,7 @@ class PenTool : Tool { 		 		// move edit point 		if (move_selected) {-			glyph.move_selected_edit_point_delta (x - last_point_x, y - last_point_y);+			glyph.move_selected_edit_point_delta ((x - last_point_x) * precision, (y - last_point_y) * precision); 			ep = (!) glyph.selected_point; 			 			if (tie_x_or_y_coordinates) {diff --git a/src/Tool.vala b/src/Tool.valaindex 34acd52..eb1e949 100644--- a/src/Tool.vala+++ b/src/Tool.vala@@ -53,6 +53,9 @@ class Tool : GLib.Object { 	public signal void move_action (Tool selected, int x, int y); 	public signal void release_action (Tool selected, int button, int x, int y); 	+	public signal void key_press_action (Tool selected, uint32 keyval);+	public signal void key_release_action (Tool selected, uint32 keyval);+	 	public signal void panel_press_action (Tool selected, uint button, double x, double y); 	public signal void panel_release_action (Tool selected, uint button, double x, double y); 	public signal void panel_move_action (Tool selected, double x, double y);

Contact

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