1.1 --- a/examples/vga/main.c Tue Nov 13 14:35:22 2018 +0100
1.2 +++ b/examples/vga/main.c Tue Nov 13 15:17:37 2018 +0100
1.3 @@ -162,7 +162,7 @@
1.4
1.5 /* Prepare the frame for updates. */
1.6
1.7 - image_unplot_sprite(&s);
1.8 + viewport_unplot_sprite_from_image(&v, &s, &scr);
1.9
1.10 /* Scroll in the indicated direction. */
1.11
2.1 --- a/include/image.h Tue Nov 13 14:35:22 2018 +0100
2.2 +++ b/include/image.h Tue Nov 13 15:17:37 2018 +0100
2.3 @@ -152,6 +152,9 @@
2.4
2.5 void image_unplot_sprite(sprite_t *s);
2.6
2.7 +void image_unplot_sprite_from_image(sprite_t *s, sprite_t *bg,
2.8 + int xorigin, int yorigin);
2.9 +
2.10 /* Convenience operations. */
2.11
2.12 void image_plot_sprite_section(sprite_t *s,
2.13 @@ -165,4 +168,8 @@
2.14 void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin,
2.15 int xstep, int ystep);
2.16
2.17 +void image_update_tiled_image(sprite_t *s, int xorigin, int yorigin,
2.18 + int width, int height,
2.19 + int xdisplay, int ydisplay);
2.20 +
2.21 #endif /* __IMAGE_H__ */
3.1 --- a/include/viewport.h Tue Nov 13 14:35:22 2018 +0100
3.2 +++ b/include/viewport.h Tue Nov 13 15:17:37 2018 +0100
3.3 @@ -21,6 +21,7 @@
3.4 #define __VIEWPORT_H__
3.5
3.6 #include "display.h"
3.7 +#include "image.h"
3.8
3.9
3.10
3.11 @@ -77,4 +78,8 @@
3.12
3.13 void viewport_update_origin(viewport_t *v, int dx, int dy);
3.14
3.15 +/* Update operations. */
3.16 +
3.17 +void viewport_unplot_sprite_from_image(viewport_t *v, sprite_t *s, sprite_t *bg);
3.18 +
3.19 #endif /* __VIEWPORT_H__ */
4.1 --- a/lib/image.c Tue Nov 13 14:35:22 2018 +0100
4.2 +++ b/lib/image.c Tue Nov 13 15:17:37 2018 +0100
4.3 @@ -98,6 +98,23 @@
4.4 p->x, p->y, -1, 1);
4.5 }
4.6
4.7 +/* Unplot a sprite by restoring a region from the background image. */
4.8 +
4.9 +void image_unplot_sprite_from_image(sprite_t *s, sprite_t *bg,
4.10 + int xorigin, int yorigin)
4.11 +{
4.12 + int frame = s->cfg->frame;
4.13 + position_t *p = image_get_stored_position(s, frame);
4.14 +
4.15 + /* Plot the region of the background using the sprite image dimensions
4.16 + converted to background image dimensions at the sprite's position on the
4.17 + display. */
4.18 +
4.19 + image_update_tiled_image(bg, xorigin, yorigin,
4.20 + s->image->width, (s->image->height / s->yscale) * bg->yscale,
4.21 + p->x, p->y);
4.22 +}
4.23 +
4.24
4.25
4.26 /* Plot a section of an image without storing the background beforehand. */
4.27 @@ -233,3 +250,21 @@
4.28 0, ydisplay);
4.29 }
4.30 }
4.31 +
4.32 +/* Plot a region of a tiled image. */
4.33 +
4.34 +void image_update_tiled_image(sprite_t *s, int xorigin, int yorigin,
4.35 + int width, int height,
4.36 + int xdisplay, int ydisplay)
4.37 +{
4.38 + /* Find the source position for the region. */
4.39 +
4.40 + int xsource = wrap_value(xorigin + xdisplay, s->image->width);
4.41 + int ysource = wrap_value(yorigin + ydisplay * s->yscale, s->image->height);
4.42 +
4.43 + /* Request tiling in the source coordinates. */
4.44 +
4.45 + image_tile_sprite(s, xsource, ysource,
4.46 + width, height,
4.47 + xdisplay, ydisplay);
4.48 +}
5.1 --- a/lib/viewport.c Tue Nov 13 14:35:22 2018 +0100
5.2 +++ b/lib/viewport.c Tue Nov 13 15:17:37 2018 +0100
5.3 @@ -72,3 +72,12 @@
5.4 v->xorigins[frame] = v->xorigin;
5.5 v->yorigins[frame] = v->yorigin;
5.6 }
5.7 +
5.8 +/* Update the display, unplotting a sprite and replotting the background. */
5.9 +
5.10 +void viewport_unplot_sprite_from_image(viewport_t *v, sprite_t *s, sprite_t *bg)
5.11 +{
5.12 + int frame = v->cfg->frame;
5.13 +
5.14 + image_unplot_sprite_from_image(s, bg, v->xorigins[frame], v->yorigins[frame]);
5.15 +}