GdkPixbuf *framebuf;
-gboolean canvas_expose(GtkWidget *canvas, GdkEventExpose *event, gpointer data)
-{
- if (!framebuf)
- return TRUE;
-
- gdk_draw_pixbuf(canvas->window, NULL, framebuf,
- event->area.x, event->area.y, event->area.x, event->area.y,
- event->area.width, event->area.height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
-
- return TRUE;
-}
-
-void get_colour(unsigned char index, unsigned char out[static 3])
+static void get_colour(unsigned char index, unsigned char out[static 3])
{
struct lbx_colour *colour;
out[2] = colour->blue;
}
-static int init_framedata(void)
+static int render_frame(LBX_IMG *img, GdkPixbuf *buf, unsigned frame)
{
- struct lbx_imginfo info;
unsigned char **imgdata, **imgmask;
+ struct lbx_imginfo info;
unsigned char *data;
unsigned stride;
lbximg_getinfo(image, &info);
- imgdata = lbximg_getframe(image, 0);
+ imgdata = lbximg_getframe(image, frame);
if (!imgdata) {
- printf("failed to decode frame 0\n");
+ printf("failed to decode frame %u\n", frame);
return -1;
}
imgmask = lbximg_getmask(image);
- framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
- info.width, info.height);
- if (!framebuf) {
- printf("failed to allocate pixbuf\n");
- return -1;
- }
-
- data = gdk_pixbuf_get_pixels(framebuf);
- stride = gdk_pixbuf_get_rowstride(framebuf);
+ data = gdk_pixbuf_get_pixels(buf);
+ stride = gdk_pixbuf_get_rowstride(buf);
for (unsigned i = 0; i < info.height; i++) {
unsigned char (*p)[3] = (void *)(data + i*stride);
}
}
- gtk_widget_set_size_request(canvas, info.width, info.height);
+ return 0;
+}
+
+void set_frame(GtkSpinButton *spin, gpointer data)
+{
+ unsigned frame = gtk_spin_button_get_value_as_int(spin);
+
+ render_frame(image, framebuf, frame);
gdk_window_invalidate_rect(canvas->window, NULL, FALSE);
+}
+
+gboolean canvas_expose(GtkWidget *canvas, GdkEventExpose *event, gpointer data)
+{
+ if (!framebuf)
+ return TRUE;
+
+ gdk_draw_pixbuf(canvas->window, NULL, framebuf,
+ event->area.x, event->area.y, event->area.x, event->area.y,
+ event->area.width, event->area.height,
+ GDK_RGB_DITHER_NORMAL, 0, 0);
+
+ return TRUE;
+}
+
+static int init_framedata(void)
+{
+ struct lbx_imginfo info;
+ GtkSpinButton *spin;
+
+ lbximg_getinfo(image, &info);
+ framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
+ info.width, info.height);
+ if (!framebuf) {
+ printf("failed to allocate pixbuf\n");
+ return -1;
+ }
+
+ gtk_widget_set_size_request(canvas, info.width, info.height);
+
+ spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
+ gtk_spin_button_set_range(spin, 0, info.nframes-1);
+ gtk_spin_button_set_value(spin, 0);
+ set_frame(spin, NULL);
return 0;
}
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkComboBoxEntry" id="imagechooser">
+ <object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
- <signal name="changed" handler="set_image_data"/>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="xpad">3</property>
+ <property name="label" translatable="yes">Image:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxEntry" id="imagechooser">
+ <property name="visible">True</property>
+ <signal name="changed" handler="set_image_data"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="padding">3</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="xalign">1</property>
+ <property name="xpad">3</property>
+ <property name="label" translatable="yes">Frame:</property>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="framespin">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="adjustment">adjustment1</property>
+ <signal name="value_changed" handler="set_frame"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
</object>
</child>
</object>
+ <object class="GtkAdjustment" id="adjustment1">
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
</interface>