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.
Faster rendering of fallback fonts in the overview 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 OverView get_overview () { 221 foreach (Tab t in tabs.tabs) { 222 if (t.get_display () is OverView) { 223 return (OverView) t.get_display (); 224 } 225 } 226 227 return overview; 228 } 229 230 public static SpacingClassTab get_spacing_class_tab () { 231 return spacing_class_tab; 232 } 233 234 public static void update_glyph_sequence () { 235 TextListener listener = new TextListener (t_("Glyph sequence"), Preferences.get ("glyph_sequence"), t_("Close")); 236 listener.signal_text_input.connect ((text) => { 237 Preferences.set ("glyph_sequence", text); 238 GlyphCanvas.redraw (); 239 }); 240 listener.signal_submit.connect (() => { 241 TabContent.hide_text_input (); 242 }); 243 TabContent.show_text_input (listener); 244 } 245 246 public static MainWindow get_singleton () { 247 return singleton; 248 } 249 250 public static void file_chooser (string title, FileChooser fc, uint flags) { 251 MainWindow.native_window.file_chooser (title, fc, flags); 252 } 253 254 public static void hide_scrollbar () { 255 if (!is_null (MainWindow.native_window)) { 256 MainWindow.native_window.set_scrollbar_size (-1); 257 } 258 } 259 260 public static void show_scrollbar () { 261 if (!is_null (MainWindow.native_window)) { 262 MainWindow.native_window.set_scrollbar_size (scrollbar_size); 263 } 264 } 265 266 public static void set_scrollbar_size (double size) { 267 if (!is_null (MainWindow.native_window)) { 268 scrollbar_size = size; 269 MainWindow.native_window.set_scrollbar_size (size); 270 } 271 } 272 273 public static void set_scrollbar_position (double position) { 274 if (!is_null (MainWindow.native_window)) { 275 MainWindow.native_window.set_scrollbar_position (position); 276 } 277 } 278 279 /** Reaload all paths and help lines from disk. */ 280 public static void clear_glyph_cache () { 281 Glyph g; 282 foreach (Tab t in get_tab_bar ().tabs) { 283 if (t.get_display () is Glyph) { 284 g = (Glyph) t.get_display (); 285 g.add_help_lines (); 286 } 287 } 288 289 GlyphCanvas.redraw (); 290 } 291 292 public static void close_all_tabs () { 293 get_tab_bar ().close_all_tabs (); 294 } 295 296 public static string translate (string s) { 297 return t_(s); 298 } 299 300 public static KerningDisplay get_kerning_display () { 301 return kerning_display; 302 } 303 304 public static LigatureList get_ligature_display () { 305 return ligature_display; 306 } 307 308 public static void next_tab () { 309 TabBar tb = MainWindow.get_tab_bar (); 310 int n = tb.get_selected () + 1; 311 312 if (!(0 <= n < tb.get_length ())) { 313 return; 314 } 315 316 tb.select_tab (n); 317 } 318 319 public static void previous_tab () { 320 TabBar tb = MainWindow.get_tab_bar (); 321 int n = tb.get_selected () - 1; 322 323 if (!(0 <= n < tb.get_length ())) { 324 return; 325 } 326 327 tb.select_tab (n); 328 } 329 330 public static void close_tab () { 331 TabBar tb = MainWindow.get_tab_bar (); 332 int n = tb.get_selected (); 333 334 if (!(0 <= n < tb.get_length ())) { 335 return; 336 } 337 338 tb.close_tab (n); 339 } 340 341 public static void set_toolbox (Toolbox tb) { 342 tools = tb; 343 } 344 } 345 346 } 347