1.1 --- a/examples/vga/main.c Sat Nov 10 22:11:32 2018 +0100
1.2 +++ b/examples/vga/main.c Sat Nov 10 22:40:06 2018 +0100
1.3 @@ -281,6 +281,7 @@
1.4
1.5 static void setup(void)
1.6 {
1.7 + SpriteOverwriting(scr, &screendata, &display_config, SOURCE_YSTEP);
1.8 int frame;
1.9
1.10 for (frame = 0; frame < display_config.frames; frame++)
1.11 @@ -291,12 +292,10 @@
1.12
1.13 /* Plot the image centred on the screen. */
1.14
1.15 - display_copy(&display_config, screendata.image,
1.16 - screendata.width, screendata.height,
1.17 - SOURCE_YSTEP,
1.18 - (display_config.line_length - screendata.width) / 2,
1.19 - (display_config.line_count - (screendata.height / SOURCE_YSTEP)) / 2,
1.20 - -1, 1);
1.21 + image_plot_sprite(&scr,
1.22 + (display_config.line_length - scr.image->width) / 2,
1.23 + (display_config.line_count - (scr.image->height / scr.yscale)) / 2,
1.24 + -1);
1.25
1.26 /* Write a sequence of characters. */
1.27
2.1 --- a/include/image.h Sat Nov 10 22:11:32 2018 +0100
2.2 +++ b/include/image.h Sat Nov 10 22:40:06 2018 +0100
2.3 @@ -116,6 +116,19 @@
2.4
2.5
2.6
2.7 +/* Initialise a sprite object using an existing image without the capability of
2.8 + storing regions of the screen.
2.9 +
2.10 + SpriteOverwriting(<name>, image_t *image, display_config_t *cfg, int yscale)
2.11 +*/
2.12 +
2.13 +#define SpriteOverwriting(NAME, IMAGE, CFG, YSCALE) \
2.14 + sprite_t NAME = { \
2.15 + .image=IMAGE, \
2.16 + .regions=0, \
2.17 + .yscale=YSCALE, \
2.18 + .cfg=CFG};
2.19 +
2.20 /* Initialise a sprite object using an existing image, creating stored regions
2.21 for the animation of the sprite.
2.22
3.1 --- a/lib/image.c Sat Nov 10 22:11:32 2018 +0100
3.2 +++ b/lib/image.c Sat Nov 10 22:40:06 2018 +0100
3.3 @@ -42,14 +42,20 @@
3.4
3.5 void image_plot_sprite(sprite_t *s, int x, int y, int key)
3.6 {
3.7 - int frame = s->cfg->frame;
3.8 - position_t *p = image_get_stored_position(s->regions, frame);
3.9 + int frame = 0;
3.10 + position_t *p = 0;
3.11
3.12 - /* Copy to the stored region. */
3.13 + if (s->regions)
3.14 + {
3.15 + frame = s->cfg->frame;
3.16 + p = image_get_stored_position(s->regions, frame);
3.17
3.18 - display_copy(s->cfg, image_get_stored_region(s->regions, frame),
3.19 - s->image->width, s->image->height / s->yscale, 1,
3.20 - x, y, -1, 0);
3.21 + /* Copy to the stored region. */
3.22 +
3.23 + display_copy(s->cfg, image_get_stored_region(s->regions, frame),
3.24 + s->image->width, s->image->height / s->yscale, 1,
3.25 + x, y, -1, 0);
3.26 + }
3.27
3.28 /* Plot to the screen. */
3.29
3.30 @@ -57,13 +63,16 @@
3.31 s->image->width, s->image->height, s->yscale,
3.32 x, y, key, 1);
3.33
3.34 - /* Record the stored background details. */
3.35 + if (s->regions)
3.36 + {
3.37 + /* Record the stored background details. */
3.38
3.39 - p->x = x;
3.40 - p->y = y;
3.41 + p->x = x;
3.42 + p->y = y;
3.43
3.44 - if (frame >= s->regions->stored)
3.45 - s->regions->stored = frame + 1;
3.46 + if (frame >= s->regions->stored)
3.47 + s->regions->stored = frame + 1;
3.48 + }
3.49 }
3.50
3.51 /* Copy a region from the store to the screen, restoring the original
3.52 @@ -71,8 +80,14 @@
3.53
3.54 void image_unplot_sprite(sprite_t *s)
3.55 {
3.56 - int frame = s->cfg->frame;
3.57 - position_t *p = image_get_stored_position(s->regions, frame);
3.58 + int frame;
3.59 + position_t *p;
3.60 +
3.61 + if (!s->regions)
3.62 + return;
3.63 +
3.64 + frame = s->cfg->frame;
3.65 + p = image_get_stored_position(s->regions, frame);
3.66
3.67 /* Only unplot the sprite if a region was stored for the frame. */
3.68