[gtk+] themingengine: use outlines to render focus rings
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] themingengine: use outlines to render focus rings
- Date: Thu, 1 May 2014 16:16:53 +0000 (UTC)
commit 489970bcdc15eaa78286d560fa2bf30a45b87eb6
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Thu May 1 18:12:35 2014 +0200
themingengine: use outlines to render focus rings
Instead of the old non-CSS implementation. This allows us to get rid of
the very last piece of custom theming in Adwaita.
gtk/gtkroundedbox.c | 15 +++++++
gtk/gtkroundedboxprivate.h | 4 ++
gtk/gtkthemingengine.c | 97 ++++++++++----------------------------------
3 files changed, 41 insertions(+), 75 deletions(-)
---
diff --git a/gtk/gtkroundedbox.c b/gtk/gtkroundedbox.c
index 653d27f..5aa53de 100644
--- a/gtk/gtkroundedbox.c
+++ b/gtk/gtkroundedbox.c
@@ -138,6 +138,21 @@ _gtk_rounded_box_apply_border_radius_for_engine (GtkRoundedBox *box,
_gtk_rounded_box_apply_border_radius_for_context (box, _gtk_theming_engine_get_context (engine), junction);
}
+void
+_gtk_rounded_box_apply_outline_radius_for_engine (GtkRoundedBox *box,
+ GtkThemingEngine *engine,
+ GtkJunctionSides junction)
+{
+ GtkCssValue *corner[4];
+
+ corner[GTK_CSS_TOP_LEFT] = _gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_TOP_LEFT_RADIUS);
+ corner[GTK_CSS_TOP_RIGHT] = _gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_TOP_RIGHT_RADIUS);
+ corner[GTK_CSS_BOTTOM_LEFT] = _gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_BOTTOM_LEFT_RADIUS);
+ corner[GTK_CSS_BOTTOM_RIGHT] = _gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_BOTTOM_RIGHT_RADIUS);
+
+ _gtk_rounded_box_apply_border_radius (box, corner, junction);
+}
+
static void
gtk_css_border_radius_grow (GtkRoundedBoxCorner *corner,
double horizontal,
diff --git a/gtk/gtkroundedboxprivate.h b/gtk/gtkroundedboxprivate.h
index a345a5c..6bc96fa 100644
--- a/gtk/gtkroundedboxprivate.h
+++ b/gtk/gtkroundedboxprivate.h
@@ -54,6 +54,10 @@ void _gtk_rounded_box_apply_border_radius_for_context (GtkRoundedBox
GtkStyleContext *context,
GtkJunctionSides junction);
+void _gtk_rounded_box_apply_outline_radius_for_engine (GtkRoundedBox *box,
+ GtkThemingEngine *engine,
+ GtkJunctionSides junction);
+
void _gtk_rounded_box_grow (GtkRoundedBox *box,
double top,
double right,
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 1abe9e8..6e4fe46 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -1742,29 +1742,6 @@ render_frame_internal (GtkThemingEngine *engine,
render_border (cr, &border_box, border_width, hidden_side, colors, border_style);
}
-
- border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_STYLE));
- if (border_style[0] != GTK_BORDER_STYLE_NONE)
- {
- int offset;
-
- border_style[1] = border_style[2] = border_style[3] = border_style[0];
- border_width[0] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
- border_width[3] = border_width[2] = border_width[1] = border_width[0];
- colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_COLOR));
- colors[3] = colors[2] = colors[1] = colors[0];
- offset = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_OFFSET), 100);
-
- /* reinit box here - outlines don't have a border radius */
- _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
- _gtk_rounded_box_shrink (&border_box,
- - border_width[GTK_CSS_TOP] - offset,
- - border_width[GTK_CSS_RIGHT] - offset,
- - border_width[GTK_CSS_LEFT] - offset,
- - border_width[GTK_CSS_BOTTOM] - offset);
-
- render_border (cr, &border_box, border_width, hidden_side, colors, border_style);
- }
}
static void
@@ -1900,63 +1877,33 @@ gtk_theming_engine_render_focus (GtkThemingEngine *engine,
gdouble width,
gdouble height)
{
- GtkStateFlags flags;
- GdkRGBA color;
- gint line_width;
- gint8 *dash_list;
-
- cairo_save (cr);
- flags = gtk_theming_engine_get_state (engine);
-
- gtk_theming_engine_get_color (engine, flags, &color);
-
- gtk_theming_engine_get_style (engine,
- "focus-line-width", &line_width,
- "focus-line-pattern", (gchar *) &dash_list,
- NULL);
-
- cairo_set_line_width (cr, (gdouble) line_width);
+ GtkBorderStyle border_style[4];
+ GtkRoundedBox border_box;
+ double border_width[4];
+ GdkRGBA colors[4];
- if (dash_list[0])
+ border_style[0] = _gtk_css_border_style_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_STYLE));
+ if (border_style[0] != GTK_BORDER_STYLE_NONE)
{
- gint n_dashes = strlen ((const gchar *) dash_list);
- gdouble *dashes = g_new (gdouble, n_dashes);
- gdouble total_length = 0;
- gdouble dash_offset;
- gint i;
-
- for (i = 0; i < n_dashes; i++)
- {
- dashes[i] = dash_list[i];
- total_length += dash_list[i];
- }
-
- /* The dash offset here aligns the pattern to integer pixels
- * by starting the dash at the right side of the left border
- * Negative dash offsets in cairo don't work
- * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
- */
- dash_offset = - line_width / 2.;
-
- while (dash_offset < 0)
- dash_offset += total_length;
-
- cairo_set_dash (cr, dashes, n_dashes, dash_offset);
- g_free (dashes);
- }
-
- cairo_rectangle (cr,
- x + line_width / 2.,
- y + line_width / 2.,
- width - line_width,
- height - line_width);
+ int offset;
- gdk_cairo_set_source_rgba (cr, &color);
- cairo_stroke (cr);
+ border_style[1] = border_style[2] = border_style[3] = border_style[0];
+ border_width[0] = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
+ border_width[3] = border_width[2] = border_width[1] = border_width[0];
+ colors[0] = *_gtk_css_rgba_value_get_rgba (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_COLOR));
+ colors[3] = colors[2] = colors[1] = colors[0];
+ offset = _gtk_css_number_value_get (_gtk_theming_engine_peek_property (engine,
GTK_CSS_PROPERTY_OUTLINE_OFFSET), 100);
- cairo_restore (cr);
+ _gtk_rounded_box_init_rect (&border_box, x, y, width, height);
+ _gtk_rounded_box_apply_outline_radius_for_engine (&border_box, engine, GTK_JUNCTION_NONE);
+ _gtk_rounded_box_shrink (&border_box,
+ - border_width[GTK_CSS_TOP] - offset,
+ - border_width[GTK_CSS_RIGHT] - offset,
+ - border_width[GTK_CSS_LEFT] - offset,
+ - border_width[GTK_CSS_BOTTOM] - offset);
- g_free (dash_list);
+ render_border (cr, &border_box, border_width, 0, colors, border_style);
+ }
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]