aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-15 03:52:54 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-15 03:53:13 +0100
commitbff2b92c9e9762dbd281b828fa0562e9992a9461 (patch)
tree1fa75102b771cc83d781c794aab75692a1512d4d
parent7297c40f93763597af43e25e04650159e7a13597 (diff)
downloadfiv-bff2b92c9e9762dbd281b828fa0562e9992a9461.tar.gz
fiv-bff2b92c9e9762dbd281b828fa0562e9992a9461.tar.xz
fiv-bff2b92c9e9762dbd281b828fa0562e9992a9461.zip
Clean up
-rw-r--r--fastiv-view.c76
1 files changed, 41 insertions, 35 deletions
diff --git a/fastiv-view.c b/fastiv-view.c
index 3aefefd..b2bc875 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -165,6 +165,46 @@ get_display_dimensions(FastivView *self, int *width, int *height)
*height = ceil(h * self->scale);
}
+static cairo_matrix_t
+get_orientation_matrix(FastivIoOrientation o, double width, double height)
+{
+ cairo_matrix_t matrix = {};
+ cairo_matrix_init_identity(&matrix);
+ switch (o) {
+ case FastivIoOrientation90:
+ cairo_matrix_rotate(&matrix, -M_PI_2);
+ cairo_matrix_translate(&matrix, -width, 0);
+ break;
+ case FastivIoOrientation180:
+ cairo_matrix_scale(&matrix, -1, -1);
+ cairo_matrix_translate(&matrix, -width, -height);
+ break;
+ case FastivIoOrientation270:
+ cairo_matrix_rotate(&matrix, +M_PI_2);
+ cairo_matrix_translate(&matrix, 0, -height);
+ break;
+ case FastivIoOrientationMirror0:
+ cairo_matrix_scale(&matrix, -1, +1);
+ cairo_matrix_translate(&matrix, -width, 0);
+ break;
+ case FastivIoOrientationMirror90:
+ cairo_matrix_rotate(&matrix, +M_PI_2);
+ cairo_matrix_scale(&matrix, -1, +1);
+ cairo_matrix_translate(&matrix, -width, -height);
+ break;
+ case FastivIoOrientationMirror180:
+ cairo_matrix_scale(&matrix, +1, -1);
+ cairo_matrix_translate(&matrix, 0, -height);
+ break;
+ case FastivIoOrientationMirror270:
+ cairo_matrix_rotate(&matrix, -M_PI_2);
+ cairo_matrix_scale(&matrix, -1, +1);
+ default:
+ break;
+ }
+ return matrix;
+}
+
static void
fastiv_view_get_preferred_height(
GtkWidget *widget, gint *minimum, gint *natural)
@@ -320,41 +360,7 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
cairo_scale(cr, self->scale, self->scale);
cairo_set_source_surface(cr, self->frame, 0, 0);
- cairo_matrix_t matrix = {};
- cairo_matrix_init_identity(&matrix);
- switch (self->orientation) {
- case FastivIoOrientation90:
- cairo_matrix_rotate(&matrix, -M_PI_2);
- cairo_matrix_translate(&matrix, -sw, 0);
- break;
- case FastivIoOrientation180:
- cairo_matrix_scale(&matrix, -1, -1);
- cairo_matrix_translate(&matrix, -sw, -sh);
- break;
- case FastivIoOrientation270:
- cairo_matrix_rotate(&matrix, +M_PI_2);
- cairo_matrix_translate(&matrix, 0, -sh);
- break;
- case FastivIoOrientationMirror0:
- cairo_matrix_scale(&matrix, -1, +1);
- cairo_matrix_translate(&matrix, -sw, 0);
- break;
- case FastivIoOrientationMirror90:
- cairo_matrix_rotate(&matrix, +M_PI_2);
- cairo_matrix_scale(&matrix, -1, +1);
- cairo_matrix_translate(&matrix, -sw, -sh);
- break;
- case FastivIoOrientationMirror180:
- cairo_matrix_scale(&matrix, +1, -1);
- cairo_matrix_translate(&matrix, 0, -sh);
- break;
- case FastivIoOrientationMirror270:
- cairo_matrix_rotate(&matrix, -M_PI_2);
- cairo_matrix_scale(&matrix, -1, +1);
- default:
- break;
- }
-
+ cairo_matrix_t matrix = get_orientation_matrix(self->orientation, sw, sh);
cairo_pattern_t *pattern = cairo_get_source(cr);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);