The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

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