#include "lbx.h"
#include "image.h"
-#include "render.h"
+#include "lbxgui.h"
#include "bg.xbm"
static GtkWidget *canvas;
+static cairo_surface_t *framebuf;
static cairo_pattern_t *bg_pattern;
static bool bg_stipple;
static struct lbx_image *image;
+static struct lbx_colour palette[256];
-static GdkPixbuf *framebuf;
+/* We support stacking up to three palettes, with each superseding the last. */
+static struct lbx_colour palette_external[256];
+static struct lbx_colour palette_internal[256];
+static struct lbx_colour palette_override[256];
+
+static void refresh_palette(void)
+{
+ memcpy(palette, palette_external, sizeof palette);
+ lbxgui_stack_palette(palette, palette_internal);
+ lbxgui_stack_palette(palette, palette_override);
+
+ if (framebuf)
+ lbxgui_render_restart(framebuf);
+}
void play_toggled(GtkToggleButton *button, gpointer data)
{
{
unsigned frame = gtk_spin_button_get_value_as_int(spin);
- if (image && framebuf)
- render_to_pixbuf(image, framebuf, frame);
+ if (image)
+ lbxgui_render_argb(framebuf, image, frame, palette);
gdk_window_invalidate_rect(canvas->window, NULL, FALSE);
}
{
GtkSpinButton *spin;
+ refresh_palette();
+
spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
set_frame(spin, NULL);
}
{
static double elapsed = 0;
double seconds_per_frame = 1.0/15;
- struct lbx_imginfo info;
GtkSpinButton *spin;
GtkToggleButton *play;
unsigned frame, newframe;
if (!image)
return;
- lbx_img_getinfo(image, &info);
spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
play = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "playbutton"));
{
cairo_t *cr;
- if (!framebuf)
- return FALSE;
-
cr = gdk_cairo_create(canvas->window);
if (bg_stipple) {
cairo_fill(cr);
}
- gdk_cairo_set_source_pixbuf(cr, framebuf, 0, 0);
+ cairo_set_source_surface(cr, framebuf, 0, 0);
gdk_cairo_rectangle(cr, &event->area);
cairo_fill(cr);
return TRUE;
}
-static int alloc_framebuffer(struct lbx_image *image)
+static int alloc_framebuffer(struct lbx_image *img)
{
GtkSpinButton *spin;
- if (framebuf)
- g_object_unref(framebuf);
-
- framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
- image->width, image->height);
- g_return_val_if_fail(framebuf, -1);
+ cairo_surface_destroy(framebuf);
+ framebuf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
+ img->width, img->height);
spin = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "framespin"));
- gtk_spin_button_set_range(spin, 0, image->frames-1);
+ gtk_spin_button_set_range(spin, 0, img->frames-1);
gtk_spin_button_set_value(spin, 0);
- gtk_widget_set_size_request(canvas, image->width, image->height);
+ gtk_widget_set_size_request(canvas, img->width, img->height);
return 0;
}
lbx_img_close(img);
}
- if (alloc_framebuffer(img) == -1) {
- puts("crap");
- lbx_img_close(img);
- }
+ alloc_framebuffer(img);
}
image = img;