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