Commit 06c84d8
Scrollbar in overveiw
Changed files (8)
modifiedbirdfont/GtkWindow.valamodifiedbirdfont/Main.valamodifiedlibbirdfont/EditPoint.valamodifiedlibbirdfont/FontDisplay.valamodifiedlibbirdfont/MainWindow.valamodifiedlibbirdfont/NativeWindow.valamodifiedlibbirdfont/OverView.valadeletedlibbirdfont/Scrollbar.vala
Diff
@@ -42,6 +42,9 @@ public class GtkWindow : Gtk.Window, NativeWindow { string clipboard_svg = ""; string inkscape_clipboard = ""; + VScrollbar scrollbar;+ bool scrollbar_supress_signal = false;+ public GtkWindow (string title) { ((Gtk.Window)this).set_title ("BirdFont"); }@@ -49,6 +52,14 @@ public class GtkWindow : Gtk.Window, NativeWindow { public void init () { clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); + scrollbar = new VScrollbar (new Adjustment (0, 0, 1, 1, 0.01, 0.1));+ scrollbar.value_changed.connect (() => {+ if (!scrollbar_supress_signal) {+ FontDisplay display = MainWindow.get_current_display ();+ display.scroll_to (scrollbar.get_value ());+ }+ });+ margin_bottom = new DrawingArea (); margin_right = new DrawingArea (); @@ -73,16 +84,16 @@ public class GtkWindow : Gtk.Window, NativeWindow { html_canvas.set_editable (true); MainWindow.get_tab_bar ().signal_tab_selected.connect ((f, tab) => {- bool n; File layout_dir; File layout_uri; string uri = ""; FontDisplay fd = tab.get_display ();- + bool html = fd.is_html_canvas (); MainWindow.glyph_canvas.set_current_glyph (fd);- n = fd.is_html_canvas (); - if (n) {+ scrollbar.set_visible (fd.has_scrollbar ());+ + if (html) { layout_dir = FontDisplay.find_layout_dir (); uri = fd.get_uri (); @@ -159,8 +170,8 @@ public class GtkWindow : Gtk.Window, NativeWindow { html_canvas.load_html_string (fd.get_html (), uri); } - html_box.set_visible (n);- glyph_canvas_area.set_visible (!n);+ html_box.set_visible (html);+ glyph_canvas_area.set_visible (!html); } else { html_box.set_visible (false); glyph_canvas_area.set_visible (true);@@ -175,7 +186,6 @@ public class GtkWindow : Gtk.Window, NativeWindow { }); MainWindow.tabs.add_unique_tab (MainWindow.menu_tab, 60, true);- MainWindow.tabs.select_tab_name ("Menu"); glyph_canvas_area = new GlyphCanvasArea (MainWindow.glyph_canvas);@@ -183,6 +193,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { canvas_box = new HBox (false, 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 VBox (false, 0); tab_box.pack_start (new TabbarCanvas (MainWindow.tabs), false, false, 0); @@ -233,6 +244,16 @@ public class GtkWindow : Gtk.Window, NativeWindow { show_all (); }++ public void set_scrollbar_size (double size) {+ scrollbar.adjustment.page_size = size;+ }+ + public void set_scrollbar_position (double position) {+ scrollbar_supress_signal = true;+ scrollbar.adjustment.value = position;+ scrollbar_supress_signal = false;+ } public void color_selection (ColorTool color_tool) { new ColorWindow (color_tool);@@ -28,8 +28,8 @@ public static int main (string[] arg) { GtkWindow native_window; MainWindow window; string file;- BirdFont.BirdFont supplement = new BirdFont.BirdFont ();- supplement.init (arg);+ BirdFont.BirdFont birdfont = new BirdFont.BirdFont ();+ birdfont.init (arg); Gtk.init (ref arg); parse_gtk_rc ();@@ -21,7 +21,7 @@ namespace BirdFont { public enum PointType { NONE,- LINE_QUADRATIC, // line with quadratic handles+ LINE_QUADRATIC, // line with quadratic handle LINE_DOUBLE_CURVE, // line with two quadratic handles LINE_CUBIC, // line with cubic handles CUBIC,@@ -124,7 +124,7 @@ public class EditPoint { h.move_to_coordinate (nx, ny); } - // on the other side+ // the other side h = n.get_right_handle (); if (h.type == PointType.LINE_DOUBLE_CURVE) {@@ -218,20 +218,26 @@ public class EditPoint { } if (left_handle.type == PointType.QUADRATIC) {- left_handle.type = PointType.DOUBLE_CURVE;- right_handle.type = PointType.DOUBLE_CURVE;- prev_rh = get_prev ().data.get_right_handle (); next_lh = get_next ().data.get_left_handle (); - prev_rh.type = PointType.DOUBLE_CURVE; - next_lh.type = PointType.DOUBLE_CURVE;- + if (next_lh.type == PointType.QUADRATIC) {+ next_lh.type = PointType.DOUBLE_CURVE;+ next_lh.length *= 0.5;+ }+ left_handle.move_to_coordinate (prev_rh.x (), prev_rh.y ()); left_handle.length *= 0.5;- right_handle.length *= 0.5;+ + if (right_handle.type == PointType.QUADRATIC) {+ right_handle.length *= 0.5;+ }+ prev_rh.length *= 0.5;- next_lh.length *= 0.5;+ + prev_rh.type = PointType.DOUBLE_CURVE;+ left_handle.type = PointType.DOUBLE_CURVE;+ right_handle.type = PointType.DOUBLE_CURVE; } else if (left_handle.type == PointType.LINE_DOUBLE_CURVE) { left_handle.type = PointType.DOUBLE_CURVE; right_handle.type = PointType.DOUBLE_CURVE;@@ -38,6 +38,13 @@ public abstract class FontDisplay : GLib.Object { return ""; } + public virtual bool has_scrollbar () {+ return false;+ }+ + public virtual void scroll_to (double percent) {+ }+ public virtual bool is_html_canvas () { return false; }@@ -112,7 +112,15 @@ public class MainWindow { public static string? file_chooser_open (string title) { return MainWindow.native_window.file_chooser_open (title); } + + public static void set_scrollbar_size (double size) { + MainWindow.native_window.set_scrollbar_size (size); + } + public static void set_scrollbar_position (double position) { + MainWindow.native_window.set_scrollbar_position (position); + } + public void set_title (string title) { // FIXA: // native_window.set_title (title); @@ -34,6 +34,9 @@ public interface NativeWindow : GLib.Object { public abstract void color_selection (ColorTool color_tool); + public abstract void set_scrollbar_size (double size);+ public abstract void set_scrollbar_position (double position);+ protected void webkit_callback (string s) { FontDisplay fd = MainWindow.get_current_display (); fd.process_property (s);@@ -48,8 +48,6 @@ public class OverView : FontDisplay { int zoom_list_index = 0; List<GlyphCollection> deleted_glyphs = new List<GlyphCollection> ();-- Scrollbar scrollbar; bool all_available = true; @@ -97,33 +95,17 @@ public class OverView : FontDisplay { } }); - scrollbar = new Scrollbar ();- scrollbar.signal_scroll.connect ((delta, delta_last, absolute) => {- if (absolute <= 0.002) {- first_character = 0;- first_visible = 0;- selected = 0;- scroll_top ();- } else if (absolute >= 1) {- scroll_bottom ();- } else {- scroll_to (absolute);- } - - redraw_area (0, 0, allocation.width, allocation.height);- });- update_scrollbar (); }- + void scroll_bottom () { Font f; if (all_available) { f = BirdFont.get_current_font ();- scroll_to_position (f.length () - items_per_row * (rows - 1));+ scroll_to_position (f.length () - items_per_row * rows); } else {- scroll_to_position (glyph_range.length () - items_per_row * (rows - 1));+ scroll_to_position (glyph_range.length () - items_per_row * rows); } } @@ -149,6 +131,10 @@ public class OverView : FontDisplay { return first_visible <= selected <= first_visible + items_per_row * rows; } + public override bool has_scrollbar () {+ return true;+ }+ public override void scroll_wheel_up (double x, double y) { key_up (); close_menus ();@@ -452,10 +438,6 @@ public class OverView : FontDisplay { draw_empty_canvas (allocation, cr); } - if (BirdFont.experimental) {- scrollbar.draw (cr, allocation);- }- n_items = ((allocation.width - 40) / nail_width); rows = (allocation.height / nail_height); @@ -550,11 +532,6 @@ public class OverView : FontDisplay { l = glyph_range.length (); } - // bottom- if (r > l - items_per_row * rows) {- return;- }- if (r < 0) { scroll_top (); return;@@ -568,21 +545,21 @@ public class OverView : FontDisplay { adjust_scroll (); } - public void scroll_to (double percent) {+ public override void scroll_to (double percent) { int64 r;- double l;+ double nrows; Font f; if (all_available) { f = BirdFont.get_current_font ();- l = f.length ();+ nrows = Math.ceil (f.length () / items_per_row); } else {- l = glyph_range.length ();+ nrows = Math.ceil (glyph_range.length () / items_per_row); } - l /= rows;- r = (int64) (percent * l * items_per_row);+ r = (int64) (Math.ceil (percent * nrows) * items_per_row); scroll_to_position (r);+ redraw_area (0, 0, allocation.width, allocation.height); } private void scroll (int64 pixel_adjustment) {@@ -862,18 +839,6 @@ public class OverView : FontDisplay { selected = c; set_glyph_range (gr); }- - public override void motion_notify (double x, double y) {- if (x > allocation.x - 10) {- scrollbar.motion_notify ((int) x, (int) y);- }- }- - public override void button_release (int button, double ex, double ey) {- if (ex > allocation.x - 10) {- scrollbar.button_release (button, ex, ey);- }- } public override void double_click (uint button, double ex, double ey) { selection_click (button, ex, ey);@@ -964,13 +929,7 @@ public class OverView : FontDisplay { } public override void button_press (uint button, double x, double y) {- if (x > allocation.width - 10) {- if (BirdFont.experimental) {- scrollbar.button_press (button, x, y);- }- } else {- selection_click (button, x, y);- }+ selection_click (button, x, y); } /** Returns true if overview shows the last character. */@@ -1068,18 +1027,23 @@ public class OverView : FontDisplay { } public void update_scrollbar () {- double len; Font f;+ double nrows = 0; - if (all_available) {- f = BirdFont.get_current_font ();- len = f.length ();+ if (rows == 0) {+ MainWindow.set_scrollbar_size (0);+ MainWindow.set_scrollbar_position (0); } else {- len = glyph_range.get_length ();- }+ if (all_available) {+ f = BirdFont.get_current_font ();+ nrows = Math.ceil (f.length () / rows);+ } else {+ nrows = Math.ceil (glyph_range.length () / rows);+ } - scrollbar.set_handle_size (items_per_row * rows / len);- scrollbar.set_handle_position (first_visible / len);+ MainWindow.set_scrollbar_size (rows / nrows);+ MainWindow.set_scrollbar_position ((first_visible / rows) / nrows);+ } } } deleted file mode 100644@@ -1,141 +0,0 @@-/*- Copyright (C) 2012 Johan Mattsson-- This program is free software: you can redistribute it and/or modify- it under the terms of the GNU General Public License as published by- the Free Software Foundation, either version 3 of the License, or- (at your option) any later version.-- This program 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 General Public License for more details.-- You should have received a copy of the GNU General Public License- along with this program. If not, see <http://www.gnu.org/licenses/>.-*/--using Cairo;--namespace BirdFont {--class Scrollbar : GLib.Object {- Allocation alloc;-- double pos = 0;- double height = 0.1;- - double y = 0;- double h = 0;- - double y_begin = 0;- double y_last = 0;- bool move = false;- bool visible = true;-- public signal void signal_scroll (double delta, double delta_last, double absolute);-- public Scrollbar () {- }- - public void set_handle_size (double s) {- height = (s < 0.01) ? 0.01 : s;- - if (height > 1) {- height = 1;- }- - h = height * alloc.height;- }-- public void set_handle_position (double p) {- pos = (p > 0) ? p : 0;- y = pos * alloc.height;- }- - public void button_press (uint button, double x, double y) {- move = true;- y_begin = y;- y_last = y;- }- - public void button_release (int button, double ex, double ey) {- move = false;- }- - public void motion_notify (double ex, double ey) {- double d = 0;- double dl = 0;- double m;- - h = height * alloc.height;- m = alloc.height;- - if (move && 0 < ey < m) {- d = ey - y_begin;- dl = ey - y_last;- y += dl;- y_last = ey;- }-- if (y < 0) {- y = 0;- }-- if (y > alloc.height - h) {- y = alloc.height - h;- d = 0;- dl = 0;- }- - if (move) {- pos = y / alloc.height;- }- - if (move) {- signal_scroll (d / (m - h), dl / (m -h), y / (m - h));- pos = y / m;- }-- }- - public void draw (Context cr, Allocation alloc) {- double ax, ay, aw, ah;-- this.alloc = alloc;-- ax = alloc.width - 10;- ay = 0;- aw = alloc.width;- ah = alloc.height;- - if (!visible) {- cr.save ();- cr.rectangle (ax, ay, aw, ah);- cr.set_line_width (0);- cr.set_source_rgba (194/255.0, 194/255.0, 194/255.0, 1);- cr.fill_preserve ();- cr.stroke ();- cr.restore ();- return;- }- - cr.save ();- cr.rectangle (ax, ay, aw, ah);- cr.set_line_width (0);- cr.set_source_rgba (183/255.0, 200/255.0, 223/255.0, 1);- cr.fill_preserve ();- cr.stroke ();- cr.restore (); - - cr.save ();- cr.rectangle (ax, pos * alloc.height, alloc.width, ah * height);- cr.set_line_width (0);- cr.set_source_rgba (133/255.0, 143/255.0, 174/255.0, 1);- cr.fill_preserve ();- cr.stroke ();- cr.restore (); - }-}--}