[gimp/gtk3-port: 239/243] app: port GimpGradientEditor to GtkSyleContext



commit d464797cfb375f1581c6518afaa97d2a86211101
Author: Michael Natterer <mitch gimp org>
Date:   Mon Mar 28 21:18:50 2011 +0200

    app: port GimpGradientEditor to GtkSyleContext

 app/widgets/gimpgradienteditor.c |   87 +++++++++++++++++++++++++++-----------
 1 files changed, 62 insertions(+), 25 deletions(-)
---
diff --git a/app/widgets/gimpgradienteditor.c b/app/widgets/gimpgradienteditor.c
index ab1a182..8df62d9 100644
--- a/app/widgets/gimpgradienteditor.c
+++ b/app/widgets/gimpgradienteditor.c
@@ -219,8 +219,8 @@ static void      control_draw_middle_handle       (GimpGradientEditor *editor,
                                                    gint                height,
                                                    gboolean            selected);
 static void      control_draw_handle              (cairo_t            *cr,
-                                                   GdkColor           *border,
-                                                   GdkColor           *fill,
+                                                   const GdkRGBA      *border,
+                                                   const GdkRGBA      *fill,
                                                    gint                xpos,
                                                    gint                height);
 
@@ -267,6 +267,17 @@ gimp_gradient_editor_class_init (GimpGradientEditorClass *klass)
 
   editor_class->set_data    = gimp_gradient_editor_set_data;
   editor_class->title       = _("Gradient Editor");
+
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_boxed ("handle-color",
+                                                               NULL, NULL,
+                                                               GDK_TYPE_RGBA,
+                                                               GIMP_PARAM_READABLE));
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_boxed ("handle-color-selected",
+                                                               NULL, NULL,
+                                                               GDK_TYPE_RGBA,
+                                                               GIMP_PARAM_READABLE));
 }
 
 static void
@@ -289,6 +300,8 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
   GtkWidget      *hbox;
   GtkWidget      *hint_vbox;
   GimpRGB         transp;
+  GtkCssProvider *css;
+  const gchar    *str;
 
   gimp_rgba_set (&transp, 0.0, 0.0, 0.0, 0.0);
 
@@ -429,6 +442,19 @@ gimp_gradient_editor_init (GimpGradientEditor *editor)
   gimp_rgba_set (&editor->saved_colors[7], 0.0, 1.0, 1.0, GIMP_OPACITY_OPAQUE);
   gimp_rgba_set (&editor->saved_colors[8], 0.0, 0.0, 1.0, GIMP_OPACITY_OPAQUE);
   gimp_rgba_set (&editor->saved_colors[9], 1.0, 0.0, 1.0, GIMP_OPACITY_OPAQUE);
+
+  str =
+    "GimpGradientEditor {\n"
+    "  -GimpGradientEditor-handle-color: mix (@text_color, @base_color, 0.5);\n"
+    "  -GimpGradientEditor-handle-color-selected: mix (@selected_fg_color, @selected_bg_color, 0.5);\n"
+    "}\n";
+
+  css = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (css, str, -1, NULL);
+  gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (editor)),
+                                  GTK_STYLE_PROVIDER (css),
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (css);
 }
 
 static void
@@ -1699,9 +1725,10 @@ control_draw_all (GimpGradientEditor *editor,
                   gdouble             left,
                   gdouble             right)
 {
-  GtkStyle               *control_style;
+  GtkStyleContext        *control_style;
   GimpGradientSegment    *seg;
   GradientEditorDragMode  handle;
+  GdkRGBA                 color;
   gint                    sel_l;
   gint                    sel_r;
   gdouble                 g_pos;
@@ -1712,21 +1739,27 @@ control_draw_all (GimpGradientEditor *editor,
 
   /* Draw selection */
 
-  control_style = gtk_widget_get_style (editor->control);
+  control_style = gtk_widget_get_style_context (editor->control);
 
   sel_l = control_calc_p_pos (editor, editor->control_sel_l->left);
   sel_r = control_calc_p_pos (editor, editor->control_sel_r->right);
 
-  gdk_cairo_set_source_color (cr,
-                              &control_style->base[GTK_STATE_NORMAL]);
+  gtk_style_context_add_class (control_style, GTK_STYLE_CLASS_ENTRY);
+
+  gtk_style_context_get_background_color (control_style, 0,
+                                          &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_rectangle (cr, 0, 0, width, height);
   cairo_fill (cr);
 
-  gdk_cairo_set_source_color (cr,
-                              &control_style->base[GTK_STATE_SELECTED]);
+  gtk_style_context_get_background_color (control_style, GTK_STATE_FLAG_SELECTED,
+                                          &color);
+  gdk_cairo_set_source_rgba (cr, &color);
   cairo_rectangle (cr, sel_l, 0, sel_r - sel_l + 1, height);
   cairo_fill (cr);
 
+  gtk_style_context_remove_class (control_style, GTK_STYLE_CLASS_ENTRY);
+
   /* Draw handles */
 
   selected = FALSE;
@@ -1791,12 +1824,14 @@ control_draw_normal_handle (GimpGradientEditor *editor,
                             gint                height,
                             gboolean            selected)
 {
-  GtkStyle     *style = gtk_widget_get_style (editor->control);
-  GtkStateType  state = selected ? GTK_STATE_SELECTED : GTK_STATE_NORMAL;
+  GdkRGBA border;
+  GdkRGBA fill = { 0.0, 0.0, 0.0, 1.0 };
+
+  gimp_get_style_color (GTK_WIDGET (editor),
+                        selected ? "handle-color-selected" : "handle-color",
+                        &border);
 
-  control_draw_handle (cr,
-                       &style->text_aa[state],
-                       &style->black,
+  control_draw_handle (cr, &border, &fill,
                        control_calc_p_pos (editor, pos), height);
 }
 
@@ -1807,31 +1842,33 @@ control_draw_middle_handle (GimpGradientEditor *editor,
                             gint                height,
                             gboolean            selected)
 {
-  GtkStyle     *style = gtk_widget_get_style (editor->control);
-  GtkStateType  state = selected ? GTK_STATE_SELECTED : GTK_STATE_NORMAL;
+  GdkRGBA border;
+  GdkRGBA fill = { 1.0, 1.0, 1.0, 1.0 };
+
+  gimp_get_style_color (GTK_WIDGET (editor),
+                        selected ? "handle-color-selected" : "handle-color",
+                        &border);
 
-  control_draw_handle (cr,
-                       &style->text_aa[state],
-                       &style->white,
+  control_draw_handle (cr, &border, &fill,
                        control_calc_p_pos (editor, pos), height);
 }
 
 static void
-control_draw_handle (cairo_t  *cr,
-                     GdkColor *border,
-                     GdkColor *fill,
-                     gint      xpos,
-                     gint      height)
+control_draw_handle (cairo_t        *cr,
+                     const GdkRGBA *border,
+                     const GdkRGBA *fill,
+                     gint           xpos,
+                     gint           height)
 {
   cairo_move_to (cr, xpos, 0);
   cairo_line_to (cr, xpos - height / 2.0, height);
   cairo_line_to (cr, xpos + height / 2.0, height);
   cairo_line_to (cr, xpos, 0);
 
-  gdk_cairo_set_source_color (cr, fill);
+  gdk_cairo_set_source_rgba (cr, fill);
   cairo_fill_preserve (cr);
 
-  gdk_cairo_set_source_color (cr, border);
+  gdk_cairo_set_source_rgba (cr, border);
   cairo_set_line_width (cr, 1);
   cairo_stroke (cr);
 }



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