aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2005-06-22 08:30:31 +0000
committerSimon Tatham <anakin@pobox.com>2005-06-22 08:30:31 +0000
commitb176767dfac722d85b3d3b4ab7969e5572189aa0 (patch)
tree100e6510f20f829d35a5fe66131d58afdb3f51f8 /gtk.c
parent64fbdf60ee2eac039c469f867a3e9c0e1b9e119f (diff)
downloadpuzzles-b176767dfac722d85b3d3b4ab7969e5572189aa0.zip
puzzles-b176767dfac722d85b3d3b4ab7969e5572189aa0.tar.gz
puzzles-b176767dfac722d85b3d3b4ab7969e5572189aa0.tar.bz2
puzzles-b176767dfac722d85b3d3b4ab7969e5572189aa0.tar.xz
New front end functions to save and restore a region of the puzzle
bitmap. Can be used to implement sprite-like animations: for example, useful for games that wish to implement a user interface which involves dragging an object around the playing area. [originally from svn r5987]
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/gtk.c b/gtk.c
index 5f016ad..e3bffa5 100644
--- a/gtk.c
+++ b/gtk.c
@@ -334,6 +334,57 @@ void draw_polygon(frontend *fe, int *coords, int npoints,
sfree(points);
}
+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 ;