The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

PointTool.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2013 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 /** Move control points. */ 21 public class PointTool : Tool { 22 23 public PointTool (string name) { 24 base (name, ""); 25 26 select_action.connect ((self) => { 27 }); 28 29 deselect_action.connect ((self) => { 30 }); 31 32 press_action.connect ((self, b, x, y) => { 33 Tool p = pen (); 34 if (b == 1) { 35 p.press_action (p, 3, x, y); 36 } else if (b == 2) { 37 p.press_action (p, 2, x, y); 38 } else if (b == 3) { 39 p.press_action (p, 1, x, y); 40 } 41 }); 42 43 double_click_action.connect ((self, b, x, y) => { 44 Tool p = pen (); 45 46 if (!BirdFont.android) { 47 p.double_click_action (p, b, x, y); 48 } 49 }); 50 51 release_action.connect ((self, b, x, y) => { 52 Tool p = pen (); 53 if (b == 1) { 54 p.release_action (p, 3, x, y); 55 } else if (b == 2) { 56 p.release_action (p, 2, x, y); 57 } else if (b == 3) { 58 p.release_action (p, 1, x, y); 59 } 60 }); 61 62 move_action.connect ((self, x, y) => { 63 Tool p = pen (); 64 p.move_action (p, x, y); 65 }); 66 67 key_press_action.connect ((self, keyval) => { 68 Tool p = pen (); 69 p.key_press_action (p, keyval); 70 }); 71 72 key_release_action.connect ((self, keyval) => { 73 Tool p = pen (); 74 p.key_release_action (p, keyval); 75 }); 76 77 draw_action.connect ((tool, cairo_context, glyph) => { 78 Tool p = pen (); 79 p.draw_action (p, cairo_context, glyph); 80 }); 81 } 82 83 public override string get_tip () { 84 string tip = t_ ("Move control points") + "\n"; 85 86 tip += HiddenTools.move_along_axis.get_key_binding (); 87 tip += " - "; 88 tip += t_ ("on axis") + "\n"; 89 90 return tip; 91 } 92 93 public static Tool pen () { 94 return MainWindow.get_toolbox ().get_tool ("pen_tool"); 95 } 96 97 public static void tie_angle (double center_x, double center_y, 98 double coordinate_x, double coordinate_y, 99 out double tied_x, out double tied_y) { 100 101 double length = fabs (Path.distance (center_x, coordinate_x, 102 center_y, coordinate_y)); 103 104 tied_x = 0; 105 tied_y = 0; 106 107 double min = double.MAX; 108 double circle_edge; 109 double circle_x; 110 double circle_y; 111 112 for (double circle_angle = 0; circle_angle < 2 * PI; circle_angle += PI / 4) { 113 circle_x = center_x + cos (circle_angle) * length; 114 circle_y = center_y + sin (circle_angle) * length; 115 116 circle_edge = fabs (Path.distance (coordinate_x, circle_x, 117 coordinate_y, circle_y)); 118 119 if (circle_edge < min) { 120 tied_x = circle_x; 121 tied_y = circle_y; 122 min = circle_edge; 123 } 124 } 125 } 126 } 127 128 } 129