Code cleanup
authorEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 13:52:45 +0000 (13:52 +0000)
committerEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 13:52:45 +0000 (13:52 +0000)
README
src/fisheye.vala

diff --git a/README b/README
index 7f0cc1f3d0773be1bb45abf7cca69870e2704686..32388df73f249142ac14635cfe43edf0b22541e1 100644 (file)
--- a/README
+++ b/README
@@ -155,12 +155,14 @@ TODO list / wish list
  http://git.freesmartphone.org/?p=specs.git;a=blob_plain;f=html/index.html;hb=HEAD
 
  * Features to add:
+ - fisheye listview
+    + use a TreeStore as a backend (precaching the elements in an array)
+    + draw something outside of focus area
+    + ensure that the first and last items are selectable
+    - rename in FisheyeListView
  - contacts: show as a fancy focus+context list (see prefuse)
-    - use a TreeStore as a backend (precaching the elements in an array)
     - profile
     - polygen can use the same list
-    - draw something outside of focus area
-    - ensure that the first and last items are selectable
  - s/autotools/cmake
  - Split polygen applet in a separate app, ran via a .desktop file
    (faster zavai startup time, can then integrate a browser in the polygen
index 15550ec3c4517396d5d76c06eea2a64d24f24e59..33efc2ace369a2670ac30a00a607e1a188320c6b 100644 (file)
@@ -27,13 +27,13 @@ protected struct FocusInfo
 }
 
 
-public class FisheyeList : Gtk.DrawingArea
+public class FisheyeListView : Gtk.DrawingArea
 {
        protected Gtk.TreeModel model;
        protected Gdk.Pixmap background;
        protected Gdk.Pixmap backing_store;
 
-       // Pango layouts cached for speed
+       // Renderers used at different sizes
        protected const int steps = 5;
        protected Gtk.CellRendererText[] renderers;
        protected int[] renderer_sizes;
@@ -80,7 +80,7 @@ public class FisheyeList : Gtk.DrawingArea
        //public virtual signal void cursor_changed ();
        public signal void row_activated(Gtk.TreePath path);
 
-       public FisheyeList()
+       public FisheyeListView()
        {
                model = null;
                backing_store = null;
@@ -141,7 +141,7 @@ public class FisheyeList : Gtk.DrawingArea
        /* Mouse button got released */
        public override bool button_release_event(Gdk.EventButton event)
        {
-               stderr.printf("Mouse released on %d %s\n", cur_el, label_cache[cur_el]);
+               //stderr.printf("Mouse released on %d %s\n", cur_el, label_cache[cur_el]);
 
                // Emit row_activated if applicable
                if (model != null)
@@ -225,14 +225,6 @@ public class FisheyeList : Gtk.DrawingArea
                base_layout_needed = true;
        }
 
-       protected int el_y(int idx)
-       {
-               // Distorted position
-               int pos = fisheye(idx);
-               //stderr.printf("%d %f %f\n", idx, undy, pos);
-               return pos;
-       }
-
        protected Gtk.CellRendererText make_cell_renderer()
        {
                var res = new Gtk.CellRendererText();
@@ -530,8 +522,6 @@ public class FisheyeList : Gtk.DrawingArea
        }
 
        /*
-        * The following function is adapted from Prefuse's FisheyeDistortion.java.
-        *
         * A relevant annotation from Prefuse:
         *
         * For more details on this form of transformation, see Manojit Sarkar and 
@@ -539,65 +529,33 @@ public class FisheyeList : Gtk.DrawingArea
         * CHI'92, Human Factors in Computing Systems, p. 83-91, 1992. Available
         * online at <a href="http://citeseer.ist.psu.edu/sarkar92graphical.html">
         * http://citeseer.ist.psu.edu/sarkar92graphical.html</a>. 
+        *
+        * See also http://www.cs.umd.edu/hcil/fisheyemenu/
         */
-
-       /*
-        * Distorts an item's coordinate.
-        * @param x the undistorted coordinate
-        * @param coordinate of the anchor or focus point
-        * @param d disortion factor
-        * @param min the beginning of the display
-        * @param max the end of the display
-        * @return the distorted coordinate
-        */
-       private int fisheye(int idx)
-       {
-               // Autocompute distortion factor
-               // 20 is the pixel size of the item at centre of focus
-               double d = label_cache.length * 20 / allocation.height;
-               if ( d <= 1 )
-                       return idx * allocation.height / label_cache.length;
-
-               double a = (double)cur_el * allocation.height / label_cache.length;
-               double x = (double)idx * allocation.height / label_cache.length;
-               double max = (double)allocation.height;
-
-               if (idx < cur_el)
-               {
-                       double m = a;
-                       if ( m == 0 ) m = max;
-                       double v = (double)(a - x) / m;
-                       v = (double)(d+1)/(d+(1/v));
-                       return (int)Math.round(a - m*v);
-               } else {
-                       double m = max-a;
-                       if ( m == 0 ) m = max;
-                       double v = (double)(x - a) / m;
-                       v = (double)(d+1)/(d+(1/v));
-                       return (int)Math.round(a + m*v);
-               }
-       }
 }
 
 public class Fisheye : Gtk.Window
 {
+       Gtk.ListStore model;
+       FisheyeListView flv;
+
        public Fisheye()
        {
                title = "Fisheye";
                destroy += Gtk.main_quit;
 
-               var list = new FisheyeList();
-               add(list);
+               flv = new FisheyeListView();
+               add(flv);
 
-               var store = new Gtk.ListStore(1, typeof(string));
+               model = new Gtk.ListStore(1, typeof(string));
                Gtk.TreeIter iter;
                var infd = FileStream.open("/tmp/names", "r");
                if (infd == null)
                {
                        for (int i = 0; i < 300; ++i)
                        {
-                               store.append(out iter);
-                               store.set(iter, 0, "Antani %d".printf(i), -1);
+                               model.append(out iter);
+                               model.set(iter, 0, "Antani %d".printf(i), -1);
                        }
                } else {
                        char buf[255];
@@ -606,12 +564,24 @@ public class Fisheye : Gtk.Window
                                string line = infd.gets(buf);
                                if (line == null)
                                        break;
-                               store.append(out iter);
-                               store.set(iter, 0, line, -1);
+                               model.append(out iter);
+                               model.set(iter, 0, line, -1);
                        }
                }
 
-               list.set_model(store);
+               flv.set_model(model);
+
+               flv.row_activated += on_row_activated;
+               //stderr.printf("Mouse released on %d %s\n", cur_el, label_cache[cur_el]);
+       }
+
+       public void on_row_activated(Gtk.TreePath path)
+       {
+               Gtk.TreeIter iter;
+               model.get_iter(out iter, path);
+               string val;
+               model.get(iter, 0, out val, -1);
+               stdout.printf("Clicked on %s\n", val);
        }
 }