.
1 /*
2 Copyright (C) 2014 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 Cairo;
16 using Math;
17
18 namespace BirdFont {
19
20 public class SettingsTab : SettingsDisplay {
21
22 public SettingsTab () {
23 base ();
24 create_setting_items ();
25 }
26
27 public override void create_setting_items () {
28 tools.clear ();
29
30 // setting items
31 tools.add (new SettingsItem.head_line (t_("Settings")));
32
33 SpinButton stroke_width = new SpinButton ("stroke_width");
34 tools.add (new SettingsItem (stroke_width, t_("Stroke width")));
35
36 stroke_width.set_max (4);
37 stroke_width.set_min (0.002);
38 stroke_width.set_value_round (1);
39
40 if (Preferences.get ("stroke_width_for_open_paths") != "") {
41 stroke_width.set_value (Preferences.get ("stroke_width_for_open_paths"));
42 }
43
44 stroke_width.new_value_action.connect ((self) => {
45 Glyph g = MainWindow.get_current_glyph ();
46 Path.stroke_width = stroke_width.get_value ();
47 g.redraw_area (0, 0, g.allocation.width, g.allocation.height);
48 Preferences.set ("stroke_width_for_open_paths", stroke_width.get_display_value ());
49 MainWindow.get_toolbox ().redraw ((int) stroke_width.x, (int) stroke_width.y, 70, 70);
50 });
51
52 Path.stroke_width = stroke_width.get_value ();
53
54 // adjust precision
55 string precision_value = Preferences.get ("precision");
56
57 if (precision_value != "") {
58 precision.set_value (precision_value);
59 } else {
60 #if ANDROID
61 precision.set_value_round (0.5);
62 #else
63 precision.set_value_round (1);
64 #endif
65 }
66
67 precision.new_value_action.connect ((self) => {
68 MainWindow.get_toolbox ().select_tool (precision);
69 Preferences.set ("precision", self.get_display_value ());
70 MainWindow.get_toolbox ().redraw ((int) precision.x, (int) precision.y, 70, 70);
71 });
72
73 precision.select_action.connect((self) => {
74 DrawingTools.pen_tool.set_precision (((SpinButton)self).get_value ());
75 });
76
77 precision.set_min (0.001);
78 precision.set_max (1);
79
80 tools.add (new SettingsItem (precision, t_("Precision for pen tool")));
81
82 Tool show_all_line_handles = new Tool ("show_all_line_handles");
83 show_all_line_handles.select_action.connect((self) => {
84 Path.show_all_line_handles = !Path.show_all_line_handles;
85 Glyph g = MainWindow.get_current_glyph ();
86 g.redraw_area (0, 0, g.allocation.width, g.allocation.height);
87 });
88 tools.add (new SettingsItem (show_all_line_handles, t_("Show or hide control point handles")));
89
90 Tool fill_open_path = new Tool ("fill_open_path");
91 fill_open_path.select_action.connect((self) => {
92 Path.fill_open_path = true;
93 });
94
95 fill_open_path.deselect_action.connect((self) => {
96 Path.fill_open_path = false;
97 });
98 tools.add (new SettingsItem (fill_open_path, t_("Fill open paths.")));
99
100 Tool ttf_units = new Tool ("ttf_units");
101 ttf_units.select_action.connect((self) => {
102 GridTool.ttf_units = !GridTool.ttf_units;
103 Preferences.set ("ttf_units", @"$(GridTool.ttf_units)");
104 });
105 tools.add (new SettingsItem (ttf_units, t_("Use TTF units.")));
106
107 SpinButton freehand_samples = new SpinButton ("freehand_samples_per_point");
108 tools.add (new SettingsItem (freehand_samples, t_("Number of points added by the freehand tool")));
109
110 freehand_samples.set_max (9);
111 freehand_samples.set_min (0.002);
112
113 if (BirdFont.android) {
114 freehand_samples.set_value_round (2.5);
115 } else {
116 freehand_samples.set_value_round (1);
117 }
118
119 if (Preferences.get ("freehand_samples") != "") {
120 freehand_samples.set_value (Preferences.get ("freehand_samples"));
121 DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ());
122 }
123
124 freehand_samples.new_value_action.connect ((self) => {
125 DrawingTools.track_tool.set_samples_per_point (freehand_samples.get_value ());
126 });
127
128 SpinButton simplification_threshold = new SpinButton ("simplification_threshold");
129 simplification_threshold.set_value_round (0.5);
130 tools.add (new SettingsItem (simplification_threshold, t_("Path simplification threshold")));
131
132 simplification_threshold.set_max (5);
133 freehand_samples.set_min (0.002);
134
135 if (Preferences.get ("simplification_threshold") != "") {
136 freehand_samples.set_value (Preferences.get ("simplification_threshold"));
137 DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ());
138 }
139
140 freehand_samples.new_value_action.connect ((self) => {
141 DrawingTools.pen_tool.set_simplification_threshold (simplification_threshold.get_value ());
142 });
143
144 Tool themes = new Tool ("open_theme_tab");
145 themes.set_icon ("theme");
146 themes.select_action.connect((self) => {
147 MenuTab.show_theme_tab ();
148 });
149 tools.add (new SettingsItem (themes, t_("Color theme")));
150
151 tools.add (new SettingsItem.head_line (t_("Key Bindings")));
152
153 foreach (MenuItem menu_item in MainWindow.get_menu ().sorted_menu_items) {
154 tools.add (new SettingsItem.key_binding (menu_item));
155 }
156 }
157
158 public override string get_label () {
159 return t_("Settings");
160 }
161
162 public override string get_name () {
163 return "Settings";
164 }
165
166 }
167
168 }
169