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