[gtk+/cairo-style: 4/21] style: Convert draw_shadow vfunc to Cairo version
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/cairo-style: 4/21] style: Convert draw_shadow vfunc to Cairo version
- Date: Tue, 17 Aug 2010 02:23:59 +0000 (UTC)
commit cc6a6c4d79f4f689938e2b01a884f1cb522358fe
Author: Benjamin Otte <otte redhat com>
Date: Mon Aug 16 15:48:06 2010 +0200
style: Convert draw_shadow vfunc to Cairo version
gtk/gtkstyle.c | 88 +++++++++++++++++++++++++++++++++++++-------------------
gtk/gtkstyle.h | 35 ++++++++++++++--------
2 files changed, 80 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index cb0be83..36ddba9 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -117,10 +117,9 @@ static void gtk_default_draw_vline (GtkStyle *style,
gint y2,
gint x);
static void gtk_default_draw_shadow (GtkStyle *style,
- GdkWindow *window,
+ cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
- GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint x,
@@ -1725,7 +1724,6 @@ static void
draw_thin_shadow (GtkStyle *style,
cairo_t *cr,
GtkStateType state,
- GdkRectangle *area,
gint x,
gint y,
gint width,
@@ -1752,7 +1750,6 @@ draw_spinbutton_shadow (GtkStyle *style,
cairo_t *cr,
GtkStateType state,
GtkTextDirection direction,
- GdkRectangle *area,
gint x,
gint y,
gint width,
@@ -1799,7 +1796,6 @@ static void
draw_menu_shadow (GtkStyle *style,
cairo_t *cr,
GtkStateType state,
- GdkRectangle *area,
gint x,
gint y,
gint width,
@@ -1873,10 +1869,9 @@ get_direction (GtkWidget *widget)
static void
gtk_default_draw_shadow (GtkStyle *style,
- GdkWindow *window,
+ cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
- GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint x,
@@ -1884,24 +1879,14 @@ gtk_default_draw_shadow (GtkStyle *style,
gint width,
gint height)
{
- cairo_t *cr;
GdkColor *gc1 = NULL;
GdkColor *gc2 = NULL;
gint thickness_light;
gint thickness_dark;
gint i;
- sanitize_size (window, &width, &height);
-
- cr = gdk_cairo_create (window);
cairo_set_line_width (cr, 1.0);
- if (area)
- {
- gdk_cairo_rectangle (cr, area);
- cairo_clip (cr);
- }
-
if (shadow_type == GTK_SHADOW_IN)
{
if (detail && strcmp (detail, "buttondefault") == 0)
@@ -1909,39 +1894,34 @@ gtk_default_draw_shadow (GtkStyle *style,
_cairo_draw_rectangle (cr, &style->black, FALSE,
x, y, width - 1, height - 1);
- cairo_destroy (cr);
return;
}
if (detail && strcmp (detail, "trough") == 0)
{
- draw_thin_shadow (style, cr, state_type, area,
+ draw_thin_shadow (style, cr, state_type,
x, y, width, height);
- cairo_destroy (cr);
return;
}
if (GTK_IS_SPIN_BUTTON (widget) &&
detail && strcmp (detail, "spinbutton") == 0)
{
draw_spinbutton_shadow (style, cr, state_type,
- get_direction (widget), area, x, y, width, height);
+ get_direction (widget), x, y, width, height);
- cairo_destroy (cr);
return;
}
}
if (shadow_type == GTK_SHADOW_OUT && detail && strcmp (detail, "menu") == 0)
{
- draw_menu_shadow (style, cr, state_type, area, x, y, width, height);
- cairo_destroy (cr);
+ draw_menu_shadow (style, cr, state_type, x, y, width, height);
return;
}
switch (shadow_type)
{
case GTK_SHADOW_NONE:
- cairo_destroy (cr);
return;
case GTK_SHADOW_IN:
case GTK_SHADOW_ETCHED_IN:
@@ -2192,9 +2172,6 @@ gtk_default_draw_shadow (GtkStyle *style,
x, y + height - 1);
}
}
-
-
- cairo_destroy (cr);
}
static void
@@ -4961,13 +4938,64 @@ gtk_paint_shadow (GtkStyle *style,
gint width,
gint height)
{
+ cairo_t *cr;
+
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
- GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type,
- (GdkRectangle *) area, widget, detail,
+ sanitize_size (window, &width, &height);
+
+ cr = gtk_style_cairo_create (window, area);
+
+ gtk_cairo_paint_shadow (style, cr, state_type, shadow_type,
+ widget, detail,
+ x, y, width, height);
+
+ cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_shadow:
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @widget: (allow-none): the widget
+ * @detail: (allow-none): a style detail
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle
+ * @height: width of the rectangle
+ *
+ * Draws a shadow around the given rectangle in @cr
+ * using the given style and state and shadow type.
+ */
+void
+gtk_cairo_paint_shadow (GtkStyle *style,
+ cairo_t *cr,
+ GtkStateType state_type,
+ GtkShadowType shadow_type,
+ GtkWidget *widget,
+ const gchar *detail,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ g_return_if_fail (GTK_IS_STYLE (style));
+ g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
+ g_return_if_fail (cr != NULL);
+ g_return_if_fail (width >= 0);
+ g_return_if_fail (height >= 0);
+
+ cairo_save (cr);
+
+ GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
+ widget, detail,
x, y, width, height);
+
+ cairo_restore (cr);
}
/**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index d26b012..6ffe514 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -182,10 +182,9 @@ struct _GtkStyleClass
gint y2_,
gint x);
void (*draw_shadow) (GtkStyle *style,
- GdkWindow *window,
+ cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
- GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint x,
@@ -486,17 +485,27 @@ void gtk_cairo_paint_vline (GtkStyle *style,
gint y1_,
gint y2_,
gint x);
-void gtk_paint_shadow (GtkStyle *style,
- GdkWindow *window,
- GtkStateType state_type,
- GtkShadowType shadow_type,
- const GdkRectangle *area,
- GtkWidget *widget,
- const gchar *detail,
- gint x,
- gint y,
- gint width,
- gint height);
+void gtk_paint_shadow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state_type,
+ GtkShadowType shadow_type,
+ const GdkRectangle *area,
+ GtkWidget *widget,
+ const gchar *detail,
+ gint x,
+ gint y,
+ gint width,
+ gint height);
+void gtk_cairo_paint_shadow (GtkStyle *style,
+ cairo_t *cr,
+ GtkStateType state_type,
+ GtkShadowType shadow_type,
+ GtkWidget *widget,
+ const gchar *detail,
+ gint x,
+ gint y,
+ gint width,
+ gint height);
void gtk_paint_arrow (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]