diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-06-22 08:30:31 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-06-22 08:30:31 +0000 |
| commit | b176767dfac722d85b3d3b4ab7969e5572189aa0 (patch) | |
| tree | 100e6510f20f829d35a5fe66131d58afdb3f51f8 /osx.m | |
| parent | 64fbdf60ee2eac039c469f867a3e9c0e1b9e119f (diff) | |
| download | puzzles-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 'osx.m')
| -rw-r--r-- | osx.m | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -1232,6 +1232,48 @@ void draw_text(frontend *fe, int x, int y, int fonttype, int fontsize, [string drawAtPoint:point withAttributes:attr]; } +struct blitter { + int w, h; + int x, y; + NSImage *img; +}; +blitter *blitter_new(int w, int h) +{ + blitter *bl = snew(blitter); + bl->x = bl->y = -1; + bl->w = w; + bl->h = h; + bl->img = [[NSImage alloc] initWithSize:NSMakeSize(w, h)]; + [bl->img setFlipped:YES]; + return bl; +} +void blitter_free(blitter *bl) +{ + [bl->img release]; + sfree(bl); +} +void blitter_save(frontend *fe, blitter *bl, int x, int y) +{ + [fe->image unlockFocus]; + [bl->img lockFocus]; + [fe->image drawInRect:NSMakeRect(0, 0, bl->w, bl->h) + fromRect:NSMakeRect(x, y, bl->w, bl->h) + operation:NSCompositeCopy fraction:1.0]; + [bl->img unlockFocus]; + [fe->image lockFocus]; + bl->x = x; + bl->y = y; +} +void blitter_load(frontend *fe, blitter *bl, int x, int y) +{ + if (x == BLITTER_FROMSAVED && y == BLITTER_FROMSAVED) { + x = bl->x; + y = bl->y; + } + [bl->img drawInRect:NSMakeRect(x, y, bl->w, bl->h) + fromRect:NSMakeRect(0, 0, bl->w, bl->h) + operation:NSCompositeCopy fraction:1.0]; +} void draw_update(frontend *fe, int x, int y, int w, int h) { [fe->view setNeedsDisplayInRect:NSMakeRect(x,y,w,h)]; |