1 /* 2 * Common viewport-related functions. 3 * 4 * Copyright (C) 2018 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "viewport.h" 21 22 23 24 /* Initialise the origin for a viewport. */ 25 26 void viewport_set_origin(viewport_t *v, int xorigin, int yorigin) 27 { 28 int frame; 29 30 /* Set the origin for every frame. */ 31 32 v->xorigin = xorigin; 33 v->yorigin = yorigin; 34 35 for (frame = 0; frame < v->cfg->frames; frame++) 36 { 37 v->xorigins[frame] = xorigin; 38 v->yorigins[frame] = yorigin; 39 } 40 } 41 42 /* Update the origin by the given changes in origin coordinates. */ 43 44 void viewport_update_origin(viewport_t *v, int dx, int dy) 45 { 46 int xstep, ystep; 47 int frame = v->cfg->frame; 48 49 /* Change the origin coordinates. */ 50 51 v->xorigin += dx; 52 v->yorigin += dy; 53 54 /* Determine the magnitude of the scrolling required from this frame to the 55 current origin. */ 56 57 xstep = v->xorigin - v->xorigins[frame]; 58 ystep = v->yorigin - v->yorigins[frame]; 59 60 /* Scroll the frame, converting to columns and rows. */ 61 62 display_scroll(v->cfg, xstep / v->xscale, ystep / v->yscale); 63 64 /* For horizontal scrolling, plot the exposed column at the left (if 65 scrolling left) or at the right (if scrolling right). */ 66 67 if (v->update) 68 v->update(v->xorigin, v->yorigin, xstep, ystep); 69 70 /* Record the origin for this frame. */ 71 72 v->xorigins[frame] = v->xorigin; 73 v->yorigins[frame] = v->yorigin; 74 }