The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

GlyphCanvas.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2012 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 using Cairo; 15 using Math; 16 17 namespace BirdFont { 18 19 public class GlyphCanvas : GLib.Object { 20 21 /** Tab content. */ 22 public static FontDisplay current_display; 23 24 public signal void signal_redraw_area (int x, int y, int w, int h); 25 public static WidgetAllocation allocation; 26 27 public GlyphCanvas () { 28 allocation = new WidgetAllocation (); 29 } 30 31 public static WidgetAllocation get_allocation () { 32 return allocation; 33 } 34 35 public static void set_allocation (WidgetAllocation w) { 36 allocation = w.copy (); 37 } 38 39 public void key_release (uint e) { 40 current_display.key_release (e); 41 } 42 43 public void key_press (uint e) { 44 current_display.key_press (e); 45 } 46 47 public static void set_display (FontDisplay fd) { 48 current_display = fd; 49 } 50 51 public void set_current_glyph_collection (GlyphCollection gc, bool signal_selected = true) { 52 Glyph g = gc.get_current (); 53 54 BirdFont.current_glyph_collection = gc; 55 g.resized (allocation); 56 57 if (!is_null (current_display)) { 58 if (signal_selected) { 59 current_display.selected_canvas (); 60 FontDisplay.dirty_scrollbar = true; 61 } 62 63 current_display.redraw_area.connect ((x, y, w, h) => { 64 signal_redraw_area ((int)x, (int)y, (int)w, (int)h); 65 }); 66 67 redraw (); 68 } 69 70 if (!is_null (MainWindow.native_window)) { 71 MainWindow.native_window.update_window_size (); 72 } 73 } 74 75 public static Glyph get_current_glyph () { 76 return MainWindow.get_current_glyph (); 77 } 78 79 public FontDisplay get_current_display () { 80 return current_display; 81 } 82 83 public void redraw_area (int x, int y, int w, int h) { 84 if (unlikely (MenuTab.has_suppress_event ())) { 85 warning ("Do not call redraw from background thread."); 86 } else { 87 signal_redraw_area (x, y, w + (int) MainWindow.scrollbar.width, h); 88 } 89 } 90 91 public static void redraw () { 92 GlyphCanvas c = MainWindow.get_glyph_canvas (); 93 if (!is_null (c) && !is_null (MainWindow.scrollbar)) { 94 int w = (int) (allocation.width + MainWindow.scrollbar.width); 95 c.redraw_area (0, 0, w, allocation.height); 96 } 97 } 98 } 99 100 } 101