Fixed size of focus lock area
authorEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 00:27:05 +0000 (00:27 +0000)
committerEnrico Zini <enrico@enricozini.org>
Thu, 10 Dec 2009 00:27:05 +0000 (00:27 +0000)
src/fisheye.vala

index c40c8a73d24afc3dd400664d234f3c38572208f7..1a35918c33a232101e301183834cac504ed67b0f 100644 (file)
@@ -78,7 +78,7 @@ public class FisheyeList : Gtk.DrawingArea
                        pango_cache[i] = null;
 
                // Defaults for properties
-               focus_size = 20;
+               focus_size = 21;
                label_column = 0;
 
                cur_el = 0;
@@ -261,15 +261,25 @@ public class FisheyeList : Gtk.DrawingArea
                        focus_end = 0;
                        focus_starts[0] = 0;
                } else {
-                       focus_first = cur_el > _focus_size/2 ? cur_el-_focus_size/2 : 0;
-                       focus_end = focus_first + _focus_size;
-                       if (focus_end >= label_cache.length) focus_end = label_cache.length;
+                       if (_focus_size >= label_cache.length)
+                       {
+                               focus_first = 0;
+                               focus_end = label_cache.length;
+                       } else {
+                               focus_first = cur_el -_focus_size/2;
+                               if (focus_first < 0) focus_first = 0;
+
+                               focus_end = focus_first + _focus_size;
+                               if (focus_end > label_cache.length)
+                               {
+                                       focus_end = label_cache.length;
+                                       focus_first = focus_end - _focus_size;
+                               }
+                       }
 
                        // Compute starting positions for all items in focus
                        for (int idx = focus_first; idx <= focus_end; ++idx)
-                       {
                                focus_starts[idx - focus_first] = el_y(idx);
-                       }
                }
                focus_layout_needed = false;
        }
@@ -288,24 +298,20 @@ public class FisheyeList : Gtk.DrawingArea
 
                // Focus lock area
                drawable.draw_rectangle(style.bg_gc[Gtk.StateType.ACTIVE], true,
-                       0, focus_starts[0], allocation.width/2, focus_starts[focus_end - focus_first]);
+                       0, focus_starts[0], allocation.width/2, focus_starts[focus_end - focus_first]-focus_starts[0]);
 
                // Focus movement area
                drawable.draw_rectangle(style.bg_gc[Gtk.StateType.INSENSITIVE], true,
                        allocation.width/2, 0, allocation.width, allocation.height);
 
-               // Create a Cairo context
-               //var context = Gdk.cairo_create (drawable);
-
                // Paint items around focus
-               //context.select_font_face(style.font_desc.get_family(), Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
-               for (int idx = focus_first; idx < focus_end; ++idx)
+               for (int idx = 0; idx < focus_end-focus_first; ++idx)
                {
-                       int y0 = focus_starts[idx - focus_first];
-                       int y1 = focus_starts[idx - focus_first + 1];
+                       int y0 = focus_starts[idx];
+                       int y1 = focus_starts[idx + 1];
 
                        Gtk.StateType itemState = Gtk.StateType.NORMAL;
-                       if (idx == cur_el)
+                       if (idx + focus_first == cur_el)
                        {
                                itemState = Gtk.StateType.SELECTED;
                                drawable.draw_rectangle(style.bg_gc[itemState], true,
@@ -313,7 +319,6 @@ public class FisheyeList : Gtk.DrawingArea
                        }
 
                
-                       // TODO: cache pango contexts instead of fontdescs
                        int size = (y1-y0)*80/100;
                        if (size <= 0) size = 1;
                        if (size >= pango_cache.length) size = pango_cache.length - 1;
@@ -325,21 +330,11 @@ public class FisheyeList : Gtk.DrawingArea
                                pc.set_font_description(fd);
                                pango_cache[size] = new Pango.Layout(pc);
                        }
-                       pango_cache[size].set_text(label_cache[idx], -1);
+                       pango_cache[size].set_text(label_cache[idx + focus_first], -1);
                        var layout = pango_cache[size];
-                       //stderr.printf("AZAZA %p\n", layout.get_attributes());
-                       //var attrlist = layout.get_attributes().copy();
-                       //stderr.printf("AL %p\n", attrlist);
-                       //var attrlist = new Pango.AttrList();
-                       //stderr.printf("SIZE %d\n", y1-y0);
-                       //attrlist.insert(new Pango.AttrSize(y1-y0));
-                       //var attrlist = layout.get_attributes();
-                       //attrlist.change(new Pango.AttrSize(y1-y0));
-                       //layout.set_attributes(attrlist);
-                       //layout.set_height(y1-y0);
-                       //int w, h;
-                       //layout.get_pixel_size(out w, out h);
                        Gdk.draw_layout(drawable, style.fg_gc[itemState], 0, y0, layout);
+
+                       //Gdk.draw_line(drawable, style.fg_gc[itemState], 0, y0, allocation.width, y0);
                }
        }