aboutsummaryrefslogtreecommitdiff
path: root/src/viewport.c
diff options
context:
space:
mode:
authorSebastian Parborg <darkdefende@gmail.com>2019-08-25 17:59:55 +0200
committerHarry Jeffery <harry@exec64.co.uk>2019-08-25 21:28:33 +0100
commitcd67aca62d1c1169bb35e580e3f4d9ddf708235d (patch)
tree2eea85fe2d71ab75bea17adca058d7f8f4eefecd /src/viewport.c
parentecc58e5ee237b6fad308e590317ff3fc5d3475fc (diff)
downloadimv-cd67aca62d1c1169bb35e580e3f4d9ddf708235d.tar.gz
Add initial_pan option to set the starting pan position
Diffstat (limited to 'src/viewport.c')
-rw-r--r--src/viewport.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/viewport.c b/src/viewport.c
index e04648f..ce9fa54 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -9,6 +9,7 @@ struct imv_viewport {
int width, height;
} buffer; /* rendering buffer dimensions */
int x, y;
+ double pan_factor_x, pan_factor_y;
int redraw;
int playing;
int locked;
@@ -30,6 +31,7 @@ struct imv_viewport *imv_viewport_create(int window_width, int window_height,
view->buffer.height = buffer_height;
view->scale = 1;
view->x = view->y = view->redraw = 0;
+ view->pan_factor_x = view->pan_factor_y = 0.5;
view->playing = 1;
view->locked = 0;
return view;
@@ -80,6 +82,12 @@ void imv_viewport_get_scale(struct imv_viewport *view, double *scale)
}
}
+void imv_viewport_set_default_pan_factor(struct imv_viewport *view, double pan_factor_x, double pan_factor_y)
+{
+ view->pan_factor_x = pan_factor_x;
+ view->pan_factor_y = pan_factor_y;
+}
+
void imv_viewport_move(struct imv_viewport *view, int x, int y,
const struct imv_image *image)
{
@@ -172,8 +180,22 @@ void imv_viewport_center(struct imv_viewport *view, const struct imv_image *imag
const int image_width = imv_image_width(image);
const int image_height = imv_image_height(image);
- view->x = (view->buffer.width - image_width * view->scale) / 2;
- view->y = (view->buffer.height - image_height * view->scale) / 2;
+ view->x = view->buffer.width - image_width * view->scale;
+ view->y = view->buffer.height - image_height * view->scale;
+
+ if (view->x > 0) {
+ /* Image is smaller than the window. Center the image */
+ view->x *= 0.5;
+ } else {
+ view->x *= view->pan_factor_x;
+ }
+
+ if (view->y > 0) {
+ /* Image is smaller than the window. Center the image */
+ view->y *= 0.5;
+ } else {
+ view->y *= view->pan_factor_y;
+ }
view->locked = 1;
view->redraw = 1;