X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/1fad7a3b87eb8156ec2ba0a9cff82f1407af24cf..4e1f57ba31665f1d681ecd245bdc74b8c6942cf4:/gtk.c diff --git a/gtk.c b/gtk.c index 5f016ad..9b95d48 100644 --- a/gtk.c +++ b/gtk.c @@ -25,6 +25,35 @@ #define USE_PANGO #endif +#ifdef DEBUGGING +static FILE *debug_fp = NULL; + +void dputs(char *buf) +{ + if (!debug_fp) { + debug_fp = fopen("debug.log", "w"); + } + + fputs(buf, stderr); + + if (debug_fp) { + fputs(buf, debug_fp); + fflush(debug_fp); + } +} + +void debug_printf(char *fmt, ...) +{ + char buf[4096]; + va_list ap; + + va_start(ap, fmt); + vsprintf(buf, fmt, ap); + dputs(buf); + va_end(ap); +} +#endif + /* ---------------------------------------------------------------------- * Error reporting functions used elsewhere. */ @@ -334,6 +363,66 @@ void draw_polygon(frontend *fe, int *coords, int npoints, sfree(points); } +void draw_circle(frontend *fe, int cx, int cy, int radius, + int fill, int colour) +{ + gdk_gc_set_foreground(fe->gc, &fe->colours[colour]); + gdk_draw_arc(fe->pixmap, fe->gc, fill, + cx - radius, cy - radius, + 2 * radius, 2 * radius, 0, 360 * 64); +} + +struct blitter { + GdkPixmap *pixmap; + int w, h, x, y; +}; + +blitter *blitter_new(int w, int h) +{ + /* + * We can't create the pixmap right now, because fe->window + * might not yet exist. So we just cache w and h and create it + * during the firs call to blitter_save. + */ + blitter *bl = snew(blitter); + bl->pixmap = NULL; + bl->w = w; + bl->h = h; + return bl; +} + +void blitter_free(blitter *bl) +{ + if (bl->pixmap) + gdk_pixmap_unref(bl->pixmap); + sfree(bl); +} + +void blitter_save(frontend *fe, blitter *bl, int x, int y) +{ + if (!bl->pixmap) + bl->pixmap = gdk_pixmap_new(fe->area->window, bl->w, bl->h, -1); + bl->x = x; + bl->y = y; + gdk_draw_pixmap(bl->pixmap, + fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)], + fe->pixmap, + x, y, 0, 0, bl->w, bl->h); +} + +void blitter_load(frontend *fe, blitter *bl, int x, int y) +{ + assert(bl->pixmap); + if (x == BLITTER_FROMSAVED && y == BLITTER_FROMSAVED) { + x = bl->x; + y = bl->y; + } + gdk_draw_pixmap(fe->pixmap, + fe->area->style->fg_gc[GTK_WIDGET_STATE(fe->area)], + bl->pixmap, + 0, 0, x, y, bl->w, bl->h); +} + void draw_update(frontend *fe, int x, int y, int w, int h) { if (fe->bbox_l > x ) fe->bbox_l = x ; @@ -909,7 +998,11 @@ static void menu_preset_event(GtkMenuItem *menuitem, gpointer data) fe->w = x; fe->h = y; gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y); - gtk_window_resize(GTK_WINDOW(fe->window), 1, 1); + { + GtkRequisition req; + gtk_widget_size_request(GTK_WIDGET(fe->window), &req); + gtk_window_resize(GTK_WIDGET(fe->window), req.width, req.height); + } } GdkAtom compound_text_atom, utf8_string_atom; @@ -1054,7 +1147,11 @@ static void menu_config_event(GtkMenuItem *menuitem, gpointer data) fe->w = x; fe->h = y; gtk_drawing_area_size(GTK_DRAWING_AREA(fe->area), x, y); - gtk_window_resize(GTK_WINDOW(fe->window), 1, 1); + { + GtkRequisition req; + gtk_widget_size_request(GTK_WIDGET(fe->window), &req); + gtk_window_resize(GTK_WIDGET(fe->window), req.width, req.height); + } } static void menu_about_event(GtkMenuItem *menuitem, gpointer data)