Commit cb4ba92
move glyph canvas out of libbirdfont
Changed files (5)
modifiedsrc/Glyph.valamodifiedsrc/GlyphCanvas.valamodifiedsrc/GtkInterface.valamodifiedsrc/Supplement.valamodifiedsrc/Toolbox.vala
Diff
@@ -215,15 +215,13 @@ public class Glyph : FontDisplay { return 1 / MainWindow.get_current_glyph ().view_zoom; } - public void resized (Allocation o, Allocation n) {+ public void resized () { double a, b, c, d; if (view_zoom > 1) { a = vertical_help_lines.first ().data.get_coordinate (); c = horizontal_help_lines.first ().data.get_coordinate (); - this.allocation = n;- b = vertical_help_lines.first ().data.get_coordinate (); d = horizontal_help_lines.first ().data.get_coordinate (); @@ -22,98 +22,13 @@ using Math; namespace Supplement { -public class GlyphCanvas : DrawingArea { +public class GlyphCanvas : GLib.Object { - FontDisplay current_display; - - Allocation alloc; + public FontDisplay current_display; + public signal void signal_redraw_area (int x, int y, int w, int h); + public Allocation allocation; public GlyphCanvas () { - set_size_request (300, 50); - - alloc.width = 0; - alloc.height = 0; - - current_display = new Glyph (""); - - expose_event.connect ((t, e)=> { - - Allocation allocation; - get_allocation (out allocation); - - if (unlikely (allocation != alloc && alloc.width != 0)) { - // Set size of glyph widget to an even number and notify - // set new allocation for glyph - bool ug = false; - - if (allocation.height % 2 != 0) { - MainWindow.native_window.toggle_expanded_margin_bottom (); - ug = true; - } - - if (allocation.width % 2 != 0) { - MainWindow.native_window.toggle_expanded_margin_right (); - ug = true; - } - - if (ug) { - redraw_area (1, 1, 2, 2); - } else if (unlikely (allocation.width % 2 != 0 || allocation.height % 2 != 0)) { - warning (@"\nGlyph canvas is not divisible by two.\nWidth: $(allocation.width)\nHeight: $(allocation.height)"); - } - - Supplement.current_glyph.resized (alloc, allocation); - } - - alloc = allocation; - - Context cw = cairo_create (get_window()); - - Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, allocation.width, allocation.height); - Context c = new Context (s); - - current_display.draw (allocation, c); - - cw.save (); - cw.set_source_surface (c.get_target (), 0, 0); - cw.paint (); - cw.restore (); - - return true; - }); - - add_events (EventMask.BUTTON_PRESS_MASK | EventMask.BUTTON_RELEASE_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK | EventMask.SCROLL_MASK); - - button_press_event.connect ((t, e)=> { - if (e.type == EventType.BUTTON_PRESS) { - current_display.button_press (e.button, e.x, e.y); - } else if (e.type == EventType.2BUTTON_PRESS) { - current_display.double_click (e.button, e.x, e.y); - } - - return true; - }); - - button_release_event.connect ((t, e)=> { - current_display.button_release ((int) e.button, e.x, e.y); - return true; - }); - - motion_notify_event.connect ((t, e)=> { - current_display.motion_notify (e.x, e.y); - return true; - }); - - scroll_event.connect ((t, e)=> { - if (e.direction == Gdk.ScrollDirection.UP) { - current_display.scroll_wheel_up (e.x, e.y); - } else if (e.direction == Gdk.ScrollDirection.DOWN) { - current_display.scroll_wheel_down (e.x, e.y); - } - - return true; - }); - } public void key_release (uint e) { @@ -126,25 +41,22 @@ public class GlyphCanvas : DrawingArea { public void set_current_glyph (FontDisplay fd) { if (fd is Glyph) { - Allocation allocation; - get_allocation (out allocation); - Glyph g = (Glyph) fd; - g.allocation = allocation; - Supplement.current_glyph = g; - Supplement.current_glyph.resized (alloc, allocation); + Supplement.current_glyph.resized (); + + g.allocation = allocation; warn_if_fail (g.allocation.width != 0 && g.allocation.height != 0); } - + current_display = fd; fd.selected_canvas (); fd.redraw_area.connect ((x, y, w, h) => { - queue_draw_area ((int)x, (int)y, (int)w, (int)h); + signal_redraw_area ((int)x, (int)y, (int)w, (int)h); }); redraw (); @@ -161,14 +73,12 @@ public class GlyphCanvas : DrawingArea { } // Deprecated - private void redraw_area (int x, int y, int w, int h) { - queue_draw_area (x, y, w, h); + public void redraw_area (int x, int y, int w, int h) { + signal_redraw_area (x, y, w, h); } public void redraw () { - Allocation allocation; - get_allocation(out allocation); - queue_draw_area (0, 0, allocation.width, allocation.height); + signal_redraw_area (0, 0, allocation.width, allocation.height); } } @@ -35,7 +35,9 @@ public class GtkWindow : Gtk.Window, NativeWindow { static DrawingArea margin_bottom; static DrawingArea margin_right;- + + GlyphCanvasArea glyph_canvas_area;+ public GtkWindow (string title) { // set_title (title); }@@ -102,17 +104,17 @@ public class GtkWindow : Gtk.Window, NativeWindow { } html_box.set_visible (n);- MainWindow.glyph_canvas.set_visible (!n);+ glyph_canvas_area.set_visible (!n); } else { html_box.set_visible (false);- MainWindow.glyph_canvas.set_visible (true);+ glyph_canvas_area.set_visible (true); } }); // Hide this canvas when window is realized and flip canvas // visibility in tab selection signal. html_canvas.expose_event.connect ((t, e) => {- MainWindow.glyph_canvas.set_visible (false);+ glyph_canvas_area.set_visible (false); return false; }); @@ -120,8 +122,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { MainWindow.tabs.select_tab_name ("Menu"); + glyph_canvas_area = new GlyphCanvasArea (MainWindow.glyph_canvas);+ canvas_box = new HBox (false, 0);- canvas_box.pack_start (MainWindow.glyph_canvas, true, true, 0);+ canvas_box.pack_start (glyph_canvas_area, true, true, 0); canvas_box.pack_start (html_box, true, true, 0); tab_box = new VBox (false, 0);@@ -340,4 +344,96 @@ class ToolboxCanvas : DrawingArea { } } +public class GlyphCanvasArea : DrawingArea {+ GlyphCanvas glyph_canvas;+ Allocation alloc;+ + public GlyphCanvasArea (GlyphCanvas gc) {+ glyph_canvas = gc;++ add_events (EventMask.BUTTON_PRESS_MASK | EventMask.BUTTON_RELEASE_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK | EventMask.SCROLL_MASK);++ glyph_canvas.signal_redraw_area.connect ((x, y, w, h) => {+ queue_draw_area ((int)x, (int)y, (int)w, (int)h);+ });++ expose_event.connect ((t, e)=> { + Allocation allocation;+ get_allocation (out allocation);+ + glyph_canvas.allocation = allocation;+ + if (unlikely (allocation != alloc && alloc.width != 0)) {+ // Set size of glyph widget to an even number and notify + // set new allocation for glyph+ bool ug = false;+ + if (allocation.height % 2 != 0) {+ MainWindow.native_window.toggle_expanded_margin_bottom ();+ ug = true;+ }+ + if (allocation.width % 2 != 0) {+ MainWindow.native_window.toggle_expanded_margin_right ();+ ug = true;+ } + + if (ug) {+ //redraw_area (1, 1, 2, 2);+ } else if (unlikely (allocation.width % 2 != 0 || allocation.height % 2 != 0)) {+ warning (@"\nGlyph canvas is not divisible by two.\nWidth: $(allocation.width)\nHeight: $(allocation.height)");+ }+ + Supplement.current_glyph.resized ();+ }+ + alloc = allocation;+ + Context cw = cairo_create (get_window());+ + Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, allocation.width, allocation.height);+ Context c = new Context (s); ++ glyph_canvas.current_display.draw (allocation, c);++ cw.save ();+ cw.set_source_surface (c.get_target (), 0, 0);+ cw.paint ();+ cw.restore ();+ + return true;+ });++ button_press_event.connect ((t, e)=> {+ if (e.type == EventType.BUTTON_PRESS) {+ glyph_canvas.current_display.button_press (e.button, e.x, e.y); + } else if (e.type == EventType.2BUTTON_PRESS) {+ glyph_canvas.current_display.double_click (e.button, e.x, e.y);+ }+ + return true;+ });+ + button_release_event.connect ((t, e)=> {+ glyph_canvas.current_display.button_release ((int) e.button, e.x, e.y);+ return true;+ });+ + motion_notify_event.connect ((t, e)=> {+ glyph_canvas.current_display.motion_notify (e.x, e.y); + return true;+ });+ + scroll_event.connect ((t, e)=> {+ if (e.direction == Gdk.ScrollDirection.UP) {+ glyph_canvas.current_display.scroll_wheel_up (e.x, e.y);+ } else if (e.direction == Gdk.ScrollDirection.DOWN) {+ glyph_canvas.current_display.scroll_wheel_down (e.x, e.y);+ }+ + return true;+ }); + }+}+ }@@ -30,7 +30,7 @@ public class Supplement { internal static string exec_path = ""; internal static Font current_font; - internal static Glyph current_glyph; + public static Glyph current_glyph; public void init (string[] arg) { int err_arg; @@ -349,7 +349,7 @@ public class Toolbox : GLib.Object { reset_zoom.select_action.connect ((self) => { zoom_tool.store_current_view (); glyph_canvas.get_current_display ().reset_zoom ();- glyph_canvas.queue_draw_area(0, 0, glyph_canvas.allocation.width, glyph_canvas.allocation.height);+ glyph_canvas.redraw_area(0, 0, glyph_canvas.allocation.width, glyph_canvas.allocation.height); }); view_tools.add_tool (reset_zoom); @@ -375,7 +375,7 @@ public class Toolbox : GLib.Object { zoom_tool.zoom_full_background_image (); - glyph_canvas.queue_draw_area(0, 0, glyph_canvas.allocation.width, glyph_canvas.allocation.height);+ glyph_canvas.redraw_area(0, 0, glyph_canvas.allocation.width, glyph_canvas.allocation.height); } }); view_tools.add_tool (zoom_bg);