[gimp/gtk3-port: 201/454] app: port GimpGradientEditor to GtkSyleContext
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 201/454] app: port GimpGradientEditor to GtkSyleContext
- Date: Wed, 16 May 2018 21:37:35 +0000 (UTC)
commit 5e3b15c9c0bd733261f4702ee688eccd22ad74df
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 b047e8b..2dc14bb 100644
--- a/app/widgets/gimpgradienteditor.c
+++ b/app/widgets/gimpgradienteditor.c
@@ -221,8 +221,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);
@@ -269,6 +269,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
@@ -291,6 +302,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);
@@ -432,6 +445,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
@@ -1696,9 +1722,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;
@@ -1709,21 +1736,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;
@@ -1788,12 +1821,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);
}
@@ -1804,31 +1839,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]