aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-09-17 20:40:11 +0200
committerPřemysl Eric Janouch <p@janouch.name>2021-09-17 20:40:11 +0200
commitaae6fd4d8baead50ef95793ba0b9b3433846a609 (patch)
treecde19c48dcc373d9edc09e01a225b5f5749e8463
parentbe6f3dfe991ed6f8d4868a215415dd9ecb6a0c5c (diff)
downloadfiv-aae6fd4d8baead50ef95793ba0b9b3433846a609.tar.gz
fiv-aae6fd4d8baead50ef95793ba0b9b3433846a609.tar.xz
fiv-aae6fd4d8baead50ef95793ba0b9b3433846a609.zip
Add internal support for image scaling
-rw-r--r--fastiv-view.c42
-rw-r--r--meson.build1
2 files changed, 31 insertions, 12 deletions
diff --git a/fastiv-view.c b/fastiv-view.c
index d06dc57..7a29321 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -40,12 +40,30 @@
struct _FastivView {
GtkWidget parent_instance;
cairo_surface_t *surface;
- // TODO(p): Eventually, we'll want to have the zoom level (scale) here,
- // and some zoom-to-fit indication.
+ // TODO(p): Zoom-to-fit indication.
+ double scale;
};
G_DEFINE_TYPE(FastivView, fastiv_view, GTK_TYPE_WIDGET)
+static int
+get_display_width(FastivView *self)
+{
+ if (!self->surface)
+ return 0;
+
+ return ceil(cairo_image_surface_get_width(self->surface) * self->scale);
+}
+
+static int
+get_display_height(FastivView *self)
+{
+ if (!self->surface)
+ return 0;
+
+ return ceil(cairo_image_surface_get_height(self->surface) * self->scale);
+}
+
static void
fastiv_view_finalize(GObject *gobject)
{
@@ -62,10 +80,8 @@ fastiv_view_get_preferred_height(GtkWidget *widget,
*minimum = 0;
*natural = 0;
- // TODO(p): Times the zoom.
FastivView *self = FASTIV_VIEW(widget);
- if (self->surface)
- *natural = cairo_image_surface_get_height(self->surface);
+ *natural = get_display_height(self);
}
static void
@@ -75,10 +91,8 @@ fastiv_view_get_preferred_width(GtkWidget *widget,
*minimum = 0;
*natural = 0;
- // TODO(p): Times the zoom.
FastivView *self = FASTIV_VIEW(widget);
- if (self->surface)
- *natural = cairo_image_surface_get_width(self->surface);
+ *natural = get_display_width(self);
}
static gboolean
@@ -95,8 +109,8 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
- int w = cairo_image_surface_get_width(self->surface);
- int h = cairo_image_surface_get_height(self->surface);
+ int w = get_display_width(self);
+ int h = get_display_height(self);
double x = 0;
double y = 0;
@@ -105,8 +119,10 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
if (h < allocation.height)
y = (allocation.height - h) / 2;
- // TODO(p): Times the zoom.
- cairo_set_source_surface(cr, self->surface, x, y);
+ cairo_scale(cr, self->scale, self->scale);
+ cairo_set_source_surface(cr, self->surface,
+ x / self->scale, y / self->scale);
+
cairo_paint(cr);
return TRUE;
}
@@ -126,6 +142,8 @@ fastiv_view_class_init(FastivViewClass *klass)
static void
fastiv_view_init(FastivView *self)
{
+ self->scale = 1.0;
+
gtk_widget_set_has_window(GTK_WIDGET(self), FALSE);
}
diff --git a/meson.build b/meson.build
index 2a13822..8c97696 100644
--- a/meson.build
+++ b/meson.build
@@ -6,6 +6,7 @@ dependencies = [
dependency('gtk+-3.0'),
dependency('libturbojpeg'),
libraw,
+ meson.get_compiler('c').find_library('m', required : false),
]
conf = configuration_data()