Commit 80f5f2d
rectangles
Changed files (5)
addedicons/rectangle.pngmodifiedlibbirdfont/CircleTool.valamodifiedlibbirdfont/Path.valaaddedlibbirdfont/RectangleTool.valamodifiedlibbirdfont/Toolbox.vala
Diff
new file mode 100644Binary files /dev/null and b/icons/rectangle.png differ@@ -34,13 +34,6 @@ public class CircleTool : Tool { public CircleTool (string n) { base (n, _("Circle"));- - select_action.connect((self) => {- });-- deselect_action.connect((self) => {- Glyph glyph = MainWindow.get_current_glyph ();- }); press_action.connect((self, b, x, y) => { press (b, x, y);@@ -101,7 +94,6 @@ public class CircleTool : Tool { double radius = 2; double px, py, steps; Path path = new Path ();- PointType type; press_x = x; press_y = y;@@ -123,28 +115,7 @@ public class CircleTool : Tool { path.add (px, py); } - switch (Toolbox.point_type) {- case PointType.QUADRATIC:- type = PointType.LINE_QUADRATIC;- break;- case PointType.DOUBLE_CURVE:- type = PointType.LINE_DOUBLE_CURVE;- break;- case PointType.CUBIC:- type = PointType.LINE_CUBIC;- break;- default:- warning ("No type is set");- type = PointType.LINE_CUBIC;- break;- }- - foreach (EditPoint ep in path.points) {- ep.type = type;- ep.get_right_handle ().type = type;- ep.get_left_handle ().type = type;- }- + path.init_point_type (); path.close (); path.recalculate_linear_handles (); @@ -2143,6 +2143,32 @@ public class Path { update_region_boundries (); }++ public void init_point_type () {+ PointType type;+ + switch (Toolbox.point_type) {+ case PointType.QUADRATIC:+ type = PointType.LINE_QUADRATIC;+ break;+ case PointType.DOUBLE_CURVE:+ type = PointType.LINE_DOUBLE_CURVE;+ break;+ case PointType.CUBIC:+ type = PointType.LINE_CUBIC;+ break;+ default:+ warning ("No type is set");+ type = PointType.LINE_CUBIC;+ break;+ }+ + foreach (EditPoint ep in points) {+ ep.type = type;+ ep.get_right_handle ().type = type;+ ep.get_left_handle ().type = type;+ } + } } }new file mode 100644@@ -0,0 +1,95 @@+/*+ Copyright (C) 2012 Johan Mattsson++ This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version.++ This library 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 + Lesser General Public License for more details.+*/++using Math;+using Cairo;++namespace BirdFont {++public class RectangleTool : Tool {++ Path rectangle = new Path ();++ double press_x = -1;+ double press_y = -1;+ + bool resize = false;+ + public RectangleTool (string n) {+ base (n, _("Rectangle"));++ press_action.connect((self, b, x, y) => {+ press (b, x, y);+ });++ release_action.connect((self, b, x, y) => {+ press_x = -1;+ press_y = -1;+ rectangle = new Path ();+ resize = false;+ });+ + move_action.connect ((self, x, y) => {+ move (x, y);+ });+ }+ + void move (double x, double y) {+ Glyph g;+ double x1, y1, x2, y2;++ if (resize) {+ g = MainWindow.get_current_glyph ();+ g.delete_path (rectangle);+ + rectangle = new Path ();+ + x1 = Glyph.path_coordinate_x (press_x); + y1 = Glyph.path_coordinate_y (press_y);+ x2 = Glyph.path_coordinate_x (x); + y2 = Glyph.path_coordinate_y (y);++ if (GridTool.is_visible ()) {+ GridTool.tie_coordinate (ref x1, ref y1);+ GridTool.tie_coordinate (ref x2, ref y2);+ }+ + rectangle.add (x1, y1);+ rectangle.add (x2, y1);+ rectangle.add (x2, y2);+ rectangle.add (x1, y2);++ rectangle.init_point_type ();++ g.add_path (rectangle);+ + foreach (EditPoint e in rectangle.points) {+ e.recalculate_linear_handles ();+ }+ + MainWindow.get_glyph_canvas ().redraw ();+ }+ }+ + void press (int button, double x, double y) {+ Glyph glyph = MainWindow.get_current_glyph ();+ press_x = x;+ press_y = y;+ resize = true;+ + MainWindow.get_glyph_canvas ().redraw ();+ }+}++}@@ -439,6 +439,9 @@ public class Toolbox : GLib.Object { Tool circle = new CircleTool ("circle"); shape_tools.add_tool (circle); + Tool rectangle = new RectangleTool ("rectangle");+ shape_tools.add_tool (rectangle);+ // background tools background_scale = new SpinButton ("scale_background", _("Set size for background image")); background_scale.set_int_value ("1.000");