From c661cb9bc48ef057baae98a2a732644c24c365c7 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Sat, 13 Sep 2008 23:15:44 +0000 Subject: [PATCH] * Don't use a single cairo_pattern to store the window gradient for ''all'' windows * Use a separate cairo_pattern for each window to store the window gradient in git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6007 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/betawidget/internal-cairo.h | 3 ++- lib/betawidget/window.c | 31 ++++++++++--------------------- lib/betawidget/window.h | 6 ++++++ 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/betawidget/internal-cairo.h b/lib/betawidget/internal-cairo.h index 2c7efa5dd..911887f06 100644 --- a/lib/betawidget/internal-cairo.h +++ b/lib/betawidget/internal-cairo.h @@ -24,8 +24,9 @@ #if defined(LIB_COMPILE) # include #else -// Forward declaration to allow pointers +// Forward declarations to allow pointers typedef struct _cairo cairo_t; +typedef struct _cairo_pattern cairo_pattern_t; #endif #endif // __INCLUDED_BETAWIDGET_INTERNAL_CAIRO_H__ diff --git a/lib/betawidget/window.c b/lib/betawidget/window.c index bf994c1c2..ea2e88c7a 100644 --- a/lib/betawidget/window.c +++ b/lib/betawidget/window.c @@ -26,7 +26,6 @@ static vector *windowVector = NULL; static int screenWidth = -1, screenHeight = -1; static const float borderRadius = 20; -cairo_pattern_t *windowPattern = NULL; const classInfo windowClassInfo = { @@ -64,30 +63,17 @@ static void windowInitVtbl(window *self) self->vtbl = &vtbl; } -static void windowInitOnce() -{ - static bool initialised = false; - - if (!initialised) - { - // Patterns initialization - windowPattern = cairo_pattern_create_linear(0, 0, 0, 384); - cairo_pattern_add_color_stop_rgba(windowPattern, 0, 0.000000, 0.000000, 0.235294, 0.75); - cairo_pattern_add_color_stop_rgba(windowPattern, 0.2, 0.176470, 0.176470, 0.372549, 0.8); - cairo_pattern_add_color_stop_rgba(windowPattern, 0.6, 0.176470, 0.176470, 0.372549, 0.7); - cairo_pattern_add_color_stop_rgba(windowPattern, 1, 0.176470, 0.176470, 0.372549, 0.7); - - initialised = true; - } -} - void windowInit(window *self, const char *id, int w, int h) { // Init our parent widgetInit(WIDGET(self), id); - // Prepare things only have to be initialized once - windowInitOnce(); + // Patterns initialization + self->windowPattern = cairo_pattern_create_linear(0, 0, 0, 384); + cairo_pattern_add_color_stop_rgba(self->windowPattern, 0, 0.000000, 0.000000, 0.235294, 0.75); + cairo_pattern_add_color_stop_rgba(self->windowPattern, 0.2, 0.176470, 0.176470, 0.372549, 0.8); + cairo_pattern_add_color_stop_rgba(self->windowPattern, 0.6, 0.176470, 0.176470, 0.372549, 0.7); + cairo_pattern_add_color_stop_rgba(self->windowPattern, 1, 0.176470, 0.176470, 0.372549, 0.7); // Prepare our vtable windowInitVtbl(self); @@ -121,6 +107,9 @@ void windowDestroyImpl(widget *self) vectorRemoveAt(windowVector, i); } } + + // Remove our pattern + cairo_pattern_destroy(WINDOW(self)->windowPattern); // Call our parents destructor widgetDestroyImpl(self); @@ -185,7 +174,7 @@ void windowDoDrawImpl(widget *self) cairo_t *cr = WIDGET(self)->cr; // Select window gradient - cairo_set_source(cr, windowPattern); + cairo_set_source(cr, WINDOW(self)->windowPattern); // Do the rounded rectangle path windowDoWindowPath(self, cr); diff --git a/lib/betawidget/window.h b/lib/betawidget/window.h index 92573e54f..4c8bab532 100644 --- a/lib/betawidget/window.h +++ b/lib/betawidget/window.h @@ -22,6 +22,7 @@ #define WINDOW_H_ #include "widget.h" +#include "internal-cairo.h" /* * Forward declarations @@ -47,6 +48,11 @@ struct _window * Our vtable */ windowVtbl *vtbl; + + /** + * Window gradient to use when drawing the window. + */ + cairo_pattern_t* windowPattern; }; /*