The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Merge ../birdfont-2.x

These changes was commited to the Birdfont repository Sat, 08 Oct 2016 15:34:52 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 08 Oct 2016 15:34:52 +0000 (17:34 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 08 Oct 2016 15:35:43 +0000 (17:35 +0200)
commit a661ec6610a6697ea26b01707df774e84ddc8fa4
tree 640b808eef4d23ef229d02f762960a5c8f4f41bc
parent 24be6eb5628ad0f5cf439068c9a8f1d13d2941d5
parent d2ead8b701fbaec11d5b2685a6ac7e056ec7dd7b
Merge ../birdfont-2.x

12 files changed:
birdfont/GtkWindow.vala
libbirdfont/BirdFont.vala
libbirdfont/EmptyTab.vala
libbirdfont/Glyph.vala
libbirdfont/GlyphCanvas.vala
libbirdfont/MainWindow.vala
libbirdfont/NativeWindow.vala
libbirdfont/RecentFiles.vala
libbirdfont/Scrollbar.vala [new ]
libbirdfont/TabContent.vala
libbirdfont/Theme.vala
--- a/birdfont/GtkWindow.vala +++ b/birdfont/GtkWindow.vala @@ -40,16 +40,12 @@ Clipboard clipboard; string clipboard_svg = ""; string inkscape_clipboard = ""; - - Scrollbar scrollbar; - bool scrollbar_supress_signal = false; ToolboxCanvas toolbox; Task background_task = new Task(idle); public GtkWindow (string title) { - scrollbar = new Scrollbar (Orientation.VERTICAL, new Adjustment (0, 0, 1, 1, 0.01, 0.1)); ((Gtk.Window)this).set_title ("BirdFont"); } @@ -61,16 +57,6 @@ Signal.connect(this, "notify::is-active", (GLib.Callback) window_focus, null); clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); - - scrollbar.value_changed.connect (() => { - double p; - - if (!scrollbar_supress_signal) { - p = scrollbar.get_value () / (1 - scrollbar.adjustment.page_size); - FontDisplay display = MainWindow.get_current_display (); - display.scroll_to (p); - } - }); delete_event.connect (() => { MenuTab.quit (); @@ -90,8 +76,6 @@ string uri = ""; string html = ""; FontDisplay fd = tab.get_display (); - - scrollbar.set_visible (fd.has_scrollbar ()); if (fd.get_name () == "Preview") { uri = Preview.get_uri (); @@ -123,9 +107,8 @@ canvas_box = new Box (Orientation.HORIZONTAL, 0); canvas_box.pack_start (glyph_canvas_area, true, true, 0); canvas_box.pack_start (html_box, true, true, 0); - canvas_box.pack_start (scrollbar, false, true, 0); - tab_box = new Box (Orientation.VERTICAL, 0); + tab_box = new Box (Orientation.VERTICAL, 0); tab_box.pack_start (new TabbarCanvas (MainWindow.get_tab_bar ()), false, false, 0); tab_box.pack_start (canvas_box, true, true, 0); @@ -159,9 +142,7 @@ size_allocate.connect(() => { GlyphCanvas.redraw (); }); - - scrollbar.set_visible (false); - + show_all (); MainWindow.open_recent_files_tab (); @@ -200,17 +181,6 @@ public void font_loaded () { Font f = BirdFont.get_current_font (); set_title (@"$(f.full_name)"); - } - - public void set_scrollbar_size (double size) { - scrollbar.adjustment.page_size = size; - scrollbar.set_visible (size != 0); - } - - public void set_scrollbar_position (double position) { - scrollbar_supress_signal = true; - scrollbar.adjustment.value = position * (1 - scrollbar.adjustment.page_size); - scrollbar_supress_signal = false; } public void dump_clipboard_content (Clipboard clipboard, SelectionData selection_data) {
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -177,7 +177,6 @@ Theme.set_default_colors (); if (theme_version == "" || int.parse (theme_version) < default_theme_version) { - Theme.load_theme ("dark.theme"); Preferences.set ("theme", "dark.theme"); } else {
--- a/libbirdfont/EmptyTab.vala +++ b/libbirdfont/EmptyTab.vala @@ -40,8 +40,8 @@ cr.rectangle (0, 0, allocation.width, allocation.height); cr.fill (); cr.restore (); - } + } } }
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -466,7 +466,7 @@ } } - redraw_area (0, 0, allocation.width, allocation.height); + GlyphCanvas.redraw (); } public virtual void add_path (Path p) { @@ -507,7 +507,7 @@ GridTool.update_lines (); if (!is_null (MainWindow.native_window)) { - MainWindow.native_window.set_scrollbar_size (0); + MainWindow.scrollbar.set_size (0); } update_zoom_bar ();
--- a/libbirdfont/GlyphCanvas.vala +++ b/libbirdfont/GlyphCanvas.vala @@ -84,17 +84,18 @@ if (unlikely (MenuTab.has_suppress_event ())) { warning ("Do not call redraw from background thread."); } else { - signal_redraw_area (x, y, w, h); + signal_redraw_area (x, y, w + (int) MainWindow.scrollbar.width, h); } } public static void redraw () { GlyphCanvas c = MainWindow.get_glyph_canvas (); - if (!is_null (c)) { - c.redraw_area (0, 0, allocation.width, allocation.height); + if (!is_null (c) && !is_null (MainWindow.scrollbar)) { + int w = (int) (allocation.width + MainWindow.scrollbar.width); + c.redraw_area (0, 0, w, allocation.height); } } } }
--- a/libbirdfont/MainWindow.vala +++ b/libbirdfont/MainWindow.vala @@ -32,7 +32,7 @@ public static Dialog dialog; public static SpacingTab spacing_tab; public static Task blocking_background_task; - public static Help help; + public static Scrollbar scrollbar; /** Number of pixels per mm */ public static double units = 1; @@ -56,15 +56,15 @@ dialog = new Dialog (); spacing_tab = new SpacingTab (); blocking_background_task = new Task (null); - help = new Help (); + scrollbar = new Scrollbar (); tools.select_tool (DrawingTools.bezier_tool); - } - - public static Help get_help () { - return help; } + public static bool has_scrollbar () { + return scrollbar.is_visible (); + } + public static void abort_task () { blocking_background_task.cancel (); } @@ -249,26 +249,26 @@ public static void hide_scrollbar () { if (!is_null (MainWindow.native_window)) { - MainWindow.native_window.set_scrollbar_size (-1); + MainWindow.scrollbar.set_size (-1); } } public static void show_scrollbar () { if (!is_null (MainWindow.native_window)) { - MainWindow.native_window.set_scrollbar_size (scrollbar_size); + MainWindow.scrollbar.set_size (scrollbar_size); } } public static void set_scrollbar_size (double size) { if (!is_null (MainWindow.native_window)) { scrollbar_size = size; - MainWindow.native_window.set_scrollbar_size (size); + MainWindow.scrollbar.set_size (size); } } public static void set_scrollbar_position (double position) { if (!is_null (MainWindow.native_window)) { - MainWindow.native_window.set_scrollbar_position (position); + MainWindow.scrollbar.set_position (position); } }
--- a/libbirdfont/NativeWindow.vala +++ b/libbirdfont/NativeWindow.vala @@ -27,9 +27,6 @@ public abstract void set_clipboard (string data); public abstract void set_inkscape_clipboard (string data); - public abstract void set_scrollbar_size (double size); - public abstract void set_scrollbar_position (double position); - /** Notify the UI about the new font. */ public abstract void font_loaded ();
--- a/libbirdfont/RecentFiles.vala +++ b/libbirdfont/RecentFiles.vala @@ -42,12 +42,16 @@ } else if (row.get_index () == RECENT_FONT) { return_if_fail (row.get_row_data () is Font); f = (Font) row.get_row_data (); + MainWindow.scrollbar.set_size (0); + GlyphCanvas.redraw (); load_font (f.get_path ()); } else if (row.get_index () == BACKUP) { return_if_fail (row.get_row_data () is Font); f = (Font) row.get_row_data (); delete_backup (f.get_file_name ()); } + + GlyphCanvas.redraw (); } public override void update_rows () {
diff --git libbirdfont/Scrollbar.vala(new)
--- /dev/null +++ b/libbirdfont/Scrollbar.vala @@ -1,1 +1,155 @@ + /* + Copyright (C) 2016 Johan Mattsson + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Cairo; + + namespace BirdFont { + + public class Scrollbar : GLib.Object { + + public double position = 1; + public double size = 1; + public double width = 0; + public double left_x = 0; + public double height = 0; + public double corner = 0; + public double scroll_max = 1; + public double margin = 0; + + public double motion_x = 0; + public double motion_y = 0; + public bool move = false; + + public Scrollbar () { + } + + public bool button_press (uint button, double x, double y) { + if (!is_visible ()) { + return false; + } + + double h = height * position * scroll_max; + + if (left_x < x < left_x + width && + h - corner < y < h + height * size + corner + 2 * margin) { + + motion_x = x; + motion_y = y; + + move = true; + } + + return left_x < x < left_x + width && 0 < size < 1; + } + + public bool button_release (uint button, double x, double y) { + if (!is_visible ()) { + return false; + } + + if (move) { + move = false; + return true; + } else if (left_x < x < left_x + width) { + double h = height * position * scroll_max; + + if (y > h + size * height) { + position += size; + } + + if (y < h) { + position -= size; + } + + if (position > 1) { + position = 1; + } else if (position < 0) { + position = 0; + } + + TabContent.scroll_to (position); + GlyphCanvas.redraw (); + return true; + } + + return false; + } + + + public bool motion (double x, double y) { + if (!move || !is_visible ()) { + return false; + } + + double p = (y - motion_y) / (height - size * height); + position += p; + + if (position > 1) { + position = 1; + } else if (position < 0) { + position = 0; + } + + TabContent.scroll_to (position); + + GlyphCanvas.redraw (); + + motion_y = y; + motion_x = x; + + return false; + } + + public void draw (Context cr, WidgetAllocation content_allocation, double width) { + if (!is_visible ()) { + return; + } + + cr.save (); + + this.width = width; + this.left_x = content_allocation.width; + this.height = content_allocation.height; + this.corner = 4 * Screen.get_scale (); + this.scroll_max = 1 - size - 2 * corner / height; + this.margin = 2 * Screen.get_scale (); + + Theme.color (cr, "Table Background 1"); + cr.rectangle (left_x, 0, width, height); + cr.fill (); + + Theme.color (cr, "Tool Foreground"); + double h = height * position * scroll_max; + + Widget.draw_rounded_rectangle (cr, left_x + margin, h, width - 2 * margin, height * size + 2 * margin, corner); + cr.fill (); + + cr.restore (); + } + + public bool is_visible () { + return 0 < size < 1; + } + + public void set_size (double size) { + this.size = size; + } + + public void set_position (double position) { + this.position = position; + } + } + + } +
--- a/libbirdfont/TabContent.vala +++ b/libbirdfont/TabContent.vala @@ -72,7 +72,12 @@ public static void draw (WidgetAllocation allocation, Context cr) { AbstractMenu menu; Dialog dialog; + double scollbar_width = 10 * Screen.get_scale (); + if (MainWindow.has_scrollbar()) { + allocation.width -= (int) scollbar_width; + } + if (unlikely (MenuTab.has_suppress_event ())) { cr.save (); Theme.color (cr, "Background 1"); @@ -109,6 +114,10 @@ if (text_input_visible) { draw_text_input (allocation, cr); + } + + if (MainWindow.has_scrollbar()) { + MainWindow.scrollbar.draw (cr, allocation, scollbar_width); } } @@ -129,6 +138,10 @@ } alloc = GlyphCanvas.get_allocation (); + + double scollbar_width = 10 * Screen.get_scale (); + alloc.width += (int) scollbar_width; + pause_surface = Screen.create_background_surface (alloc.width, alloc.height); cr = new Context ((!) pause_surface); cr.scale (Screen.get_scale (), Screen.get_scale ()); @@ -188,7 +201,11 @@ } if (!text_input_visible) { - GlyphCanvas.current_display.motion_notify (x, y); + bool consumed = MainWindow.scrollbar.motion (x, y); + + if (!consumed) { + GlyphCanvas.current_display.motion_notify (x, y); + } } else { text_input.motion (x, y); GlyphCanvas.redraw (); @@ -212,7 +229,11 @@ text_input.button_release (button, x, y); GlyphCanvas.redraw (); } else { - GlyphCanvas.current_display.button_release (button, x, y); + bool consumed = MainWindow.scrollbar.button_release (button, x, y); + + if (!consumed) { + GlyphCanvas.current_display.button_release (button, x, y); + } } } @@ -240,7 +261,11 @@ hide_text_input (); } } else { - GlyphCanvas.current_display.button_press (button, x, y); + bool consumed = MainWindow.scrollbar.button_press (button, x, y); + + if (!consumed) { + GlyphCanvas.current_display.button_press (button, x, y); + } } } }
--- a/libbirdfont/Theme.vala +++ b/libbirdfont/Theme.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Johan Mattsson + Copyright (C) 2015 2016 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -111,8 +111,7 @@ Theme.set_default_color ("Default Background", 238 / 255.0, 239 / 255.0, 243 / 255.0, 1); Theme.set_default_color ("Headline Background", 110 / 255.0, 113 / 255.0, 130 / 255.0, 1); - Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); - + Theme.set_default_color ("Checkbox Background", 255 / 255.0, 255 / 255.0, 255 / 255.0, 1); Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); Theme.set_default_color ("Text Foreground", 3 / 255.0, 16 / 255.0, 24 / 255.0, 1); @@ -324,7 +323,6 @@ Theme.set_default_color ("Headline Background", 0, 0, 0, 1); Theme.set_default_color ("Checkbox Background", 1, 1, 1, 1); - Theme.set_default_color ("Foreground 1", 0, 0, 0, 1); Theme.set_default_color ("Text Foreground", 0, 0, 0, 1);