aboutsummaryrefslogtreecommitdiff
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
parentecc58e5ee237b6fad308e590317ff3fc5d3475fc (diff)
downloadimv-cd67aca62d1c1169bb35e580e3f4d9ddf708235d.tar.gz
Add initial_pan option to set the starting pan position
-rw-r--r--AUTHORS1
-rw-r--r--doc/imv.5.txt5
-rw-r--r--src/imv.c24
-rw-r--r--src/viewport.c26
-rw-r--r--src/viewport.h3
5 files changed, 57 insertions, 2 deletions
diff --git a/AUTHORS b/AUTHORS
index b88acf6..385dba0 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -10,6 +10,7 @@ People who have contributed to imv:
* Hannes Körber
* Aleksandra Kosiacka
* Michal Koutenský
+ * Sebastian Parborg
---
When submitting a patch or pull request to imv, feel free to add yourself to
diff --git a/doc/imv.5.txt b/doc/imv.5.txt
index 7e0689f..5b26c54 100644
--- a/doc/imv.5.txt
+++ b/doc/imv.5.txt
@@ -37,6 +37,11 @@ The *[options]* section accepts the following settings:
*height* = <height>::
Initial height of the imv window. Defaults to 720.
+*initial_pan* = <pan_factor_x> <pan_factor_y>::
+ Initial pan/focus position factor of the opened images. A value of 50
+ represents the middle point of the image (50%).
+ Defaults to '50 50'
+
*list_files_at_exit* = <true|false>::
Print open files to stdout at exit, each on a separate line.
Defaults to 'false'.
diff --git a/src/imv.c b/src/imv.c
index d8f8304..b12ed98 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -114,6 +114,10 @@ struct imv {
/* scale up / down images to match window, or actual size */
enum scaling_mode scaling_mode;
+ /* initial pan factor when opening new images */
+ bool custom_start_pan;
+ double initial_pan_x, initial_pan_y;
+
struct {
/* show a solid background colour, or chequerboard pattern */
enum background_type type;
@@ -670,6 +674,18 @@ static bool parse_upscaling_method(struct imv *imv, const char *method)
return false;
}
+static bool parse_initial_pan(struct imv *imv, const char *pan_params)
+{
+ char *next_val;
+ long int val_x = strtol(pan_params, &next_val, 10);
+ long int val_y = strtol(next_val, NULL, 10);
+
+ imv->custom_start_pan = true;
+ imv->initial_pan_x = (double)val_x / (double)100;
+ imv->initial_pan_y = (double)val_y / (double)100;
+ return true;
+}
+
static void *load_paths_from_stdin(void *data)
{
struct imv *imv = data;
@@ -1064,6 +1080,10 @@ static bool setup_window(struct imv *imv)
imv->view = imv_viewport_create(ww, wh, bw, bh);
}
+ if (imv->custom_start_pan) {
+ imv_viewport_set_default_pan_factor(imv->view, imv->initial_pan_x, imv->initial_pan_y);
+ }
+
/* put us in fullscren mode to begin with if requested */
imv_window_set_fullscreen(imv->window, imv->start_fullscreen);
@@ -1319,6 +1339,10 @@ static int handle_ini_value(void *user, const char *section, const char *name,
return parse_scaling_mode(imv, value);
}
+ if (!strcmp(name, "initial_pan")) {
+ return parse_initial_pan(imv, value);
+ }
+
if (!strcmp(name, "background")) {
if (!parse_bg(imv, value)) {
return false;
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;
diff --git a/src/viewport.h b/src/viewport.h
index 32fc728..0b9519f 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -34,6 +34,9 @@ void imv_viewport_get_offset(struct imv_viewport *view, int *x, int *y);
/* Fetch viewport scale */
void imv_viewport_get_scale(struct imv_viewport *view, double *scale);
+/* Set the default pan_factor factor for the x and y position */
+void imv_viewport_set_default_pan_factor(struct imv_viewport *view, double pan_factor_x, double pan_factor_y);
+
/* Pan the view by the given amounts without letting the image get too far
* off-screen */
void imv_viewport_move(struct imv_viewport *view, int x, int y,