The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

TabContent.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/TabContent.vala.
New color theme
1 /* 2 Copyright (C) 2014 2015 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 using Cairo; 16 17 namespace BirdFont { 18 19 /** Interface for events from native window to the current tab. */ 20 public class TabContent : GLib.Object { 21 22 static Text text_input_label; 23 static LineTextArea text_input; 24 static Button text_input_button; 25 static bool text_input_visible = false; 26 static TextListener text_callback; 27 28 static const int TEXT_INPUT_HEIGHT = 51; 29 30 public static void zoom_in () { 31 if (MenuTab.suppress_event) { 32 } 33 34 GlyphCanvas.current_display.zoom_in (); 35 } 36 37 public static void zoom_out () { 38 if (MenuTab.suppress_event) { 39 return; 40 } 41 42 GlyphCanvas.current_display.zoom_out (); 43 } 44 45 public static void move_view (double x, double y) { 46 if (MenuTab.suppress_event) { 47 return; 48 } 49 50 GlyphCanvas.current_display.move_view (x, y); 51 } 52 53 public static bool has_scrollbar () { 54 if (MenuTab.suppress_event) { 55 return false; 56 } 57 58 return GlyphCanvas.current_display.has_scrollbar (); 59 } 60 61 public static void scroll_to (double percent) { 62 if (MenuTab.suppress_event) { 63 return; 64 } 65 66 GlyphCanvas.current_display.scroll_to (percent); 67 } 68 69 public static void draw (WidgetAllocation allocation, Context cr) { 70 Menu menu; 71 Dialog dialog; 72 73 if (unlikely (MenuTab.suppress_event)) { 74 cr.save (); 75 Theme.color (cr, "Background 1"); 76 cr.rectangle (0, 0, allocation.width, allocation.height); 77 cr.fill (); 78 cr.restore (); 79 } else { 80 menu = MainWindow.get_menu (); 81 dialog = MainWindow.get_dialog (); 82 83 GlyphCanvas.set_allocation (allocation); 84 MainWindow.get_current_glyph ().resized (allocation); 85 GlyphCanvas.current_display.draw (allocation, cr); 86 87 if (dialog.visible) { 88 dialog.allocation = allocation; 89 dialog.draw (cr); 90 } 91 92 if (menu.show_menu) { 93 menu.draw (allocation, cr); 94 } 95 96 if (FontDisplay.dirty_scrollbar) { 97 GlyphCanvas.current_display.update_scrollbar (); 98 FontDisplay.dirty_scrollbar = false; 99 } 100 101 if (text_input_visible) { 102 draw_text_input (allocation, cr); 103 } 104 } 105 } 106 107 public static void key_press (uint keyval) { 108 if (MenuTab.suppress_event) { 109 return; 110 } 111 112 KeyBindings.add_modifier_from_keyval (keyval); 113 114 if (!text_input_visible) { 115 MainWindow.get_menu ().process_key_binding_events (keyval); 116 GlyphCanvas.current_display.key_press (keyval); 117 } else { 118 text_input.key_press (keyval); 119 } 120 } 121 122 public static void key_release (uint keyval) { 123 if (MenuTab.suppress_event) { 124 return; 125 } 126 127 KeyBindings.remove_modifier_from_keyval (keyval); 128 129 if (!text_input_visible) { 130 GlyphCanvas.current_display.key_release (keyval); 131 } 132 } 133 134 public static void motion_notify (double x, double y) { 135 Toolbox toolbox; 136 137 if (MenuTab.suppress_event) { 138 return; 139 } 140 141 if (!text_input_visible) { 142 GlyphCanvas.current_display.motion_notify (x, y); 143 } else { 144 text_input.motion (x, y); 145 GlyphCanvas.redraw (); 146 } 147 148 toolbox = MainWindow.get_toolbox (); 149 toolbox.hide_tooltip (); 150 } 151 152 public static void button_release (int button, double x, double y) { 153 if (MenuTab.suppress_event) { 154 return; 155 } 156 157 if (MainWindow.get_menu ().show_menu) { 158 MainWindow.get_menu ().button_release (button, x, y); 159 } else { 160 if (text_input_visible) { 161 text_input.button_release (button, x, y); 162 GlyphCanvas.redraw (); 163 } else { 164 GlyphCanvas.current_display.button_release (button, x, y); 165 } 166 } 167 } 168 169 public static void button_press (uint button, double x, double y) { 170 if (MenuTab.suppress_event) { 171 return; 172 } 173 174 if (MainWindow.get_dialog ().visible) { 175 MainWindow.get_dialog ().button_press (button, x, y); 176 } else if (!MainWindow.get_menu ().show_menu) { 177 if (text_input_visible) { 178 text_input.button_press (button, x, y); 179 text_input_button.button_press (button, x, y); 180 181 if (y > TEXT_INPUT_HEIGHT) { 182 hide_text_input (); 183 } 184 } else { 185 GlyphCanvas.current_display.button_press (button, x, y); 186 } 187 } 188 } 189 190 public static void double_click (uint button, double ex, double ey) { 191 if (MenuTab.suppress_event) { 192 return; 193 } 194 195 if (!MainWindow.get_menu ().show_menu) { 196 GlyphCanvas.current_display.double_click (button, ex, ey); 197 } 198 } 199 200 public static void scroll_wheel_up (double x, double y) { 201 if (MenuTab.suppress_event) { 202 return; 203 } 204 205 if (!MainWindow.get_menu ().show_menu) { 206 GlyphCanvas.current_display.scroll_wheel_up (x, y); 207 } 208 } 209 210 public static void scroll_wheel_down (double x, double y) { 211 if (MenuTab.suppress_event) { 212 return; 213 } 214 215 if (!MainWindow.get_menu ().show_menu) { 216 GlyphCanvas.current_display.scroll_wheel_down (x, y); 217 } 218 } 219 220 public static void tap_down (int finger, int x, int y) { 221 if (MenuTab.suppress_event) { 222 return; 223 } 224 225 if (!MainWindow.get_menu ().show_menu) { 226 GlyphCanvas.current_display.tap_down (finger, x, y); 227 } 228 } 229 230 public static void tap_up (int finger, int x, int y) { 231 if (MenuTab.suppress_event) { 232 return; 233 } 234 235 if (!MainWindow.get_menu ().show_menu) { 236 GlyphCanvas.current_display.tap_up (finger, x, y); 237 } 238 } 239 240 public static void tap_move (int finger, int x, int y) { 241 if (MenuTab.suppress_event) { 242 return; 243 } 244 245 if (!MainWindow.get_menu ().show_menu) { 246 GlyphCanvas.current_display.tap_move (finger, x, y); 247 } 248 } 249 250 public static void undo () { 251 if (MenuTab.suppress_event) { 252 return; 253 } 254 255 GlyphCanvas.current_display.undo (); 256 } 257 258 public static void redo () { 259 if (MenuTab.suppress_event) { 260 return; 261 } 262 263 GlyphCanvas.current_display.redo (); 264 } 265 266 public static string path_to_uri (string path) { 267 string uri = path; 268 string wp; 269 270 // wine uri hack 271 if (BirdFont.win32) { 272 wp = wine_to_unix_path (uri); 273 274 if (SearchPaths.find_file (wp, "").query_exists ()) { 275 uri = wp; 276 } 277 278 if (uri.index_of ("\\") > -1) { 279 uri = uri.replace ("\\", "/"); 280 } 281 } 282 283 if (uri.index_of ("/") == 0) { 284 uri = @"file://$uri"; 285 } else { 286 uri = @"file:///$uri"; 287 } 288 289 return uri; 290 } 291 292 public static void draw_text_input (WidgetAllocation allocation, Context cr) { 293 cr.save (); 294 Theme.color (cr, "Default Background"); 295 cr.rectangle (0, 0, allocation.width, TEXT_INPUT_HEIGHT); 296 cr.fill (); 297 cr.restore (); 298 299 Theme.text_color (text_input_label, "Button Foreground"); 300 301 text_input_label.widget_x = 10; 302 text_input_label.widget_y = 17; 303 304 text_input.allocation = allocation; 305 text_input.layout (); 306 text_input.widget_x = text_input_label.get_extent () + 20; 307 text_input.widget_y = 10; 308 text_input.width = allocation.width 309 - text_input_button.get_width () 310 - text_input_label.get_extent () 311 - 40; 312 313 text_input_button.allocation = allocation; 314 text_input_button.widget_x = text_input.widget_x + text_input.width + 10; 315 text_input_button.widget_y = 10; 316 317 text_input_label.draw (cr); 318 text_input.draw (cr); 319 text_input_button.draw (cr); 320 } 321 322 public static void show_text_input (TextListener tl) { 323 text_callback = tl; 324 325 text_input_label = new Text (tl.label); 326 text_input = new LineTextArea (20 * MainWindow.units); 327 text_input_button = new Button (tl.button_label); 328 329 text_input.carret_is_visible = true; 330 331 text_input.set_text (tl.default_text); 332 text_input.text_changed.connect ((text) => { 333 tl.signal_text_input (text); 334 }); 335 336 text_input.enter.connect ((text) => { 337 tl.signal_submit (text); 338 text_input_visible = false; 339 GlyphCanvas.redraw (); 340 }); 341 342 text_input_button.action.connect (() => { 343 tl.signal_submit (text_input.get_text ()); 344 }); 345 346 text_input_visible = true; 347 GlyphCanvas.redraw (); 348 } 349 350 public static void hide_text_input () { 351 text_input_visible = false; 352 text_callback = new TextListener ("", "", ""); 353 } 354 } 355 356 } 357