The Birdfont Source Code
Fix new paths in Beziér tool
These changes was commited to the Birdfont repository Mon, 04 May 2015 18:35:09 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Fix new paths in Beziér tool
--- a/birdfont/GtkWindow.vala
+++ b/birdfont/GtkWindow.vala
@@ -851,7 +851,7 @@
button_press_event.connect ((t, e)=> {
GtkWindow.reset_modifier (e.state);
-
+
if (e.type == EventType.BUTTON_PRESS) {
TabContent.button_press (e.button, e.x, e.y);
} else if (e.type == EventType.2BUTTON_PRESS) {
@@ -887,7 +887,7 @@
}
public class DescriptionForm : GLib.Object {
-
+
public ScrolledWindow canvas;
public Box box;
--- a/libbirdfont/BackgroundImage.vala
+++ b/libbirdfont/BackgroundImage.vala
@@ -429,7 +429,7 @@
ct = new Context (st);
ct.save ();
- Theme.color (ct, "Background 1");
+ ct.set_source_rgba (1, 1, 1, 1);
ct.rectangle (0, 0, allocation.width, allocation.height);
ct.fill ();
--- a/libbirdfont/ForesightTool.vala
+++ b/libbirdfont/ForesightTool.vala
@@ -38,7 +38,7 @@
public bool skip_deselect = false;
static int press_counter = 0;
- bool button_pressed = false;
+ double last_release_time = 0;
public ForesightTool (string name) {
base (name, t_ ("Create Beziér curves"));
@@ -53,8 +53,6 @@
MainWindow.get_current_glyph ().clear_active_paths ();
MainWindow.set_cursor (NativeWindow.VISIBLE);
state = NONE;
-
- print (@"select press_action\n");
});
deselect_action.connect ((self) => {
@@ -66,25 +64,37 @@
MainWindow.set_cursor (NativeWindow.VISIBLE);
state = NONE;
-
- print (@"deselect press_action\n");
});
press_action.connect ((self, b, x, y) => {
+ // ignore double clicks
+ if ((GLib.get_real_time () - last_release_time) / 1000000.0 < 0.4) {
+ print ("Double click.");
+ last_release_time = GLib.get_real_time ();
+ MainWindow.set_cursor (NativeWindow.VISIBLE);
+ return;
+ }
+ last_release_time = GLib.get_real_time ();
+
press (b, x, y);
+ });
+
+ double_click_action.connect ((self, b, x, y) => {
+ EditPoint last;
+ get_active_path ().delete_last_point ();
+
+ last = get_active_path ().get_last_point ();
+
+ PenTool.selected_points.clear ();
+ PenTool.selected_points.add (new PointSelection (last, get_active_path ()));
+ PenTool.selected_point = last;
+ PenTool.active_edit_point = null;
});
release_action.connect ((self, b, x, y) => {
PenTool p = (PenTool) PointTool.pen ();
PointSelection last;
-
- if (!button_pressed) {
- warning ("!button_pressed");
- return;
- }
-
- print (@"bezier release_action\n");
-
+
if (state == MOVE_HANDLES || state == MOVE_FIRST_HANDLE) {
if (state != MOVE_FIRST_HANDLE) {
last = add_new_point (x, y);
@@ -119,7 +129,6 @@
}
current_path.hide_end_handle = true;
- button_pressed = false;
});
move_action.connect ((self, x, y) => {
@@ -148,7 +157,7 @@
}
PenTool.active_path = current_path;
- PenTool.active_path.hide_end_handle = (state == MOVE_POINT);
+ PenTool.active_path.hide_end_handle = PenTool.active_path.is_open ();
if (state == MOVE_HANDLES || state == MOVE_LAST_HANDLE) {
if (previous_point > 0) {
@@ -266,32 +275,18 @@
bool clockwise;
Path? path = null;
bool one_point = false;
-
- if (button_pressed) {
- warning ("no release event");
- return;
- }
- button_pressed = true;
+ Glyph g;
MainWindow.set_cursor (NativeWindow.HIDDEN);
-
- print (@"$(press_counter++) bezier press_action\n");
-
- if (b == 2) {
- stop_drawing ();
- return;
- }
BirdFont.get_current_font ().touch ();
- MainWindow.get_current_glyph ().store_undo_state ();
+ g = MainWindow.get_current_glyph ();
+ g.store_undo_state ();
last_move_x = x;
last_move_y = y;
- if (previous_point > 0) {
- previous_point = 0;
- state = MOVE_POINT;
- } else {
+ if (previous_point == 0) {
if (state == MOVE_POINT) {
state = MOVE_HANDLES;
@@ -344,28 +339,39 @@
if (state == NONE) {
state = MOVE_POINT;
- PenTool.active_path = get_active_path ();
-
add_new_point (x, y);
+
+ PenTool.active_path = get_active_path ();
PenTool.last_point_x = Glyph.path_coordinate_x (x);
PenTool.last_point_y = Glyph.path_coordinate_y (y);
move_action (this, x, y);
state = MOVE_FIRST_HANDLE;
+
+ press_action(this, b, x, y);
release_action(this, b, x, y);
- }
+ }
+
+ if (previous_point > 0) {
+ previous_point = 0;
+ state = MOVE_POINT;
+ }
+
+ if (b == 2) {
+ stop_drawing ();
+ }
}
public void stop_drawing () {
PenTool p = (PenTool) PointTool.pen ();
Path a;
- p.release_action (p, 1, 0, 0);
-
+ p.release_action (p, 1, last_move_x, last_move_y);
+
if (state != NONE) {
a = get_active_path ();
- if (a.is_open ()) {
+ if (a.is_open () && a.points.size > 0) {
a.delete_last_point ();
a.get_first_point ().set_reflective_handles (false);
@@ -375,16 +381,15 @@
a.get_last_point ().set_tie_handle (false);
}
}
-
- p.press_action (p, 2, 0, 0);
- p.release_action (p, 2, 0, 0);
+
+ MainWindow.get_current_glyph ().clear_active_paths ();
+
+ p.press_action (p, 2, last_move_x, last_move_y);
+ p.release_action (p, 2, last_move_x, last_move_y);
current_path.hide_end_handle = true;
- MainWindow.set_cursor (NativeWindow.VISIBLE);
- MainWindow.get_current_glyph ().clear_active_paths ();
-
+ previous_point = 0;
state = NONE;
- MainWindow.set_cursor (NativeWindow.VISIBLE);
}
public Path get_active_path () {
@@ -415,12 +420,16 @@
PointSelection last;
double handle_x, handle_y;
- print (@"add_new_point: $(PenTool.active_path.points.size)\n");
PenTool p = (PenTool) PointTool.pen ();
if (PenTool.active_path.points.size == 0) {
last = p.new_point_action (x, y);
} else {
+
+ if (PenTool.selected_points.size == 0) {
+ p.press_action (p, 1, x, y);
+ }
+
if (PenTool.selected_points.size == 0) {
warning ("No selected points.");
return new PointSelection.empty ();
--- a/libbirdfont/Glyph.vala
+++ b/libbirdfont/Glyph.vala
@@ -1273,6 +1273,13 @@
foreach (Path p in path_list) {
p.set_editable (true);
p.recalculate_linear_handles ();
+
+ if (p.is_open () && p.points.size > 0) {
+ p.get_first_point ().set_reflective_handles (false);
+ p.get_first_point ().set_tie_handle (false);
+ p.get_last_point ().set_reflective_handles (false);
+ p.get_last_point ().set_tie_handle (false);
+ }
}
open = true;
--- a/libbirdfont/PenTool.vala
+++ b/libbirdfont/PenTool.vala
@@ -76,7 +76,6 @@
public static double simplification_threshold = 0.5;
public static bool retain_angle = false;
- bool button_pressed = false;
static int press_counter = 0;
@@ -105,15 +104,6 @@
});
press_action.connect ((self, b, x, y) => {
- if (button_pressed) {
- warning ("Unexpected event");
- return;
- }
-
- print (@"$(press_counter++) pen press_action\n");
-
- button_pressed = true;
-
// retain path direction
clockwise = new Gee.ArrayList<Path> ();
counter_clockwise = new Gee.ArrayList<Path> ();
@@ -156,7 +146,7 @@
last_point_x = Glyph.path_coordinate_x (x);
last_point_y = Glyph.path_coordinate_y (y);
- if (!move_selected_handle && !move_selected && !button_pressed) {
+ if (!move_selected_handle && !move_selected) {
press (b, x, y, true);
} else {
warning ("double click suppressed");
@@ -208,15 +198,13 @@
reset_stroke ();
foreach (Path p in g.active_paths) {
- if (p.is_open ()) {
+ if (p.is_open () && p.points.size > 0) {
p.get_first_point ().set_tie_handle (false);
p.get_first_point ().set_reflective_handles (false);
p.get_last_point ().set_tie_handle (false);
p.get_last_point ().set_reflective_handles (false);
}
}
-
- button_pressed = false;
});
move_action.connect ((self, x, y) => {
@@ -859,7 +847,7 @@
// don't use set point to reflective to on open ends
reflective = true;
foreach (Path path in MainWindow.get_current_glyph ().active_paths) {
- if (path.is_open ()) {
+ if (path.is_open () && path.points.size > 0) {
if (selected_handle.parent == path.get_first_point ()
|| selected_handle.parent == path.get_last_point ()) {
reflective = false;
@@ -1582,9 +1570,7 @@
active_path = new_point.path;
glyph.clear_active_paths ();
glyph.add_active_path (new_point.path);
-
- print (@"PointSelection new_point_action; $(glyph.active_paths.size)\n");
-
+
move_selected = true;
return new_point;
@@ -1598,6 +1584,13 @@
new_point = glyph.add_new_edit_point (x, y);
new_point.path.update_region_boundaries ();
+
+ if (new_point.path.is_open () && new_point.path.points.size > 0) {
+ new_point.path.get_first_point ().set_reflective_handles (false);
+ new_point.path.get_first_point ().set_tie_handle (false);
+ new_point.path.get_last_point ().set_reflective_handles (false);
+ new_point.path.get_last_point ().set_tie_handle (false);
+ }
selected_point = new_point.point;
active_edit_point = new_point.point;
--- a/libbirdfont/TabContent.vala
+++ b/libbirdfont/TabContent.vala
@@ -26,6 +26,9 @@
static TextListener text_callback;
static const int TEXT_INPUT_HEIGHT = 51;
+
+ static double last_press_time = 0;
+ static bool double_click_event = false;
public static void zoom_in () {
if (MenuTab.suppress_event) {
@@ -153,7 +156,7 @@
if (MenuTab.suppress_event) {
return;
}
-
+
if (MainWindow.get_menu ().show_menu) {
MainWindow.get_menu ().button_release (button, x, y);
} else {
@@ -170,6 +173,8 @@
if (MenuTab.suppress_event) {
return;
}
+
+ last_press_time = GLib.get_real_time ();
if (MainWindow.get_dialog ().visible) {
MainWindow.get_dialog ().button_press (button, x, y);