aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Älgmyr <anton@algmyr.se>2020-03-11 01:01:40 +0100
committerHarry Jeffery <harry@exec64.co.uk>2020-06-12 01:00:10 +0100
commita71709b889743bddc4f48a8f13a34a5075ca8ff7 (patch)
tree0ce957376ebcffeb184eb22edc5ef52383d1d02d /src
parentf968eb420c8d30d45adc1f668c15c29f5b9ee87d (diff)
downloadimv-a71709b889743bddc4f48a8f13a34a5075ca8ff7.tar.gz
Unify rotation commands, reset transformation properly
Diffstat (limited to 'src')
-rw-r--r--src/imv.c25
-rw-r--r--src/viewport.c9
-rw-r--r--src/viewport.h5
3 files changed, 20 insertions, 19 deletions
diff --git a/src/imv.c b/src/imv.c
index 313b253..cad548e 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -180,7 +180,6 @@ static void command_prev(struct list *args, const char *argstr, void *data);
static void command_goto(struct list *args, const char *argstr, void *data);
static void command_zoom(struct list *args, const char *argstr, void *data);
static void command_rotate(struct list *args, const char *argstr, void *data);
-static void command_rotate_to(struct list *args, const char *argstr, void *data);
static void command_flip(struct list *args, const char *argstr, void *data);
static void command_open(struct list *args, const char *argstr, void *data);
static void command_close(struct list *args, const char *argstr, void *data);
@@ -501,7 +500,6 @@ struct imv *imv_create(void)
imv_command_register(imv->commands, "goto", &command_goto);
imv_command_register(imv->commands, "zoom", &command_zoom);
imv_command_register(imv->commands, "rotate", &command_rotate);
- imv_command_register(imv->commands, "rotate_to", &command_rotate_to);
imv_command_register(imv->commands, "flip", &command_flip);
imv_command_register(imv->commands, "open", &command_open);
imv_command_register(imv->commands, "close", &command_close);
@@ -1512,19 +1510,14 @@ static void command_rotate(struct list *args, const char *argstr, void *data)
{
(void)argstr;
struct imv *imv = data;
- if (args->len == 2) {
- double degrees = strtod(args->items[1], NULL);
- imv_viewport_rotate(imv->view, degrees);
- }
-}
-
-static void command_rotate_to(struct list *args, const char *argstr, void *data)
-{
- (void)argstr;
- struct imv *imv = data;
- if (args->len == 2) {
- double degrees = strtod(args->items[1], NULL);
- imv_viewport_rotate_to(imv->view, degrees);
+ if (args->len == 3) {
+ if (!strcmp(args->items[1], "by")) {
+ double degrees = strtod(args->items[2], NULL);
+ imv_viewport_rotate_by(imv->view, degrees);
+ } else if (!strcmp(args->items[1], "to")) {
+ double degrees = strtod(args->items[2], NULL);
+ imv_viewport_rotate_to(imv->view, degrees);
+ }
}
}
@@ -1628,7 +1621,7 @@ static void command_reset(struct list *args, const char *argstr, void *data)
(void)args;
(void)argstr;
struct imv *imv = data;
- imv_viewport_rotate_to(imv->view, 0);
+ imv_viewport_reset_transform(imv->view);
imv->need_rescale = true;
imv->need_redraw = true;
}
diff --git a/src/viewport.c b/src/viewport.c
index 7cfb7db..d43cb72 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -196,7 +196,7 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image,
view->locked = 1;
}
-void imv_viewport_rotate(struct imv_viewport *view, double degrees) {
+void imv_viewport_rotate_by(struct imv_viewport *view, double degrees) {
view->rotation += degrees;
}
@@ -210,7 +210,12 @@ void imv_viewport_flip_h(struct imv_viewport *view) {
void imv_viewport_flip_v(struct imv_viewport *view) {
view->mirrored = !view->mirrored;
- view->rotation = -(180.0 - view->rotation);
+ view->rotation = view->rotation - 180;
+}
+
+void imv_viewport_reset_transform(struct imv_viewport *view) {
+ view->mirrored = false;
+ view->rotation = 0;
}
void imv_viewport_center(struct imv_viewport *view, const struct imv_image *image)
diff --git a/src/viewport.h b/src/viewport.h
index 417bf93..a24113c 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -62,7 +62,7 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_image *image,
enum imv_zoom_source, int mouse_x, int mouse_y, int amount);
/* Rotate the view by the given number of degrees */
-void imv_viewport_rotate(struct imv_viewport *view, double degrees);
+void imv_viewport_rotate_by(struct imv_viewport *view, double degrees);
/* Rotate the view to the given number of degrees */
void imv_viewport_rotate_to(struct imv_viewport *view, double degrees);
@@ -73,6 +73,9 @@ void imv_viewport_flip_h(struct imv_viewport *view);
/* Flip vertically (across horizontal axis) */
void imv_viewport_flip_v(struct imv_viewport *view);
+/* Flip vertically (across horizontal axis) */
+void imv_viewport_reset_transform(struct imv_viewport *view);
+
/* Recenter the view to be in the middle of the image */
void imv_viewport_center(struct imv_viewport *view,
const struct imv_image *image);