summaryrefslogtreecommitdiff
path: root/src/ui/testgradient.c
diff options
context:
space:
mode:
authorFlorian Müllner <fmuellner@gnome.org>2010-08-18 03:09:50 +0200
committerThomas Thurman <tthurman@gnome.org>2010-09-15 11:58:29 -0400
commit3608ff90798cbb6c8d88be902abd56f1a4b16bc0 (patch)
tree4ffb446cbf78ea2defea218df7b9837f2509bfd9 /src/ui/testgradient.c
parent874f55b645d664925b49ee9972cd82dc39287098 (diff)
downloadmetacity-3608ff90798cbb6c8d88be902abd56f1a4b16bc0.tar.gz
metacity-3608ff90798cbb6c8d88be902abd56f1a4b16bc0.tar.bz2
Replace GDK drawing API with cairo
The GDK drawing API was deprecated/removed. https://bugzilla.gnome.org/show_bug.cgi?id=627245
Diffstat (limited to 'src/ui/testgradient.c')
-rw-r--r--src/ui/testgradient.c134
1 files changed, 61 insertions, 73 deletions
diff --git a/src/ui/testgradient.c b/src/ui/testgradient.c
index 02c1364..89d0d22 100644
--- a/src/ui/testgradient.c
+++ b/src/ui/testgradient.c
@@ -24,7 +24,7 @@
#include <gtk/gtk.h>
typedef void (* RenderGradientFunc) (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width,
int height);
@@ -34,28 +34,22 @@ draw_checkerboard (GdkDrawable *drawable,
int height)
{
gint i, j, xcount, ycount;
- GdkGC *gc1, *gc2;
- GdkColor color;
+ GdkColor color1, color2;
+ cairo_t *cr;
#define CHECK_SIZE 10
#define SPACING 2
-
- /* It would be a bit more efficient to keep these
- * GC's around instead of recreating on each expose, but
- * this is the lazy/slow way.
- */
- gc1 = gdk_gc_new (drawable);
- color.red = 30000;
- color.green = 30000;
- color.blue = 30000;
- gdk_gc_set_rgb_fg_color (gc1, &color);
-
- gc2 = gdk_gc_new (drawable);
- color.red = 50000;
- color.green = 50000;
- color.blue = 50000;
- gdk_gc_set_rgb_fg_color (gc2, &color);
+ color1.red = 30000;
+ color1.green = 30000;
+ color1.blue = 30000;
+
+ color2.red = 50000;
+ color2.green = 50000;
+ color2.blue = 50000;
+
+ cr = gdk_cairo_create (drawable);
+
xcount = 0;
i = SPACING;
while (i < width)
@@ -64,23 +58,17 @@ draw_checkerboard (GdkDrawable *drawable,
ycount = xcount % 2; /* start with even/odd depending on row */
while (j < height)
{
- GdkGC *gc;
-
if (ycount % 2)
- gc = gc1;
+ gdk_cairo_set_source_color (cr, &color1);
else
- gc = gc2;
+ gdk_cairo_set_source_color (cr, &color2);
/* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled
* the clipping ourselves, but again we're feeling lazy.
*/
- gdk_draw_rectangle (drawable,
- gc,
- TRUE,
- i, j,
- CHECK_SIZE,
- CHECK_SIZE);
+ cairo_rectangle (cr, i, j, CHECK_SIZE, CHECK_SIZE);
+ cairo_fill (cr);
j += CHECK_SIZE + SPACING;
++ycount;
@@ -90,13 +78,12 @@ draw_checkerboard (GdkDrawable *drawable,
++xcount;
}
- g_object_unref (G_OBJECT (gc1));
- g_object_unref (G_OBJECT (gc2));
+ cairo_destroy (cr);
}
static void
render_simple (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height,
MetaGradientType type,
gboolean with_alpha)
@@ -131,52 +118,48 @@ render_simple (GdkDrawable *drawable,
draw_checkerboard (drawable, width, height);
}
- gdk_draw_pixbuf (drawable,
- gc,
- pixbuf,
- 0, 0,
- 0, 0, width, height,
- GDK_RGB_DITHER_MAX,
- 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
g_object_unref (G_OBJECT (pixbuf));
}
static void
render_vertical_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_simple (drawable, gc, width, height, META_GRADIENT_VERTICAL, FALSE);
+ render_simple (drawable, cr, width, height, META_GRADIENT_VERTICAL, FALSE);
}
static void
render_horizontal_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_simple (drawable, gc, width, height, META_GRADIENT_HORIZONTAL, FALSE);
+ render_simple (drawable, cr, width, height, META_GRADIENT_HORIZONTAL, FALSE);
}
static void
render_diagonal_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_simple (drawable, gc, width, height, META_GRADIENT_DIAGONAL, FALSE);
+ render_simple (drawable, cr, width, height, META_GRADIENT_DIAGONAL, FALSE);
}
static void
render_diagonal_alpha_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_simple (drawable, gc, width, height, META_GRADIENT_DIAGONAL, TRUE);
+ render_simple (drawable, cr, width, height, META_GRADIENT_DIAGONAL, TRUE);
}
static void
render_multi (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height,
MetaGradientType type)
{
@@ -194,13 +177,9 @@ render_multi (GdkDrawable *drawable,
colors, N_COLORS,
type);
- gdk_draw_pixbuf (drawable,
- gc,
- pixbuf,
- 0, 0,
- 0, 0, width, height,
- GDK_RGB_DITHER_NORMAL,
- 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
g_object_unref (G_OBJECT (pixbuf));
#undef N_COLORS
@@ -208,31 +187,31 @@ render_multi (GdkDrawable *drawable,
static void
render_vertical_multi_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_multi (drawable, gc, width, height, META_GRADIENT_VERTICAL);
+ render_multi (drawable, cr, width, height, META_GRADIENT_VERTICAL);
}
static void
render_horizontal_multi_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_multi (drawable, gc, width, height, META_GRADIENT_HORIZONTAL);
+ render_multi (drawable, cr, width, height, META_GRADIENT_HORIZONTAL);
}
static void
render_diagonal_multi_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
- render_multi (drawable, gc, width, height, META_GRADIENT_DIAGONAL);
+ render_multi (drawable, cr, width, height, META_GRADIENT_DIAGONAL);
}
static void
render_interwoven_func (GdkDrawable *drawable,
- GdkGC *gc,
+ cairo_t *cr,
int width, int height)
{
GdkPixbuf *pixbuf;
@@ -248,13 +227,9 @@ render_interwoven_func (GdkDrawable *drawable,
colors, height / 10,
colors + 2, height / 14);
- gdk_draw_pixbuf (drawable,
- gc,
- pixbuf,
- 0, 0,
- 0, 0, width, height,
- GDK_RGB_DITHER_NORMAL,
- 0, 0);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
g_object_unref (G_OBJECT (pixbuf));
}
@@ -265,11 +240,24 @@ expose_callback (GtkWidget *widget,
gpointer data)
{
RenderGradientFunc func = data;
+ GdkWindow *window;
+ GtkAllocation allocation;
+ GtkStyle *style;
+ cairo_t *cr;
+
+ style = gtk_widget_get_style (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+
+ window = gtk_widget_get_window (widget);
+ cr = gdk_cairo_create (window);
+ gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
+
+ (* func) (window,
+ cr,
+ allocation.width,
+ allocation.height);
- (* func) (widget->window,
- widget->style->fg_gc[widget->state],
- widget->allocation.width,
- widget->allocation.height);
+ cairo_destroy (cr);
return TRUE;
}