Configurable focus size
authorEnrico Zini <enrico@enricozini.org>
Wed, 9 Dec 2009 19:53:37 +0000 (19:53 +0000)
committerEnrico Zini <enrico@enricozini.org>
Wed, 9 Dec 2009 19:53:37 +0000 (19:53 +0000)
src/fisheye.vala

index 87ae4b069d30f28be89a5fc7df85f7fb0341d8a5..367ea40913b5c294d39c51427b828962a20bd8a1 100644 (file)
@@ -22,6 +22,7 @@ using GLib;
 
 public class FisheyeList : Gtk.DrawingArea
 {
 
 public class FisheyeList : Gtk.DrawingArea
 {
+       protected Gtk.TreeModel model;
        protected Gdk.Pixmap backing_store;
 
        private string[] list;
        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;
        // 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 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()
        {
 
        public FisheyeList()
        {
+               model = null;
                backing_store = null;
 
                list = new string[300];
                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;
                cur_el = 0;
                focus_centre = 0;
                focus_size = 20;
-               focus_starts = new int[focus_size + 1];
                focus_locked = false;
                distortion_factor = 30;
                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);
        }
 
 
                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)
        {
        /* 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;
 
                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)
                {
 
                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)
                } 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);
                }
 
                //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);
        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;
        }
                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_starts[idx - focus_first] = y0;
                        focus_starts[idx - focus_first + 1] = y1;
                }
+               focus_layout_needed = false;
        }
 
        protected void draw(Gdk.Drawable drawable)
        {
        }
 
        protected void draw(Gdk.Drawable drawable)
        {
+               if (focus_layout_needed)
+                       focus_layout();
+
                 Gtk.Style style = get_style();
 
                // Background
                 Gtk.Style style = get_style();
 
                // Background