[shotwell/wip/phako/dark: 23/24] Use theme colors for rendering CheckerBoardLayout



commit 40468604a67763f0db7e1a1c83a729a91f60ca51
Author: Jens Georg <mail+gitkraken jensge org>
Date:   Sun Apr 1 09:55:56 2018 +0200

    Use theme colors for rendering CheckerBoardLayout
    
     * Remove custom background color
     * Render the text with gtk_render_layout

 src/CheckerboardLayout.vala  |   59 +++++++++-------------
 src/dialogs/Preferences.vala |   45 -----------------
 ui/preferences_dialog.ui     |  111 ++++++++----------------------------------
 3 files changed, 46 insertions(+), 169 deletions(-)
---
diff --git a/src/CheckerboardLayout.vala b/src/CheckerboardLayout.vala
index f39a4f7..77f7f12 100644
--- a/src/CheckerboardLayout.vala
+++ b/src/CheckerboardLayout.vala
@@ -587,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;
@@ -643,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) {
@@ -654,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
         }
         
@@ -871,6 +867,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
     private bool reflow_needed = false;
     
     public CheckerboardLayout(ViewCollection view) {
+        this.get_style_context().add_class("content-view");
         this.view = view;
         
         clear_drag_select();
@@ -885,7 +882,6 @@ public class CheckerboardLayout : Gtk.DrawingArea {
         view.geometries_altered.connect(on_geometries_altered);
         view.items_selected.connect(on_items_selection_changed);
         view.items_unselected.connect(on_items_selection_changed);
-        
 
         Config.Facade.get_instance().colors_changed.connect(on_colors_changed);
 
@@ -1903,10 +1899,13 @@ public class CheckerboardLayout : Gtk.DrawingArea {
 
     private void set_colors(bool in_focus = true) {
         // set up selected/unselected colors
-        selected_color = Config.Facade.get_instance().get_selected_color(in_focus);
-        unselected_color =  Config.Facade.get_instance().get_unselected_color();
+        var val = get_style_context().get_property("border-color", Gtk.StateFlags.SELECTED); 
//Config.Facade.get_instance().get_unselected_color();
+        selected_color = *(Gdk.RGBA*)val.get_boxed();
+        Config.Facade.get_instance().get_selected_color(in_focus);
+        val = get_style_context().get_property("color", Gtk.StateFlags.NORMAL); 
//Config.Facade.get_instance().get_unselected_color();
+
+        unselected_color = *(Gdk.RGBA*)val.get_boxed();
         border_color =  Config.Facade.get_instance().get_border_color();
-        bg_color = Config.Facade.get_instance().get_bg_color();
     }
     
     public override void size_allocate(Gtk.Allocation allocation) {
@@ -1925,12 +1924,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
 
         Gtk.Allocation allocation;
         get_allocation(out allocation);
-        var color = Config.Facade.get_instance().get_bg_color();
-        ctx.save();
-        ctx.set_source_rgb(color.red, color.green, color.blue);
-        ctx.rectangle(0, 0, allocation.width, allocation.height);
-        ctx.fill();
-        ctx.restore();
+        get_style_context().render_background (ctx, 0, 0, allocation.width, allocation.height);
         
         // watch for message mode
         if (message == null) {
@@ -1943,8 +1937,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
@@ -1960,9 +1954,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;
@@ -2008,7 +2000,6 @@ public class CheckerboardLayout : Gtk.DrawingArea {
     private void on_colors_changed() {
         invalidate_transparent_background();
         queue_draw();
-        set_colors();
     }
 
     public override bool focus_in_event(Gdk.EventFocus event) {
diff --git a/src/dialogs/Preferences.vala b/src/dialogs/Preferences.vala
index 847edcd..acf53c6 100644
--- a/src/dialogs/Preferences.vala
+++ b/src/dialogs/Preferences.vala
@@ -19,10 +19,6 @@ public class PreferencesDialog : Gtk.Dialog {
     private static PreferencesDialog preferences_dialog;
 
     [GtkChild]
-    private Gtk.Adjustment bg_color_adjustment;
-    [GtkChild]
-    private Gtk.Scale bg_color_slider;
-    [GtkChild]
     private Gtk.ComboBox photo_editor_combo;
     [GtkChild]
     private Gtk.ComboBox raw_editor_combo;
@@ -72,12 +68,6 @@ public class PreferencesDialog : Gtk.Dialog {
         delete_event.connect(on_delete);
         response.connect(on_close);
 
-        bg_color_adjustment.set_value(bg_color_adjustment.get_upper() -
-            (Config.Facade.get_instance().get_bg_color().red * 65535.0));
-        bg_color_adjustment.value_changed.connect(on_value_changed);
-
-        bg_color_slider.button_press_event.connect(on_bg_color_reset);
-
         transparent_checker_radio.toggled.connect(on_radio_changed);
         transparent_solid_radio.toggled.connect(on_radio_changed);
         transparent_none_radio.toggled.connect(on_radio_changed);
@@ -294,7 +284,6 @@ public class PreferencesDialog : Gtk.Dialog {
     // For items that should only be committed when the dialog is closed, not as soon as the change
     // is made.
     private void commit_on_close() {
-        Config.Facade.get_instance().commit_bg_color();
         Config.Facade.get_instance().set_auto_import_from_library(autoimport.active);
         Config.Facade.get_instance().set_commit_metadata_to_masters(write_metadata.active);
 
@@ -326,25 +315,6 @@ public class PreferencesDialog : Gtk.Dialog {
         commit_on_close();
     }
 
-    private void on_value_changed() {
-        set_background_color((double)(bg_color_adjustment.get_upper() -
-            bg_color_adjustment.get_value()) / 65535.0);
-    }
-
-    private bool on_bg_color_reset(Gdk.EventButton event) {
-        if (event.button == 1 && event.type == Gdk.EventType.BUTTON_PRESS
-            && has_only_key_modifier(event.state, Gdk.ModifierType.CONTROL_MASK)) {
-            // Left Mouse Button and CTRL pressed
-            bg_color_slider.set_value(bg_color_adjustment.get_upper() -
-                (parse_color(Config.Facade.DEFAULT_BG_COLOR).red * 65536.0f));
-            on_value_changed();
-
-            return true;
-        }
-
-        return false;
-    }
-
     private void on_dir_pattern_combo_changed() {
         PathFormat pf = path_formats.get(dir_pattern_combo.get_active());
         if (null == pf.pattern) {
@@ -387,21 +357,6 @@ public class PreferencesDialog : Gtk.Dialog {
         return allow_closing;
     }
 
-    private void set_background_color(double bg_color_value) {
-        Config.Facade.get_instance().set_bg_color(to_grayscale(bg_color_value));
-    }
-
-    private Gdk.RGBA to_grayscale(double color_value) {
-        Gdk.RGBA color = Gdk.RGBA();
-
-        color.red = color_value;
-        color.green = color_value;
-        color.blue = color_value;
-        color.alpha = 1.0;
-
-        return color;
-    }
-
     private void on_photo_editor_changed() {
         int photo_app_choice_index = (photo_editor_combo.get_active() < external_photo_apps.size) ?
             photo_editor_combo.get_active() : external_photo_apps.size;
diff --git a/ui/preferences_dialog.ui b/ui/preferences_dialog.ui
index 60df1c2..4dbaa1f 100644
--- a/ui/preferences_dialog.ui
+++ b/ui/preferences_dialog.ui
@@ -2,12 +2,6 @@
 <!-- Generated with glade 3.20.0 -->
 <interface domain="shotwell">
   <requires lib="gtk+" version="3.18"/>
-  <object class="GtkAdjustment" id="bg_color_adjustment">
-    <property name="upper">65535</property>
-    <property name="step_increment">1000</property>
-    <property name="page_increment">1000</property>
-    <property name="page_size">1000</property>
-  </object>
   <template class="PreferencesDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
     <property name="destroy_with_parent">True</property>
@@ -50,57 +44,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">4</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkBox" id="slider container">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="spacing">6</property>
-                    <child>
-                      <object class="GtkLabel" id="label1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">white</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkScale" id="bg_color_slider">
-                        <property name="width_request">150</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="adjustment">bg_color_adjustment</property>
-                        <property name="draw_value">False</property>
-                        <property name="value_pos">left</property>
-                      </object>
-                      <packing>
-                        <property name="expand">True</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkLabel" id="label2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">black</property>
-                      </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="top_attach">1</property>
+                    <property name="top_attach">3</property>
                   </packing>
                 </child>
                 <child>
@@ -110,7 +54,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">14</property>
+                    <property name="top_attach">13</property>
                   </packing>
                 </child>
                 <child>
@@ -146,27 +90,11 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">3</property>
+                    <property name="top_attach">2</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="bg_color_label">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="halign">start</property>
-                    <property name="margin_left">10</property>
-                    <property name="hexpand">True</property>
-                    <property name="label" translatable="yes">_Background:</property>
-                    <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">bg_color_slider</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">0</property>
-                    <property name="top_attach">1</property>
-                  </packing>
-                </child>
-                <child>
                   <object class="GtkLabel" id="label4">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
@@ -178,7 +106,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">4</property>
+                    <property name="top_attach">3</property>
                   </packing>
                 </child>
                 <child>
@@ -194,7 +122,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">5</property>
+                    <property name="top_attach">4</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -213,7 +141,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">6</property>
+                    <property name="top_attach">5</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -229,7 +157,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">7</property>
+                    <property name="top_attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -242,7 +170,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">9</property>
+                    <property name="top_attach">8</property>
                   </packing>
                 </child>
                 <child>
@@ -258,7 +186,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">10</property>
+                    <property name="top_attach">9</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -276,7 +204,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">11</property>
+                    <property name="top_attach">10</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -293,7 +221,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">12</property>
+                    <property name="top_attach">11</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -311,7 +239,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">13</property>
+                    <property name="top_attach">12</property>
                     <property name="width">2</property>
                   </packing>
                 </child>
@@ -327,7 +255,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">14</property>
+                    <property name="top_attach">13</property>
                   </packing>
                 </child>
                 <child>
@@ -337,7 +265,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">7</property>
+                    <property name="top_attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -350,7 +278,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">8</property>
+                    <property name="top_attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -401,7 +329,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">8</property>
+                    <property name="top_attach">7</property>
                   </packing>
                 </child>
                 <child>
@@ -415,7 +343,7 @@
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
-                    <property name="top_attach">2</property>
+                    <property name="top_attach">1</property>
                   </packing>
                 </child>
                 <child>
@@ -500,9 +428,12 @@
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
-                    <property name="top_attach">2</property>
+                    <property name="top_attach">1</property>
                   </packing>
                 </child>
+                <child>
+                  <placeholder/>
+                </child>
               </object>
             </child>
             <child type="tab">


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