]> git.draconx.ca Git - liblbx.git/commitdiff
lbxgui: Make transparent pixels more obvious.
authorNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 02:19:36 +0000 (21:19 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 9 Feb 2010 02:27:46 +0000 (21:27 -0500)
src/gui/bg.xbm [new file with mode: 0644]
src/gui/lbxgui.c

diff --git a/src/gui/bg.xbm b/src/gui/bg.xbm
new file mode 100644 (file)
index 0000000..b37f454
--- /dev/null
@@ -0,0 +1,27 @@
+#define bg_width 48
+#define bg_height 48
+static unsigned char bg_bits[] = {
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,
+   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff };
index 21dee9ab5f06bfc7e8325238781d0fda5c387ac8..ebb92abd52545428c17f76d8c3e15192bc5be67c 100644 (file)
@@ -8,10 +8,14 @@
 #include "lbx.h"
 #include "image.h"
 
+#include "bg.xbm"
+
 static GtkTreeStore *archives;
 static GtkBuilder *builder;
 
 static GtkWidget *canvas;
+static GdkGC     *bg_gc;
+
 static LBX_IMG *image;
 /* LBX images can have up to three palettes, with each superseding the last. */
 static struct lbx_colour palette_external[256];
@@ -75,15 +79,14 @@ static int render_frame(LBX_IMG *img, GdkPixbuf *buf, unsigned frame)
        stride = gdk_pixbuf_get_rowstride(buf);
 
        for (unsigned i = 0; i < info.height; i++) {
-               unsigned char (*p)[3] = (void *)(data + i*stride);
+               unsigned char (*p)[4] = (void *)(data + i*stride);
 
                for (unsigned j = 0; j < info.width; j++) {
                        if (imgmask[i][j]) {
                                get_colour(imgdata[i][j], p[j]);
+                               p[j][3] = -1;
                        } else {
-                               p[j][0] = 0;
-                               p[j][1] = 0;
-                               p[j][2] = 0;
+                               p[j][3] = 0;
                        }
                }
        }
@@ -161,6 +164,10 @@ gboolean canvas_expose(GtkWidget *canvas, GdkEventExpose *event, gpointer data)
        if (!framebuf)
                return TRUE;
 
+       gdk_draw_rectangle(canvas->window, bg_gc, TRUE,
+               event->area.x, event->area.y,
+               event->area.width, event->area.height);
+
        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,
@@ -178,7 +185,7 @@ static int init_framedata(int reset)
                return 0;
 
        lbximg_getinfo(image, &info);
-       framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
+       framebuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
                info.width, info.height);
        if (!framebuf) {
                printf("failed to allocate pixbuf\n");
@@ -427,6 +434,23 @@ static void interface_init(void)
        gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(combo), 0);
 }
 
+GdkBitmap *init_bg(GdkDrawable *drawable, GdkGC *gc)
+{
+       GdkColor fg = { .red = 0x6666, .green = 0x6666, .blue = 0x6666 };
+       GdkColor bg = { .red = 0x9999, .green = 0x9999, .blue = 0x9999 };
+       GdkBitmap *bitmap;
+
+       bitmap = gdk_bitmap_create_from_data(drawable, bg_bits,
+               bg_width, bg_height);
+
+       gdk_gc_set_rgb_fg_color(gc, &fg);
+       gdk_gc_set_rgb_bg_color(gc, &bg);
+       gdk_gc_set_fill(gc, GDK_OPAQUE_STIPPLED);
+       gdk_gc_set_stipple(gc, bitmap);
+       gdk_gc_set_ts_origin(gc, 0, 0);
+       return bitmap;
+}
+
 int main(int argc, char **argv)
 {
        GtkWidget *window;
@@ -456,5 +480,8 @@ int main(int argc, char **argv)
 
        g_timeout_add(10, timeout, NULL);
        gtk_widget_show_all(window);
+
+       bg_gc = gdk_gc_new(canvas->window);
+       init_bg(canvas->window, bg_gc);
        gtk_main();
 }