From: Enrico Zini Date: Wed, 9 Dec 2009 19:53:37 +0000 (+0000) Subject: Configurable focus size X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/commitdiff_plain/073345f85b5ef8e0547c6058be2715e2aefa0197 Configurable focus size --- diff --git a/src/fisheye.vala b/src/fisheye.vala index 87ae4b0..367ea40 100644 --- a/src/fisheye.vala +++ b/src/fisheye.vala @@ -22,6 +22,7 @@ using GLib; public class FisheyeList : Gtk.DrawingArea { + protected Gtk.TreeModel model; protected Gdk.Pixmap backing_store; private string[] list; @@ -33,13 +34,24 @@ public class FisheyeList : Gtk.DrawingArea // Number of items shown before and after the focus element protected int focus_first; protected int focus_end; - protected int focus_size; protected int[] focus_starts; protected bool focus_locked; protected int focus_centre; + protected bool focus_layout_needed; + + protected int _focus_size; + public int focus_size { + get { return _focus_size; } + set { + _focus_size = value; + focus_starts = new int[value+1]; + focus_layout_needed = true; + } + } public FisheyeList() { + model = null; backing_store = null; list = new string[300]; @@ -53,16 +65,20 @@ public class FisheyeList : Gtk.DrawingArea cur_el = 0; focus_centre = 0; focus_size = 20; - focus_starts = new int[focus_size + 1]; focus_locked = false; distortion_factor = 30; - focus_layout(); add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK); } + public unowned Gtk.TreeModel get_model() { return model; } + public void set_model (Gtk.TreeModel? model) + { + this.model = model; + } + /* Mouse button got pressed over widget */ public override bool button_press_event(Gdk.EventButton event) { @@ -85,7 +101,7 @@ public class FisheyeList : Gtk.DrawingArea int x = (int)event.x; int y = (int)event.y; - focus_locked = x < allocation.width/2 && y >= focus_starts[0] && y < focus_starts[focus_end - focus_first]; + focus_locked = !focus_layout_needed && x < allocation.width/2 && y >= focus_starts[0] && y < focus_starts[focus_end - focus_first]; if (focus_locked) { @@ -99,7 +115,7 @@ public class FisheyeList : Gtk.DrawingArea } else { cur_el = y * list.length / allocation.height; if (old_cur_el != cur_el) - focus_layout(); + focus_layout_needed = true; } //stderr.printf("MOTION %f %f CE %d\n", event.x, event.y, cur_el); @@ -114,7 +130,7 @@ public class FisheyeList : Gtk.DrawingArea public override bool configure_event (Gdk.EventConfigure event) { backing_store = new Gdk.Pixmap(window, allocation.width, allocation.height, -1); - focus_layout(); + focus_layout_needed = true; queue_draw(); return false; } @@ -168,10 +184,14 @@ public class FisheyeList : Gtk.DrawingArea focus_starts[idx - focus_first] = y0; focus_starts[idx - focus_first + 1] = y1; } + focus_layout_needed = false; } protected void draw(Gdk.Drawable drawable) { + if (focus_layout_needed) + focus_layout(); + Gtk.Style style = get_style(); // Background