aboutsummaryrefslogtreecommitdiff
path: root/src/canvas.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/canvas.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/canvas.c')
-rw-r--r--src/canvas.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/canvas.c b/src/canvas.c
index c185c06..a1044d5 100644
--- a/src/canvas.c
+++ b/src/canvas.c
@@ -8,9 +8,9 @@
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdbool.h>
#ifdef IMV_BACKEND_LIBRSVG
#include <librsvg/rsvg.h>
@@ -204,7 +204,9 @@ static int convert_pixelformat(enum imv_pixelformat fmt)
static void draw_bitmap(struct imv_canvas *canvas,
struct imv_bitmap *bitmap,
int bx, int by, double scale,
- enum upscaling_method upscaling_method, bool cache_invalidated)
+ double rotation, bool mirrored,
+ enum upscaling_method upscaling_method,
+ bool cache_invalidated)
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
@@ -249,6 +251,15 @@ static void draw_bitmap(struct imv_canvas *canvas,
const int top = by;
const int right = left + bitmap->width * scale;
const int bottom = top + bitmap->height * scale;
+ const int center_x = left + bitmap->width * scale / 2;
+ const int center_y = top + bitmap->height * scale / 2;
+
+ glTranslated(center_x, center_y, 0);
+ if (mirrored) {
+ glScaled(-1, 1, 1);
+ }
+ glRotated(-rotation, 0, 0, 1);
+ glTranslated(-center_x, -center_y, 0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -273,11 +284,14 @@ RsvgHandle *imv_image_get_svg(const struct imv_image *image);
void imv_canvas_draw_image(struct imv_canvas *canvas, struct imv_image *image,
int x, int y, double scale,
- enum upscaling_method upscaling_method, bool cache_invalidated)
+ double rotation, bool mirrored,
+ enum upscaling_method upscaling_method,
+ bool cache_invalidated)
{
struct imv_bitmap *bitmap = imv_image_get_bitmap(image);
if (bitmap) {
- draw_bitmap(canvas, bitmap, x, y, scale, upscaling_method, cache_invalidated);
+ draw_bitmap(canvas, bitmap, x, y, scale, rotation, mirrored,
+ upscaling_method, cache_invalidated);
return;
}