The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

RectangleTool.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/RectangleTool.vala.
Merge ../birdfont-2.x
1 /* 2 Copyright (C) 2012 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Math; 16 using Cairo; 17 18 namespace BirdFont { 19 20 public class RectangleTool : Tool { 21 22 Path rectangle = new Path (); 23 24 double press_x = -1; 25 double press_y = -1; 26 27 bool resize = false; 28 29 public RectangleTool (string n) { 30 base (n, t_("Rectangle")); 31 32 press_action.connect((self, b, x, y) => { 33 press (b, x, y); 34 }); 35 36 release_action.connect((self, b, x, y) => { 37 press_x = -1; 38 press_y = -1; 39 rectangle = new Path (); 40 resize = false; 41 }); 42 43 move_action.connect ((self, x, y) => { 44 move (x, y); 45 }); 46 } 47 48 void move (double x, double y) { 49 Glyph g; 50 double x1, y1, x2, y2; 51 52 if (resize) { 53 g = MainWindow.get_current_glyph (); 54 g.delete_path (rectangle); 55 56 rectangle = new Path (); 57 58 x1 = Glyph.path_coordinate_x (press_x); 59 y1 = Glyph.path_coordinate_y (press_y); 60 x2 = Glyph.path_coordinate_x (x); 61 y2 = Glyph.path_coordinate_y (y); 62 63 if (GridTool.is_visible ()) { 64 GridTool.tie_coordinate (ref x1, ref y1); 65 GridTool.tie_coordinate (ref x2, ref y2); 66 } 67 68 rectangle.add (x1, y1); 69 rectangle.add (x2, y1); 70 rectangle.add (x2, y2); 71 rectangle.add (x1, y2); 72 73 if (StrokeTool.add_stroke) { 74 rectangle.stroke = StrokeTool.stroke_width; 75 rectangle.line_cap = StrokeTool.line_cap; 76 } 77 78 rectangle.init_point_type (); 79 rectangle.close (); 80 81 g.add_path (rectangle); 82 83 foreach (EditPoint e in rectangle.points) { 84 rectangle.recalculate_linear_handles_for_point (e); 85 } 86 87 rectangle.reset_stroke (); 88 rectangle.update_region_boundaries (); 89 90 GlyphCanvas.redraw (); 91 } 92 } 93 94 void press (int button, double x, double y) { 95 press_x = x; 96 press_y = y; 97 resize = true; 98 99 GlyphCanvas.redraw (); 100 } 101 } 102 103 } 104