aboutsummaryrefslogtreecommitdiff
path: root/fastiv-view.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-26 17:14:29 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-26 17:14:51 +0100
commit8c897593254719a5331cf84b884c6590a5f16332 (patch)
tree40148ffb390eae43778fa2c328585996217a3740 /fastiv-view.c
parentdd8461cebf44aeae9e88a9c33f4848678cf580d2 (diff)
downloadfiv-8c897593254719a5331cf84b884c6590a5f16332.tar.gz
fiv-8c897593254719a5331cf84b884c6590a5f16332.tar.xz
fiv-8c897593254719a5331cf84b884c6590a5f16332.zip
Allow manual animation frame iteration
Diffstat (limited to 'fastiv-view.c')
-rw-r--r--fastiv-view.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/fastiv-view.c b/fastiv-view.c
index f200bd1..f119fba 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -31,7 +31,8 @@
struct _FastivView {
GtkWidget parent_instance;
- cairo_surface_t *surface;
+ cairo_surface_t *surface; ///< The loaded image (sequence)
+ cairo_surface_t *frame; ///< Current frame within, unreferenced
bool scale_to_fit;
double scale;
};
@@ -237,12 +238,12 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
// FIXME: Recording surfaces do not work well with CAIRO_SURFACE_TYPE_XLIB,
// we always get a shitty pixmap, where transparency contains junk.
- if (cairo_surface_get_type(self->surface) == CAIRO_SURFACE_TYPE_RECORDING) {
+ if (cairo_surface_get_type(self->frame) == CAIRO_SURFACE_TYPE_RECORDING) {
cairo_surface_t *image =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
cairo_t *tcr = cairo_create(image);
cairo_scale(tcr, self->scale, self->scale);
- cairo_set_source_surface(tcr, self->surface, 0, 0);
+ cairo_set_source_surface(tcr, self->frame, 0, 0);
cairo_paint(tcr);
cairo_destroy(tcr);
@@ -259,7 +260,7 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
cairo_scale(cr, self->scale, self->scale);
cairo_set_source_surface(
- cr, self->surface, x / self->scale, y / self->scale);
+ cr, self->frame, x / self->scale, y / self->scale);
cairo_pattern_t *pattern = cairo_get_source(cr);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
@@ -339,6 +340,8 @@ fastiv_view_key_press_event(GtkWidget *widget, GdkEventKey *event)
FastivView *self = FASTIV_VIEW(widget);
if (event->state & ~GDK_SHIFT_MASK & gtk_accelerator_get_default_mod_mask())
return FALSE;
+ if (!self->surface)
+ return FALSE;
switch (event->keyval) {
case GDK_KEY_1:
@@ -349,6 +352,13 @@ fastiv_view_key_press_event(GtkWidget *widget, GdkEventKey *event)
return set_scale(self, self->scale / SCALE_STEP);
case GDK_KEY_F:
return set_scale_to_fit(self, !self->scale_to_fit);
+ case GDK_KEY_greater: {
+ if (!(self->frame = cairo_surface_get_user_data(
+ self->frame, &fastiv_io_key_frame_next)))
+ self->frame = self->surface;
+ gtk_widget_queue_draw(widget);
+ return TRUE;
+ }
}
return FALSE;
}
@@ -404,7 +414,7 @@ fastiv_view_open(FastivView *self, const gchar *path, GError **error)
if (self->surface)
cairo_surface_destroy(self->surface);
- self->surface = surface;
+ self->frame = self->surface = surface;
set_scale_to_fit(self, true);
return TRUE;
}