Render without cairo
authorEnrico Zini <enrico@enricozini.org>
Tue, 8 Dec 2009 20:48:48 +0000 (20:48 +0000)
committerEnrico Zini <enrico@enricozini.org>
Tue, 8 Dec 2009 20:48:48 +0000 (20:48 +0000)
src/fisheye.vala

index a92b66f3846dc227ee2020e6891554a504842b86..caa124096291b814ffdd273d3d7496c5c0dad0a8 100644 (file)
@@ -22,6 +22,8 @@ using GLib;
 
 public class FisheyeList : Gtk.DrawingArea
 {
+       protected Gdk.Pixmap backing_store;
+
        private string[] list;
        protected int cur_el;
        protected double distortion_factor;
@@ -36,6 +38,8 @@ public class FisheyeList : Gtk.DrawingArea
 
        public FisheyeList()
        {
+               backing_store = null;
+
                list = new string[300];
                for (int i = 0; i < 300; ++i)
                        list[i] = "Antani %d".printf(i);
@@ -103,23 +107,26 @@ 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();
                queue_draw();
                return false;
        }
 
        /* Widget is asked to draw itself */
-       public override bool expose_event (Gdk.EventExpose event) {
-
-               // Create a Cairo context
-               var cr = Gdk.cairo_create (this.window);
+       public override bool expose_event (Gdk.EventExpose event)
+       {
+               if (backing_store == null)
+                       return false;
 
-               // Set clipping area in order to avoid unnecessary drawing
-               cr.rectangle(event.area.x, event.area.y,
-                               event.area.width, event.area.height);
-               cr.clip();
+               draw(backing_store);
 
-               draw(cr);
+               window.draw_drawable(
+                       get_style().fg_gc[Gtk.StateType.NORMAL],
+                       backing_store,
+                       event.area.x, event.area.y,
+                       event.area.x, event.area.y,
+                       event.area.width, event.area.height);
 
                return false;
        }
@@ -157,7 +164,7 @@ public class FisheyeList : Gtk.DrawingArea
                }
        }
 
-       protected void draw(Cairo.Context context)
+       protected void draw(Gdk.Drawable drawable)
        {
                 Gtk.Style style = get_style();
        /*
@@ -173,51 +180,51 @@ public class FisheyeList : Gtk.DrawingArea
 
 
                // Background
-               Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.NORMAL]);
-               context.paint();
+               drawable.draw_rectangle(style.bg_gc[Gtk.StateType.NORMAL], true, 0, 0, allocation.width, allocation.height);
 
                // Focus lock area
-               Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.ACTIVE]);
-               context.new_path();
-               context.rectangle(0, focus_starts[0], allocation.width/2, focus_starts[focus_end - focus_first]);
-               context.fill();
-               context.stroke();
+               drawable.draw_rectangle(style.bg_gc[Gtk.StateType.ACTIVE], true,
+                       0, focus_starts[0], allocation.width/2, focus_starts[focus_end - focus_first]);
 
                // Focus movement area
-               Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.INSENSITIVE]);
-               context.new_path();
-               context.rectangle(allocation.width/2, 0, allocation.width, allocation.height);
-               context.fill();
-               context.stroke();
+               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);
+               //context.select_font_face(style.font_desc.get_family(), Cairo.FontSlant.NORMAL, Cairo.FontWeight.NORMAL);
                for (int idx = focus_first; idx < focus_end; ++idx)
                {
                        int y0 = focus_starts[idx - focus_first];
                        int y1 = focus_starts[idx - focus_first + 1];
 
+                       Gtk.StateType itemState = Gtk.StateType.NORMAL;
                        if (idx == cur_el)
                        {
-                               Gdk.cairo_set_source_color(context, style.bg[Gtk.StateType.SELECTED]);
-                               context.new_path();
-                               context.rectangle(0, y0, allocation.width, y1-y0);
-                               context.fill();
-                               context.stroke();
-
-                               Gdk.cairo_set_source_color(context, style.fg[Gtk.StateType.SELECTED]);
-                       } else {
-                               Gdk.cairo_set_source_color(context, style.fg[Gtk.StateType.NORMAL]);
+                               itemState = Gtk.StateType.SELECTED;
+                               drawable.draw_rectangle(style.bg_gc[itemState], true,
+                                       0, y0, allocation.width, y1-y0);
                        }
 
-                       context.new_path();
-                       context.set_font_size(y1-y0);
-                       Cairo.FontExtents extents;
-                       context.font_extents(out extents);
-                       context.move_to(0, y1-extents.descent);
-                       context.text_path(list[idx]);
-                       context.fill();
-                       context.stroke();
+                       var layout = create_pango_layout(list[idx]);
+
+                       var fd = style.font_desc.copy();
+                       //fd.set_size((y1-y0)*Pango.SCALE);
+                       fd.set_absolute_size((y1-y0)*Pango.SCALE);
+                       layout.set_font_description(fd);
+                       //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);
+                       Gdk.draw_layout(drawable, style.fg_gc[itemState], 0, y0, layout);
                }
        }