paul@116 | 1 | /* |
paul@116 | 2 | * Common viewport-related functions. |
paul@116 | 3 | * |
paul@116 | 4 | * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> |
paul@116 | 5 | * |
paul@116 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@116 | 7 | * it under the terms of the GNU General Public License as published by |
paul@116 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@116 | 9 | * (at your option) any later version. |
paul@116 | 10 | * |
paul@116 | 11 | * This program is distributed in the hope that it will be useful, |
paul@116 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@116 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@116 | 14 | * GNU General Public License for more details. |
paul@116 | 15 | * |
paul@116 | 16 | * You should have received a copy of the GNU General Public License |
paul@116 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@116 | 18 | */ |
paul@116 | 19 | |
paul@116 | 20 | #ifndef __VIEWPORT_H__ |
paul@116 | 21 | #define __VIEWPORT_H__ |
paul@116 | 22 | |
paul@116 | 23 | #include "display.h" |
paul@137 | 24 | #include "image.h" |
paul@116 | 25 | |
paul@116 | 26 | |
paul@116 | 27 | |
paul@116 | 28 | /* An abstraction providing a scrolling viewport. */ |
paul@116 | 29 | |
paul@116 | 30 | typedef struct |
paul@116 | 31 | { |
paul@116 | 32 | /* Display configuration. */ |
paul@116 | 33 | |
paul@116 | 34 | display_config_t *cfg; |
paul@116 | 35 | |
paul@116 | 36 | /* Scrolling positions for each frame. */ |
paul@116 | 37 | |
paul@116 | 38 | int *xorigins, *yorigins; |
paul@116 | 39 | |
paul@116 | 40 | /* Scrolling position. */ |
paul@116 | 41 | |
paul@116 | 42 | int xorigin, yorigin; |
paul@116 | 43 | |
paul@116 | 44 | /* Scaling factors, translating the origin coordinates to display columns |
paul@116 | 45 | and rows. */ |
paul@116 | 46 | |
paul@116 | 47 | int xscale, yscale; |
paul@116 | 48 | |
paul@116 | 49 | /* Update function after scrolling. */ |
paul@116 | 50 | |
paul@116 | 51 | void (*update)(); |
paul@116 | 52 | |
paul@116 | 53 | } viewport_t; |
paul@116 | 54 | |
paul@116 | 55 | |
paul@116 | 56 | |
paul@122 | 57 | /* Initialise a viewport. |
paul@122 | 58 | |
paul@122 | 59 | Viewport(<name>, display_config_t *cfg, int xscale, int yscale, void (*update)()) |
paul@122 | 60 | */ |
paul@122 | 61 | |
paul@122 | 62 | #define Viewport(NAME, CFG, XSCALE, YSCALE, UPDATE) \ |
paul@122 | 63 | int __##NAME##_xorigins[(CFG)->frames]; \ |
paul@122 | 64 | int __##NAME##_yorigins[(CFG)->frames]; \ |
paul@122 | 65 | viewport_t NAME = { \ |
paul@122 | 66 | .cfg=CFG, \ |
paul@122 | 67 | .xorigins=__##NAME##_xorigins, \ |
paul@122 | 68 | .yorigins=__##NAME##_yorigins, \ |
paul@122 | 69 | .xorigin=0, \ |
paul@122 | 70 | .yorigin=0, \ |
paul@122 | 71 | .xscale=XSCALE, \ |
paul@122 | 72 | .yscale=YSCALE, \ |
paul@122 | 73 | .update=UPDATE}; |
paul@122 | 74 | |
paul@116 | 75 | /* Viewport operations. */ |
paul@116 | 76 | |
paul@122 | 77 | void viewport_set_origin(viewport_t *v, int xorigin, int yorigin); |
paul@116 | 78 | |
paul@116 | 79 | void viewport_update_origin(viewport_t *v, int dx, int dy); |
paul@116 | 80 | |
paul@137 | 81 | /* Update operations. */ |
paul@137 | 82 | |
paul@137 | 83 | void viewport_unplot_sprite_from_image(viewport_t *v, sprite_t *s, sprite_t *bg); |
paul@137 | 84 | |
paul@116 | 85 | #endif /* __VIEWPORT_H__ */ |