The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

MainWindow.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

Revisions

View the latest version of libbirdfont/MainWindow.vala.
Redraw after switching from rsb to lsb in spacing tab
1 /* 2 Copyright (C) 2012 2014 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 namespace BirdFont { 16 17 public class MainWindow : GLib.Object { 18 19 public static Toolbox tools; 20 public static GlyphCanvas glyph_canvas; 21 public static MainWindow singleton; 22 public static MenuTab menu_tab; 23 public static RecentFiles file_tab; 24 public static OverView overview; 25 public static TabBar tabs; 26 public static NativeWindow native_window; 27 public static KerningDisplay kerning_display; 28 public static CharDatabase character_database; 29 public static LigatureList ligature_display; 30 public static SpacingClassTab spacing_class_tab; 31 public static AbstractMenu menu; 32 public static Dialog dialog; 33 public static SpacingTab spacing_tab; 34 public static Task blocking_background_task; 35 36 /** Number of pixels per mm */ 37 public static double units = 1; 38 39 private static double scrollbar_size = -1; 40 41 public MainWindow () { 42 singleton = this; 43 44 glyph_canvas = new GlyphCanvas (); 45 tabs = new TabBar (); 46 tools = new Toolbox (glyph_canvas, tabs); 47 menu_tab = new MenuTab (); 48 file_tab = new RecentFiles (); 49 overview = new OverView(); 50 kerning_display = new KerningDisplay (); 51 character_database = new CharDatabase (); 52 ligature_display = new LigatureList (); 53 spacing_class_tab = new SpacingClassTab (); 54 menu = new Menu (); 55 dialog = new Dialog (); 56 spacing_tab = new SpacingTab (); 57 blocking_background_task = new Task (null); 58 59 tools.select_tool (DrawingTools.bezier_tool); 60 } 61 62 public static void abort_task () { 63 blocking_background_task.cancel (); 64 } 65 66 public static void run_blocking_task (Task task) { 67 blocking_background_task = task; 68 native_window.run_background_thread (task); 69 } 70 71 public static SpacingTab get_spacing_tab () { 72 return spacing_tab; 73 } 74 75 public static Dialog get_dialog () { 76 return dialog; 77 } 78 79 public static void show_dialog (Dialog d) 80 requires (!is_null(MainWindow.get_tab_bar ())) { 81 Tab t = MainWindow.get_tab_bar ().get_selected_tab (); 82 string tab_name = t.get_display ().get_name (); 83 84 if (tab_name == "Preview") { 85 MenuTab.select_overview (); 86 } 87 88 dialog = d; 89 dialog.visible = true; 90 GlyphCanvas.redraw (); 91 92 set_cursor (NativeWindow.VISIBLE); 93 } 94 95 public static void show_license_dialog () { 96 show_dialog (new LicenseDialog ()); 97 } 98 99 public static void set_cursor (int flags) { 100 if (BirdFont.has_argument ("--test")) { 101 if (dialog.visible) { 102 native_window.set_cursor (NativeWindow.VISIBLE); 103 } else { 104 native_window.set_cursor (flags); 105 } 106 } 107 } 108 109 public static void show_message (string text) { 110 MessageDialog md = new MessageDialog (text); 111 show_dialog (md); 112 } 113 114 public static void hide_dialog () { 115 dialog = new Dialog (); 116 dialog.visible = false; 117 GlyphCanvas.redraw (); 118 } 119 120 public static void set_menu (AbstractMenu m) { 121 menu = m; 122 } 123 124 public static AbstractMenu get_menu () { 125 return menu; 126 } 127 128 /** Set the number of pixels per millimeter for the current screen. */ 129 public static void set_units_per_pixel (double u) { 130 MainWindow.units = u; 131 } 132 133 public static void init () { 134 singleton = new MainWindow (); 135 } 136 137 public static RecentFiles get_recent_files_tab () { 138 return file_tab; 139 } 140 141 public static void open_recent_files_tab () { 142 // FIXME: do not idle 143 IdleSource idle = new IdleSource (); 144 tabs.add_unique_tab (file_tab); 145 idle.set_callback (() => { 146 tabs.select_tab_name ("Files"); 147 return false; 148 }); 149 idle.attach (null); 150 } 151 152 public static void select_all_paths () { 153 Tool t = tools.get_current_tool (); 154 155 if (! (t is MoveTool || t is ResizeTool)) { 156 get_toolbox ().select_tool (DrawingTools.move_tool); 157 } 158 159 IdleSource idle = new IdleSource (); 160 idle.set_callback (() => { 161 DrawingTools.move_tool.select_all_paths (); 162 return false; 163 }); 164 idle.attach (null); 165 } 166 167 public static DrawingTools get_drawing_tools () { 168 return Toolbox.drawing_tools; 169 } 170 171 public void set_native (NativeWindow nw) { 172 native_window = nw; 173 } 174 175 public static FontDisplay get_current_display () { 176 return get_glyph_canvas ().get_current_display (); 177 } 178 179 public static GlyphCanvas get_glyph_canvas () { 180 return glyph_canvas; 181 } 182 183 public static GlyphCollection get_current_glyph_collection () { 184 if (unlikely (is_null (BirdFont.current_glyph_collection))) { 185 GlyphCollection gc; 186 187 warning ("No default glyph have been set yet.\n"); 188 gc = new GlyphCollection.with_glyph ('\0', ""); 189 190 return gc; 191 } 192 193 return BirdFont.current_glyph_collection; 194 } 195 196 public static Glyph get_current_glyph () { 197 return get_current_glyph_collection ().get_current (); 198 } 199 200 public static Toolbox get_toolbox () { 201 return tools; 202 } 203 204 public static Tool get_tool (string n) { 205 return tools.get_tool (n); 206 } 207 208 public static TabBar get_tab_bar () { 209 return tabs; 210 } 211 212 public static Tab get_current_tab () { 213 return tabs.get_selected_tab (); 214 } 215 216 public static bool select_tab (Tab t) { 217 return tabs.selected_open_tab (t); 218 } 219 220 public static SpacingClassTab get_spacing_class_tab () { 221 return spacing_class_tab; 222 } 223 224 public static void update_glyph_sequence () { 225 TextListener listener = new TextListener (t_("Glyph sequence"), Preferences.get ("glyph_sequence"), t_("Close")); 226 listener.signal_text_input.connect ((text) => { 227 Preferences.set ("glyph_sequence", text); 228 GlyphCanvas.redraw (); 229 }); 230 listener.signal_submit.connect (() => { 231 TabContent.hide_text_input (); 232 }); 233 TabContent.show_text_input (listener); 234 } 235 236 public static MainWindow get_singleton () { 237 return singleton; 238 } 239 240 public static void file_chooser (string title, FileChooser fc, uint flags) { 241 MainWindow.native_window.file_chooser (title, fc, flags); 242 } 243 244 public static void hide_scrollbar () { 245 if (!is_null (MainWindow.native_window)) { 246 MainWindow.native_window.set_scrollbar_size (-1); 247 } 248 } 249 250 public static void show_scrollbar () { 251 if (!is_null (MainWindow.native_window)) { 252 MainWindow.native_window.set_scrollbar_size (scrollbar_size); 253 } 254 } 255 256 public static void set_scrollbar_size (double size) { 257 if (!is_null (MainWindow.native_window)) { 258 scrollbar_size = size; 259 MainWindow.native_window.set_scrollbar_size (size); 260 } 261 } 262 263 public static void set_scrollbar_position (double position) { 264 if (!is_null (MainWindow.native_window)) { 265 MainWindow.native_window.set_scrollbar_position (position); 266 } 267 } 268 269 public static void close_all_tabs () { 270 get_tab_bar ().close_all_tabs (); 271 } 272 273 public static string translate (string s) { 274 return t_(s); 275 } 276 277 public static KerningDisplay get_kerning_display () { 278 return kerning_display; 279 } 280 281 public static LigatureList get_ligature_display () { 282 return ligature_display; 283 } 284 285 public static void next_tab () { 286 TabBar tb = MainWindow.get_tab_bar (); 287 int n = tb.get_selected () + 1; 288 289 if (!(0 <= n < tb.get_length ())) { 290 return; 291 } 292 293 tb.select_tab (n); 294 } 295 296 public static void previous_tab () { 297 TabBar tb = MainWindow.get_tab_bar (); 298 int n = tb.get_selected () - 1; 299 300 if (!(0 <= n < tb.get_length ())) { 301 return; 302 } 303 304 tb.select_tab (n); 305 } 306 307 public static void close_tab () { 308 TabBar tb = MainWindow.get_tab_bar (); 309 int n = tb.get_selected (); 310 311 if (!(0 <= n < tb.get_length ())) { 312 return; 313 } 314 315 tb.close_tab (n); 316 } 317 318 public static void set_toolbox (Toolbox tb) { 319 tools = tb; 320 } 321 322 public static OverView get_overview () { 323 foreach (Tab t in tabs.tabs) { 324 if (t.get_display () is OverView) { 325 return (OverView) t.get_display (); 326 } 327 } 328 329 return overview; 330 } 331 } 332 333 } 334