The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OrientationTool.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) 2015 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 OrientationTool : Tool { 21 22 double time = 0; 23 bool count_down = false; 24 25 public OrientationTool (string name, string tip) { 26 base (name, tip); 27 28 set_icon ("orientation_both"); 29 30 select_action.connect ((self) => { 31 Glyph g = MainWindow.get_current_glyph (); 32 33 foreach (Object o in g.active_paths) { 34 if (o is PathObject) { 35 PathObject p = (PathObject) o; 36 p.get_path ().reverse (); 37 } 38 } 39 40 count_down = true; 41 Glyph.show_orientation_arrow = true; 42 Glyph.orientation_arrow_opacity = 1; 43 time = 10; 44 fade_out (); 45 46 update_icon (); 47 GlyphCanvas.redraw (); 48 }); 49 50 DrawingTools.move_tool.selection_changed.connect (() => { 51 update_icon (); 52 }); 53 } 54 55 public void update_icon () { 56 Glyph glyph = MainWindow.get_current_glyph (); 57 bool has_clockwise_paths = false; 58 bool has_counter_clockwise_paths = false; 59 60 foreach (Object o in glyph.active_paths) { 61 if (o is PathObject) { 62 Path p = ((PathObject) o).get_path (); 63 64 if (p.is_clockwise ()) { 65 has_clockwise_paths = true; 66 } 67 68 if (!p.is_clockwise ()) { 69 has_counter_clockwise_paths = true; 70 } 71 } 72 } 73 74 if (has_clockwise_paths && has_counter_clockwise_paths) { 75 set_icon ("orientation_both"); 76 } else if (has_clockwise_paths) { 77 set_icon ("orientation_clockwise"); 78 } else if (has_counter_clockwise_paths) { 79 set_icon ("orientation_counter_clockwise"); 80 } else { 81 set_icon ("orientation_both"); 82 } 83 84 Toolbox.redraw_tool_box (); 85 } 86 87 public void fade_out () { 88 TimeoutSource timer = new TimeoutSource (100); 89 timer.set_callback (() => { 90 if (count_down) { 91 if (time <= 0) { 92 Glyph.show_orientation_arrow = false; 93 count_down = false; 94 } 95 96 if (time < 1) { 97 Glyph.orientation_arrow_opacity = time; 98 GlyphCanvas.redraw (); 99 } 100 101 time -= 0.1; 102 } else { 103 Glyph.show_orientation_arrow = false; 104 } 105 106 return count_down; 107 }); 108 timer.attach (null); 109 } 110 } 111 112 } 113