From 242547a147c741c338b22a095a398785280e6f8f Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 8 Feb 2010 21:19:36 -0500 Subject: [PATCH] lbxgui: Make transparent pixels more obvious. --- src/gui/bg.xbm | 27 +++++++++++++++++++++++++++ src/gui/lbxgui.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/gui/bg.xbm diff --git a/src/gui/bg.xbm b/src/gui/bg.xbm new file mode 100644 index 0000000..b37f454 --- /dev/null +++ b/src/gui/bg.xbm @@ -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 }; diff --git a/src/gui/lbxgui.c b/src/gui/lbxgui.c index 21dee9a..ebb92ab 100644 --- a/src/gui/lbxgui.c +++ b/src/gui/lbxgui.c @@ -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(); } -- 2.43.0