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