1.1 --- a/lib/image.c Sun Nov 11 18:15:24 2018 +0100
1.2 +++ b/lib/image.c Sun Nov 11 22:23:40 2018 +0100
1.3 @@ -175,3 +175,61 @@
1.4 source_width = s->image->width;
1.5 }
1.6 }
1.7 +
1.8 +/* Plot a scrolling tiled image upon a viewport update. */
1.9 +
1.10 +void image_update_scrolled_tiled_image(sprite_t *s, int xorigin, int yorigin,
1.11 + int xstep, int ystep)
1.12 +{
1.13 + /* The display regions are either the left or right edge... */
1.14 +
1.15 + int xedge = xstep < 0 ? 0 : s->cfg->line_length - xstep;
1.16 + int xdisplay = xedge;
1.17 +
1.18 + /* and either the top or bottom edge... */
1.19 +
1.20 + int yedge = ystep < 0 ? 0 : s->cfg->line_count * s->yscale - ystep;
1.21 + int ydisplay = yedge / s->yscale;
1.22 +
1.23 + /* Determine the origin position within the image. */
1.24 +
1.25 + int xpos = wrap_value(xorigin, s->image->width);
1.26 + int ypos = wrap_value(yorigin, s->image->height);
1.27 + int xsource, ysource;
1.28 +
1.29 + /* Horizontal scrolling requires columns spanning the height of the screen
1.30 + at the appropriate edge (left or right). */
1.31 +
1.32 + /* The column width is the absolute increment. */
1.33 +
1.34 + if (xstep)
1.35 + {
1.36 + /* Find the source position for the appropriate edge. */
1.37 +
1.38 + xsource = wrap_value(xpos + xedge, s->image->width);
1.39 + ysource = ypos;
1.40 +
1.41 + /* Request tiling in the source coordinates. */
1.42 +
1.43 + image_tile_sprite(s, xsource, ysource,
1.44 + abs(xstep), s->cfg->line_count * s->yscale,
1.45 + xdisplay, 0);
1.46 + }
1.47 +
1.48 + /* Vertical scrolling requires columns across the width of the screen at the
1.49 + appropriate edge (top or bottom). */
1.50 +
1.51 + if (ystep)
1.52 + {
1.53 + /* Find the source position for the appropriate edge. */
1.54 +
1.55 + xsource = xpos;
1.56 + ysource = wrap_value(ypos + yedge, s->image->height);
1.57 +
1.58 + /* Request tiling in the source coordinates. */
1.59 +
1.60 + image_tile_sprite(s, xsource, ysource,
1.61 + s->cfg->line_length, abs(ystep),
1.62 + 0, ydisplay);
1.63 + }
1.64 +}