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