diff options
-rw-r--r-- | doc/imv.1.txt | 7 | ||||
-rw-r--r-- | src/imv.c | 25 | ||||
-rw-r--r-- | src/viewport.c | 9 | ||||
-rw-r--r-- | src/viewport.h | 5 |
4 files changed, 22 insertions, 24 deletions
diff --git a/doc/imv.1.txt b/doc/imv.1.txt index 14dd727..1eda54f 100644 --- a/doc/imv.1.txt +++ b/doc/imv.1.txt @@ -99,11 +99,8 @@ Commands can be entered by pressing *:*. imv supports the following commands: 'actual' resets the zoom to 100%, showing the image at its actual size. Aliased to 'z'. -*rotate* <amount>:: - Rotate image clockwise by the given amount in degrees. - -*rotate_to* <angle>:: - Rotate image clockwise to the given angle in degrees. +*rotate* <'to'|'by'> <angle>:: + Rotate image clockwise by/to the given amount in degrees. *flip* <'horizontal'|'vertical'>:: Flip image horizontally/vertically (across vertical/horizontal axis). @@ -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); |