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