X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/blobdiff_plain/bb7d211ec536b03803b0d52e771efb3e10a01c12..ec931a97b9880f43af2ccf0d5049e4e2a860a5bc:/src/fisheye.vala diff --git a/src/fisheye.vala b/src/fisheye.vala index 15550ec..33efc2a 100644 --- a/src/fisheye.vala +++ b/src/fisheye.vala @@ -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 * http://citeseer.ist.psu.edu/sarkar92graphical.html. + * + * 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); } }