.
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 (Path p in g.active_paths) {
34 p.reverse ();
35 }
36
37 count_down = true;
38 Glyph.show_orientation_arrow = true;
39 Glyph.orientation_arrow_opacity = 1;
40 time = 10;
41 fade_out ();
42
43 update_icon ();
44 GlyphCanvas.redraw ();
45 });
46
47 DrawingTools.move_tool.selection_changed.connect (() => {
48 update_icon ();
49 });
50 }
51
52 public void update_icon () {
53 Glyph glyph = MainWindow.get_current_glyph ();
54 bool has_clockwise_paths = false;
55 bool has_counter_clockwise_paths = false;
56
57 foreach (Path p in glyph.active_paths) {
58 if (p.is_clockwise ()) {
59 has_clockwise_paths = true;
60 }
61
62 if (!p.is_clockwise ()) {
63 has_counter_clockwise_paths = true;
64 }
65 }
66
67 if (has_clockwise_paths && has_counter_clockwise_paths) {
68 set_icon ("orientation_both");
69 } else if (has_clockwise_paths) {
70 set_icon ("orientation_clockwise");
71 } else if (has_counter_clockwise_paths) {
72 set_icon ("orientation_counter_clockwise");
73 } else {
74 set_icon ("orientation_both");
75 }
76
77 Toolbox.redraw_tool_box ();
78 }
79
80 public void fade_out () {
81 TimeoutSource timer = new TimeoutSource (100);
82 timer.set_callback (() => {
83 if (count_down) {
84 if (time <= 0) {
85 Glyph.show_orientation_arrow = false;
86 count_down = false;
87 }
88
89 if (time < 1) {
90 Glyph.orientation_arrow_opacity = time;
91 GlyphCanvas.redraw ();
92 }
93
94 time -= 0.1;
95 } else {
96 Glyph.show_orientation_arrow = false;
97 }
98
99 return count_down;
100 });
101 timer.attach (null);
102 }
103 }
104
105 }
106