ref: 4d41f0f7178a55dfdce23e5bd5b9c3095ca1754e
parent: 64e78f644cd99f06f70c818e6689622d8652f43f
author: Simon Tatham <anakin@pobox.com>
date: Sat Nov 6 13:47:46 EDT 2010
Fixes to r8997: firstly, move the fix out of #ifdef CAIRO so that it applies to both drawing mechanisms, and secondly, make sure to paint the spare pieces of window in the _puzzle's_ background colour rather than the (sometimes slightly different) system default. [originally from svn r9021] [r8997 == 26c669a6b2892b97b4a9bc6842f633291951fdbd]
--- a/gtk.c
+++ b/gtk.c
@@ -125,11 +125,13 @@
cairo_t *cr;
cairo_surface_t *image;
GdkPixmap *pixmap;
+ GdkColor background; /* for painting outside puzzle area */
#else
GdkPixmap *pixmap;
GdkGC *gc;
GdkColor *colours;
GdkColormap *colmap;
+ int backgroundindex; /* which of colours[] is background */
#endif
int ncolours;
int bbox_l, bbox_r, bbox_u, bbox_d;
@@ -238,18 +240,18 @@
static void set_window_background(frontend *fe, int colour)
{
GdkColormap *colmap;
- GdkColor backg;
colmap = gdk_colormap_get_system();
- backg.red = fe->colours[3*colour + 0] * 65535;
- backg.green = fe->colours[3*colour + 1] * 65535;
- backg.blue = fe->colours[3*colour + 2] * 65535;
- if (!gdk_colormap_alloc_color(colmap, &backg, FALSE, FALSE)) {
+ fe->background.red = fe->colours[3*colour + 0] * 65535;
+ fe->background.green = fe->colours[3*colour + 1] * 65535;
+ fe->background.blue = fe->colours[3*colour + 2] * 65535;
+ if (!gdk_colormap_alloc_color(colmap, &fe->background, FALSE, FALSE)) {
g_error("couldn't allocate background (#%02x%02x%02x)\n",
- backg.red >> 8, backg.green >> 8, backg.blue >> 8);
+ fe->background.red >> 8, fe->background.green >> 8,
+ fe->background.blue >> 8);
}
- gdk_window_set_background(fe->area->window, &backg);
- gdk_window_set_background(fe->window->window, &backg);
+ gdk_window_set_background(fe->area->window, &fe->background);
+ gdk_window_set_background(fe->window->window, &fe->background);
}
static PangoLayout *make_pango_layout(frontend *fe)
@@ -408,41 +410,6 @@
fe->image = NULL;
}
-static void repaint_rectangle(frontend *fe, GtkWidget *widget,
- int x, int y, int w, int h)
-{
- if (x < fe->ox) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y, fe->ox - x, h);
- w -= (fe->ox - x);
- x = fe->ox;
- }
- if (y < fe->oy) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y, w, fe->oy - y);
- h -= (fe->oy - y);
- y = fe->oy;
- }
- if (w > fe->pw) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x + fe->pw, y, w - fe->pw, h);
- w = fe->pw;
- }
- if (h > fe->ph) {
- gdk_draw_rectangle(widget->window,
- widget->style->bg_gc[GTK_WIDGET_STATE(fe->area)],
- TRUE, x, y + fe->ph, w, h - fe->ph);
- h = fe->ph;
- }
- gdk_draw_pixmap(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
- fe->pixmap,
- x - fe->ox, y - fe->oy, x, y, w, h);
-}
-
#endif
/* ----------------------------------------------------------------------
@@ -492,6 +459,7 @@
static void set_window_background(frontend *fe, int colour)
{
+ fe->backgroundindex = colour;
gdk_window_set_background(fe->area->window, &fe->colours[colour]);
gdk_window_set_background(fe->window->window, &fe->colours[colour]);
}
@@ -690,16 +658,43 @@
fe->pixmap = NULL;
}
+#endif
+
static void repaint_rectangle(frontend *fe, GtkWidget *widget,
int x, int y, int w, int h)
{
- gdk_draw_pixmap(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE(fe->area)],
- fe->pixmap,
+ GdkGC *gc = gdk_gc_new(widget->window);
+#ifdef USE_CAIRO
+ gdk_gc_set_foreground(gc, &fe->background);
+#else
+ gdk_gc_set_foreground(gc, &fe->colours[fe->backgroundindex]);
+#endif
+ if (x < fe->ox) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, fe->ox - x, h);
+ w -= (fe->ox - x);
+ x = fe->ox;
+ }
+ if (y < fe->oy) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y, w, fe->oy - y);
+ h -= (fe->oy - y);
+ y = fe->oy;
+ }
+ if (w > fe->pw) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x + fe->pw, y, w - fe->pw, h);
+ w = fe->pw;
+ }
+ if (h > fe->ph) {
+ gdk_draw_rectangle(widget->window, gc,
+ TRUE, x, y + fe->ph, w, h - fe->ph);
+ h = fe->ph;
+ }
+ gdk_draw_pixmap(widget->window, gc, fe->pixmap,
x - fe->ox, y - fe->oy, x, y, w, h);
+ gdk_gc_unref(gc);
}
-
-#endif
/* ----------------------------------------------------------------------
* Pango font functions.