aboutsummaryrefslogtreecommitdiff
path: root/src/viewport.c
diff options
context:
space:
mode:
authorAnton Älgmyr <anton@algmyr.se>2020-03-11 00:35:28 +0100
committerHarry Jeffery <harry@exec64.co.uk>2020-06-12 01:00:10 +0100
commitf968eb420c8d30d45adc1f668c15c29f5b9ee87d (patch)
tree48e33cd4bc0613dd87d66151cbfaab5d7ff6a093 /src/viewport.c
parenteb60fefc3b7e9b5367bca9d3b5e5d4e50f5b72a7 (diff)
downloadimv-f968eb420c8d30d45adc1f668c15c29f5b9ee87d.tar.gz
Add rotation and flipping commands.
Rotation can be done by any amount (not limited to multiples of 90). Commands allow flipping horizontally and vertically. The flips are done relative to the current rotation.
Diffstat (limited to 'src/viewport.c')
-rw-r--r--src/viewport.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/viewport.c b/src/viewport.c
index c894f26..7cfb7db 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -1,9 +1,12 @@
#include "viewport.h"
+#include <stdbool.h>
#include <stdlib.h>
struct imv_viewport {
double scale;
+ double rotation;
+ bool mirrored;
struct {
int width, height;
} window; /* window dimensions */
@@ -32,6 +35,8 @@ struct imv_viewport *imv_viewport_create(int window_width, int window_height,
view->buffer.width = buffer_width;
view->buffer.height = buffer_height;
view->scale = 1;
+ view->rotation = 0;
+ view->mirrored = false;
view->x = view->y = view->redraw = 0;
view->pan_factor_x = view->pan_factor_y = 0.5;
view->playing = 1;
@@ -84,6 +89,20 @@ void imv_viewport_get_scale(struct imv_viewport *view, double *scale)
}
}
+void imv_viewport_get_rotation(struct imv_viewport *view, double *rotation)
+{
+ if(rotation) {
+ *rotation = view->rotation;
+ }
+}
+
+void imv_viewport_get_mirrored(struct imv_viewport *view, bool *mirrored)
+{
+ if(mirrored) {
+ *mirrored = view->mirrored;
+ }
+}
+
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;
@@ -177,6 +196,23 @@ 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) {
+ view->rotation += degrees;
+}
+
+void imv_viewport_rotate_to(struct imv_viewport *view, double degrees) {
+ view->rotation = degrees;
+}
+
+void imv_viewport_flip_h(struct imv_viewport *view) {
+ view->mirrored = !view->mirrored;
+}
+
+void imv_viewport_flip_v(struct imv_viewport *view) {
+ view->mirrored = !view->mirrored;
+ view->rotation = -(180.0 - view->rotation);
+}
+
void imv_viewport_center(struct imv_viewport *view, const struct imv_image *image)
{
const int image_width = imv_image_width(image);