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.
Merge branch '2.14' of github.com:johanmattssonm/birdfont into 2.14
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 ('\0', ""); 189 gc.add_glyph (new Glyph ("", '\0')); 190 191 return gc; 192 } 193 194 return BirdFont.current_glyph_collection; 195 } 196 197 public static Glyph get_current_glyph () { 198 return get_current_glyph_collection ().get_current (); 199 } 200 201 public static Toolbox get_toolbox () { 202 return tools; 203 } 204 205 public static Tool get_tool (string n) { 206 return tools.get_tool (n); 207 } 208 209 public static TabBar get_tab_bar () { 210 return tabs; 211 } 212 213 public static Tab get_current_tab () { 214 return tabs.get_selected_tab (); 215 } 216 217 public static bool select_tab (Tab t) { 218 return tabs.selected_open_tab (t); 219 } 220 221 public static OverView get_overview () { 222 foreach (Tab t in tabs.tabs) { 223 if (t.get_display () is OverView) { 224 return (OverView) t.get_display (); 225 } 226 } 227 228 return overview; 229 } 230 231 public static SpacingClassTab get_spacing_class_tab () { 232 return spacing_class_tab; 233 } 234 235 public static void update_glyph_sequence () { 236 TextListener listener = new TextListener (t_("Glyph sequence"), Preferences.get ("glyph_sequence"), t_("Close")); 237 listener.signal_text_input.connect ((text) => { 238 Preferences.set ("glyph_sequence", text); 239 GlyphCanvas.redraw (); 240 }); 241 listener.signal_submit.connect (() => { 242 TabContent.hide_text_input (); 243 }); 244 TabContent.show_text_input (listener); 245 } 246 247 public static MainWindow get_singleton () { 248 return singleton; 249 } 250 251 public static void file_chooser (string title, FileChooser fc, uint flags) { 252 MainWindow.native_window.file_chooser (title, fc, flags); 253 } 254 255 public static void hide_scrollbar () { 256 if (!is_null (MainWindow.native_window)) { 257 MainWindow.native_window.set_scrollbar_size (-1); 258 } 259 } 260 261 public static void show_scrollbar () { 262 if (!is_null (MainWindow.native_window)) { 263 MainWindow.native_window.set_scrollbar_size (scrollbar_size); 264 } 265 } 266 267 public static void set_scrollbar_size (double size) { 268 if (!is_null (MainWindow.native_window)) { 269 scrollbar_size = size; 270 MainWindow.native_window.set_scrollbar_size (size); 271 } 272 } 273 274 public static void set_scrollbar_position (double position) { 275 if (!is_null (MainWindow.native_window)) { 276 MainWindow.native_window.set_scrollbar_position (position); 277 } 278 } 279 280 /** Reaload all paths and help lines from disk. */ 281 public static void clear_glyph_cache () { 282 Glyph g; 283 foreach (Tab t in get_tab_bar ().tabs) { 284 if (t.get_display () is Glyph) { 285 g = (Glyph) t.get_display (); 286 g.add_help_lines (); 287 } 288 } 289 290 GlyphCanvas.redraw (); 291 } 292 293 public static void close_all_tabs () { 294 get_tab_bar ().close_all_tabs (); 295 } 296 297 public static string translate (string s) { 298 return t_(s); 299 } 300 301 public static KerningDisplay get_kerning_display () { 302 return kerning_display; 303 } 304 305 public static LigatureList get_ligature_display () { 306 return ligature_display; 307 } 308 309 public static void next_tab () { 310 TabBar tb = MainWindow.get_tab_bar (); 311 int n = tb.get_selected () + 1; 312 313 if (!(0 <= n < tb.get_length ())) { 314 return; 315 } 316 317 tb.select_tab (n); 318 } 319 320 public static void previous_tab () { 321 TabBar tb = MainWindow.get_tab_bar (); 322 int n = tb.get_selected () - 1; 323 324 if (!(0 <= n < tb.get_length ())) { 325 return; 326 } 327 328 tb.select_tab (n); 329 } 330 331 public static void close_tab () { 332 TabBar tb = MainWindow.get_tab_bar (); 333 int n = tb.get_selected (); 334 335 if (!(0 <= n < tb.get_length ())) { 336 return; 337 } 338 339 tb.close_tab (n); 340 } 341 342 public static void set_toolbox (Toolbox tb) { 343 tools = tb; 344 } 345 } 346 347 } 348