summaryrefslogtreecommitdiff
path: root/src/ui/testgradient.c
diff options
context:
space:
mode:
authorDenis Gorodnichev <[email protected]>2014-07-24 10:37:41 +0400
committerinfirit <[email protected]>2014-11-25 18:06:24 +0100
commitb25395fab6fe9ee38bc0cd359941d0a825d88451 (patch)
treee7b6720a543a00495fae1dd1423d652056bedb03 /src/ui/testgradient.c
parentb8d8e52f0effbf76ff909f88932098d4daf4336e (diff)
downloadmarco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.bz2
marco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.xz
merge metacity(gtk3) changes
merge metacity(gtk3) changes fix warnings clean up unused variables replace UNUSED_VARIABLE by G_GNUC_UNUSED
Diffstat (limited to 'src/ui/testgradient.c')
-rw-r--r--src/ui/testgradient.c117
1 files changed, 85 insertions, 32 deletions
diff --git a/src/ui/testgradient.c b/src/ui/testgradient.c
index 8f8cd6a5..8875452d 100644
--- a/src/ui/testgradient.c
+++ b/src/ui/testgradient.c
@@ -23,12 +23,6 @@
#include "gradient.h"
#include <gtk/gtk.h>
-#ifdef __GNUC__
-#define UNUSED_VARIABLE __attribute__ ((unused))
-#else
-#define UNUSED_VARIABLE
-#endif
-
typedef void (* RenderGradientFunc) (
#if !GTK_CHECK_VERSION (3, 0, 0)
GdkDrawable *drawable,
@@ -47,14 +41,27 @@ draw_checkerboard (GdkDrawable *drawable,
int height)
{
gint i, j, xcount, ycount;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA color1, color2;
+#else
GdkColor color1, color2;
-#if !GTK_CHECK_VERSION (3, 0, 0)
cairo_t *cr;
#endif
#define CHECK_SIZE 10
#define SPACING 2
+#if GTK_CHECK_VERSION (3, 0, 0)
+ color1.red = 30000. / 65535.;
+ color1.green = 30000. / 65535.;
+ color1.blue = 30000. / 65535.;
+ color1.alpha = 1.0;
+
+ color2.red = 50000. / 65535.;
+ color2.green = 50000. / 65535.;
+ color2.blue = 50000. / 65535.;
+ color2.alpha = 1.0;
+#else
color1.red = 30000;
color1.green = 30000;
color1.blue = 30000;
@@ -63,7 +70,6 @@ draw_checkerboard (GdkDrawable *drawable,
color2.green = 50000;
color2.blue = 50000;
-#if !GTK_CHECK_VERSION (3, 0, 0)
cr = gdk_cairo_create (drawable);
#endif
@@ -76,9 +82,17 @@ draw_checkerboard (GdkDrawable *drawable,
while (j < height)
{
if (ycount % 2)
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_cairo_set_source_rgba (cr, &color1);
+#else
gdk_cairo_set_source_color (cr, &color1);
+#endif
else
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_cairo_set_source_rgba (cr, &color2);
+#else
gdk_cairo_set_source_color (cr, &color2);
+#endif
/* If we're outside event->area, this will do nothing.
* It might be mildly more efficient if we handled
@@ -111,10 +125,17 @@ render_simple (
gboolean with_alpha)
{
GdkPixbuf *pixbuf;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA from, to;
+
+ gdk_rgba_parse (&from, "blue");
+ gdk_rgba_parse (&to, "green");
+#else
GdkColor from, to;
gdk_color_parse ("blue", &from);
gdk_color_parse ("green", &to);
+#endif
pixbuf = meta_gradient_create_simple (width, height,
&from, &to,
@@ -138,7 +159,7 @@ render_simple (
META_GRADIENT_HORIZONTAL);
#if GTK_CHECK_VERSION (3, 0, 0)
- draw_checkerboard (cr , width, height);
+ draw_checkerboard (cr, width, height);
#else
draw_checkerboard (drawable, width, height);
#endif
@@ -222,6 +243,16 @@ render_multi (
{
GdkPixbuf *pixbuf;
#define N_COLORS 5
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA colors[N_COLORS];
+
+ gdk_rgba_parse (&colors[0], "red");
+ gdk_rgba_parse (&colors[1], "blue");
+ gdk_rgba_parse (&colors[2], "orange");
+ gdk_rgba_parse (&colors[3], "pink");
+ gdk_rgba_parse (&colors[4], "green");
+#else
GdkColor colors[N_COLORS];
gdk_color_parse ("red", &colors[0]);
@@ -229,6 +260,7 @@ render_multi (
gdk_color_parse ("orange", &colors[2]);
gdk_color_parse ("pink", &colors[3]);
gdk_color_parse ("green", &colors[4]);
+#endif
pixbuf = meta_gradient_create_multi (width, height,
colors, N_COLORS,
@@ -297,12 +329,22 @@ render_interwoven_func (
{
GdkPixbuf *pixbuf;
#define N_COLORS 4
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA colors[N_COLORS];
+
+ gdk_rgba_parse (&colors[0], "red");
+ gdk_rgba_parse (&colors[1], "blue");
+ gdk_rgba_parse (&colors[2], "pink");
+ gdk_rgba_parse (&colors[3], "green");
+#else
GdkColor colors[N_COLORS];
gdk_color_parse ("red", &colors[0]);
gdk_color_parse ("blue", &colors[1]);
gdk_color_parse ("pink", &colors[2]);
gdk_color_parse ("green", &colors[3]);
+#endif
pixbuf = meta_gradient_create_interwoven (width, height,
colors, height / 10,
@@ -327,21 +369,34 @@ expose_callback (GtkWidget *widget,
#endif
{
RenderGradientFunc func = data;
- GdkWindow *window;
GtkAllocation allocation;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *style;
+ GdkRGBA color;
+
+ style = gtk_widget_get_style_context (widget);
+
+ gtk_style_context_save (style);
+ gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget));
+ gtk_style_context_lookup_color (style, "foreground-color", &color);
+ gtk_style_context_restore (style);
+#else
+ GdkWindow *window;
GtkStyle *style;
-#if !GTK_CHECK_VERSION (3, 0, 0)
cairo_t *cr;
-#endif
style = gtk_widget_get_style (widget);
+#endif
+
gtk_widget_get_allocation (widget, &allocation);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
+#else
window = gtk_widget_get_window (widget);
-#if !GTK_CHECK_VERSION (3, 0, 0)
cr = gdk_cairo_create (window);
-#endif
gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]);
+#endif
(* func) (
#if !GTK_CHECK_VERSION (3, 0, 0)
@@ -399,31 +454,29 @@ create_gradient_window (const char *title,
static void
meta_gradient_test (void)
{
- GtkWidget UNUSED_VARIABLE *window;
-
- window = create_gradient_window ("Simple vertical",
- render_vertical_func);
+ create_gradient_window ("Simple vertical",
+ render_vertical_func);
- window = create_gradient_window ("Simple horizontal",
- render_horizontal_func);
+ create_gradient_window ("Simple horizontal",
+ render_horizontal_func);
- window = create_gradient_window ("Simple diagonal",
- render_diagonal_func);
+ create_gradient_window ("Simple diagonal",
+ render_diagonal_func);
- window = create_gradient_window ("Multi vertical",
- render_vertical_multi_func);
+ create_gradient_window ("Multi vertical",
+ render_vertical_multi_func);
- window = create_gradient_window ("Multi horizontal",
- render_horizontal_multi_func);
+ create_gradient_window ("Multi horizontal",
+ render_horizontal_multi_func);
- window = create_gradient_window ("Multi diagonal",
- render_diagonal_multi_func);
+ create_gradient_window ("Multi diagonal",
+ render_diagonal_multi_func);
- window = create_gradient_window ("Interwoven",
- render_interwoven_func);
+ create_gradient_window ("Interwoven",
+ render_interwoven_func);
- window = create_gradient_window ("Simple diagonal with horizontal multi alpha",
- render_diagonal_alpha_func);
+ create_gradient_window ("Simple diagonal with horizontal multi alpha",
+ render_diagonal_alpha_func);
}