ref: 05178ae202fb620c3397fe8db5578186edec1d59
parent: 9149ed8d0e8923dfedd57ec9f4d17dc12745dc56
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Jan 4 15:57:20 EST 2020
extract icons, put them into a separate atlas as a compressed plan 9 image
--- /dev/null
+++ b/demo/atlas_p9.h
@@ -1,0 +1,43 @@
+static u8int atlas_texture[] = {
+ 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0a, 0x20, 0x20, 0x20, 0x72, 0x38,
+ 0x67, 0x38, 0x62, 0x38, 0x61, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x34, 0x36, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x31, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x31, 0x38, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x33, 0x38, 0x36, 0x20, 0x80,
+ 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x78, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0x8f, 0x00,
+ 0x00, 0x74, 0x13, 0x04, 0x0f, 0x04, 0x17, 0x7c, 0x51, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x14,
+ 0x8f, 0x24, 0xa7, 0x34, 0x13, 0x24, 0x0f, 0x7c, 0x51, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
+ 0xbb, 0x2c, 0x1b, 0x7c, 0x00, 0x7c, 0x00, 0x34, 0x00, 0x80, 0x14, 0x00, 0x00, 0x80, 0x5c, 0x00,
+ 0x00, 0x54, 0x1f, 0x04, 0x1b, 0x04, 0x23, 0x7c, 0xbb, 0x5c, 0x13, 0x7c, 0x00, 0x3c, 0x00, 0x80,
+ 0x20, 0x00, 0x00, 0x80, 0xc0, 0x00, 0x00, 0x04, 0x07, 0x44, 0x1f, 0x80, 0x5e, 0x00, 0x00, 0x04,
+ 0x67, 0x80, 0x70, 0x00, 0x00, 0x34, 0x1b, 0x04, 0x13, 0x04, 0x1b, 0x04, 0x23, 0x7c, 0xb3, 0x2c,
+ 0x1b, 0x24, 0x0f, 0x7c, 0x00, 0x2c, 0x00, 0x80, 0x21, 0x00, 0x00, 0x80, 0xe0, 0x00, 0x00, 0x80,
+ 0xea, 0x00, 0x00, 0x80, 0x2c, 0x00, 0x00, 0x54, 0x27, 0x14, 0x9f, 0x24, 0xbb, 0x44, 0x13, 0x7c,
+ 0xb3, 0x4c, 0x00, 0x7c, 0x00, 0x4c, 0xb3, 0x80, 0x2d, 0x00, 0x00, 0x74, 0x2f, 0x24, 0xa7, 0x64,
+ 0xb3, 0x04, 0x00, 0x7c, 0xb3, 0x2c, 0x00, 0x7c, 0x00, 0x1c, 0xb3, 0x80, 0xe1, 0x00, 0x00, 0x80,
+ 0xeb, 0x00, 0x00, 0x7c, 0xb3, 0x3c, 0xbb, 0x64, 0xb3, 0x7c, 0x00, 0x3c, 0x00, 0x24, 0x00, 0x80,
+ 0x0e, 0x00, 0x00, 0x7c, 0xb3, 0x7c, 0xb3, 0x7c, 0xb7, 0x7c, 0x00, 0x74, 0x00, 0x14, 0x00, 0x80,
+ 0x3d, 0x00, 0x00, 0x80, 0xed, 0x00, 0x00, 0x80, 0x45, 0x00, 0x00, 0x24, 0x17, 0x80, 0x22, 0x00,
+ 0x00, 0x7c, 0xb3, 0x7e, 0x27, 0x76, 0x27, 0x7c, 0x00, 0x2c, 0x00, 0x14, 0x00, 0x80, 0x13, 0x00,
+ 0x00, 0x80, 0xd0, 0x00, 0x00, 0x80, 0xf6, 0x00, 0x00, 0x14, 0xbb, 0x24, 0xb3, 0x80, 0x2e, 0x00,
+ 0x00, 0x7c, 0x45, 0x7f, 0x97, 0x7c, 0xbb, 0x7c, 0x00, 0x04, 0x00, 0x54, 0xbb, 0x80, 0x63, 0x00,
+ 0x00, 0x7c, 0xb3, 0x4c, 0x00, 0x80, 0x5e, 0x00, 0x00, 0x54, 0x9f, 0x14, 0xbb, 0x04, 0x23, 0x7c,
+ 0x49, 0x5c, 0x00, 0x54, 0xbb, 0x04, 0x5b, 0x80, 0xec, 0x00, 0x00, 0x7c, 0xb3, 0x3c, 0x00, 0x80,
+ 0x14, 0x00, 0x00, 0x80, 0x5c, 0x00, 0x00, 0x54, 0x1f, 0x04, 0x1b, 0x04, 0x23, 0x7c, 0x49, 0x5c,
+ 0x00, 0x54, 0xbb, 0x80, 0xbc, 0x00, 0x00, 0x7c, 0xb3, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x44,
+ 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x2c, 0x00, 0x7c, 0x00, 0x7c,
+ 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x2c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
+ 0x00, 0x7c, 0x00, 0x2c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x2c,
+ 0x00,
+};
+
+static struct {
+ int x, y, w, h;
+}atlas[] = {
+ [MU_ICON_CHECK] = {0, 0, 18, 18},
+ [MU_ICON_CLOSE] = {18, 0, 16, 16},
+ [MU_ICON_COLLAPSED] = {34, 0, 5, 7},
+ [MU_ICON_EXPANDED] = {39, 0, 7, 5},
+ [ATLAS_DIMENSIONS] = {0, 0, 46, 18},
+};
binary files /dev/null b/demo/icons/mu_icon_check.png differ
binary files /dev/null b/demo/icons/mu_icon_close.png differ
binary files /dev/null b/demo/icons/mu_icon_collapsed.png differ
binary files /dev/null b/demo/icons/mu_icon_expanded.png differ
--- a/demo/renderer_plan9.c
+++ b/demo/renderer_plan9.c
@@ -2,7 +2,7 @@
#include <libc.h>
#include <draw.h>
#include "common.h"
-#include "atlas.inl"
+#include "atlas_p9.h"
enum
{
@@ -69,20 +69,16 @@
void
r_init(void)
{
- u8int *b;
- Rectangle r = {ZP, (Point){ATLAS_WIDTH, ATLAS_HEIGHT}};
- int i;
+ Rectangle r = Rect(0, 0, atlas[ATLAS_DIMENSIONS].w, atlas[ATLAS_DIMENSIONS].h);
+ int res;
- b = malloc(sizeof(atlas_texture)*4);
- for (i = 0; i < sizeof(atlas_texture); i++) {
- b[i*4+0] = atlas_texture[i];
- b[i*4+1] = atlas_texture[i];
- b[i*4+2] = atlas_texture[i];
- b[i*4+3] = atlas_texture[i];
- }
- atlasimage = allocimage(display, r, RGBA32, 1, DWhite);
- if (loadimage(atlasimage, r, b, sizeof(atlas_texture)*4) < 0)
- sysfatal("failed to load atlas");
+ atlasimage = allocimage(display, r, RGBA32, 1, DTransparent);
+ if (memcmp(atlas_texture, "compressed\n", 11) == 0)
+ res = cloadimage(atlasimage, r, atlas_texture+11+5*12, sizeof(atlas_texture)-11-5*12);
+ else
+ res = loadimage(atlasimage, r, atlas_texture, sizeof(atlas_texture));
+ if (res < 0)
+ sysfatal("failed to load atlas: %r");
}
void
--- a/src/microui.h
+++ b/src/microui.h
@@ -60,7 +60,16 @@
MU_COLOR_MAX
};
+#ifdef __plan9__
enum {
+ MU_ICON_CHECK,
+ MU_ICON_CLOSE,
+ MU_ICON_COLLAPSED,
+ MU_ICON_EXPANDED,
+ ATLAS_DIMENSIONS,
+};
+#else
+enum {
MU_ICON_CLOSE = 1,
MU_ICON_CHECK,
MU_ICON_COLLAPSED,
@@ -67,6 +76,7 @@
MU_ICON_EXPANDED,
MU_ICON_MAX
};
+#endif
enum {
MU_RES_ACTIVE = (1 << 0),