[shotwell/wip/phako/dark: 4/12] wip: Paint text with gtk_render_layout



commit 92b4c08aa3061a25e17e93dac534931314339400
Author: Jens Georg <mail jensge org>
Date:   Mon Apr 2 11:03:16 2018 +0200

    wip: Paint text with gtk_render_layout

 src/CheckerboardLayout.vala |   42 +++++++++++++++++-------------------------
 1 files changed, 17 insertions(+), 25 deletions(-)
---
diff --git a/src/CheckerboardLayout.vala b/src/CheckerboardLayout.vala
index bd1d3a1..8dbd8c1 100644
--- a/src/CheckerboardLayout.vala
+++ b/src/CheckerboardLayout.vala
@@ -501,7 +501,6 @@ public abstract class CheckerboardItem : ThumbnailView {
 
     protected virtual void paint_shadow(Cairo.Context ctx, Dimensions dimensions, Gdk.Point origin, 
         int radius, float initial_alpha) { 
-        #if 0
         double rgb_all = 0.0;
         
         // top right corner
@@ -532,7 +531,6 @@ public abstract class CheckerboardItem : ThumbnailView {
         ctx.rectangle(origin.x + dimensions.width, origin.y + radius, 
             radius, dimensions.height - radius);
         ctx.fill();
-        #endif
     }
 
     protected void paint_shadow_in_corner(Cairo.Context ctx, int x, int y, 
@@ -589,8 +587,8 @@ public abstract class CheckerboardItem : ThumbnailView {
         return null;
     }
     
-    public void paint(Cairo.Context ctx, Gdk.RGBA bg_color, Gdk.RGBA selected_color,
-        Gdk.RGBA text_color, Gdk.RGBA? border_color) {
+    public void paint(Gtk.StyleContext style_context, Cairo.Context ctx, Gdk.RGBA bg_color, Gdk.RGBA 
selected_color,
+        Gdk.RGBA? border_color) {
         // calc the top-left point of the pixbuf
         Gdk.Point pixbuf_origin = Gdk.Point();
         pixbuf_origin.x = allocation.x + FRAME_WIDTH + BORDER_WIDTH;
@@ -645,8 +643,6 @@ public abstract class CheckerboardItem : ThumbnailView {
             ctx.restore();
         }
         
-        ctx.set_source_rgba(text_color.red, text_color.green, text_color.blue, text_color.alpha);
-        
         // title and subtitles are LABEL_PADDING below bottom of pixbuf
         int text_y = allocation.y + FRAME_WIDTH + pixbuf_dim.height + FRAME_WIDTH + LABEL_PADDING;
         if (title != null && title_visible) {
@@ -656,34 +652,32 @@ public abstract class CheckerboardItem : ThumbnailView {
             title.allocation.y = text_y;
             title.allocation.width = pixbuf_dim.width;
             title.allocation.height = title.get_height();
-            
-            ctx.move_to(title.allocation.x, title.allocation.y);
-            Pango.cairo_show_layout(ctx, title.get_pango_layout(pixbuf_dim.width));
-            
+            style_context.render_layout(ctx, title.allocation.x, title.allocation.y,
+                    title.get_pango_layout(pixbuf_dim.width));
+
             text_y += title.get_height() + LABEL_PADDING;
         }
-        
+
         if (comment != null && comment_visible) {
             comment.allocation.x = allocation.x + FRAME_WIDTH;
             comment.allocation.y = text_y;
             comment.allocation.width = pixbuf_dim.width;
             comment.allocation.height = comment.get_height();
-            
-            ctx.move_to(comment.allocation.x, comment.allocation.y);
-            Pango.cairo_show_layout(ctx, comment.get_pango_layout(pixbuf_dim.width));
-            
+            style_context.render_layout(ctx, comment.allocation.x, comment.allocation.y,
+                    comment.get_pango_layout(pixbuf_dim.width));
+
             text_y += comment.get_height() + LABEL_PADDING;
         }
-        
+
         if (subtitle != null && subtitle_visible) {
             subtitle.allocation.x = allocation.x + FRAME_WIDTH;
             subtitle.allocation.y = text_y;
             subtitle.allocation.width = pixbuf_dim.width;
             subtitle.allocation.height = subtitle.get_height();
-            
-            ctx.move_to(subtitle.allocation.x, subtitle.allocation.y);
-            Pango.cairo_show_layout(ctx, subtitle.get_pango_layout(pixbuf_dim.width));
-            
+
+            style_context.render_layout(ctx, subtitle.allocation.x, subtitle.allocation.y,
+                    subtitle.get_pango_layout(pixbuf_dim.width));
+
             // increment text_y if more text lines follow
         }
         
@@ -1939,8 +1933,8 @@ public class CheckerboardLayout : Gtk.DrawingArea {
             
             // have all items in the exposed area paint themselves
             foreach (CheckerboardItem item in intersection(visible_page)) {
-                item.paint(ctx, bg_color, item.is_selected() ? selected_color : unselected_color,
-                    unselected_color, border_color);
+                item.paint(get_style_context(), ctx, bg_color, item.is_selected() ? selected_color : 
unselected_color,
+                    border_color);
             }
         } else {
             // draw the message in the center of the window
@@ -1956,9 +1950,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
             int y = allocation.height - text_height;
             y = (y > 0) ? y / 2 : 0;
             
-            ctx.set_source_rgb(unselected_color.red, unselected_color.green, unselected_color.blue);
-            ctx.move_to(x, y);
-            Pango.cairo_show_layout(ctx, pango_layout);
+            get_style_context().render_layout(ctx, x, y, pango_layout);
         }
         
         bool result = (base.draw != null) ? base.draw(ctx) : true;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]