/* Really limited bitmap glyph editor */ #include #include #include "xshmu.h" /* XXX C&P from tetris.c; factor this out */ static inline void fill(xshmu_pic pic, uint32_t color) { for (int i = 0; i < pic.h; i++) { uint32_t *p = xshmu_pix(pic, 0, i); for (int j = 0; j < pic.w; j++) p[j] = color; } } int main() { xshmu w = xshmu_open("glyphEd", 320, 200, ""); char glyph[8] = {1,2,3,4,5,6,7,8}; int buttons = 0; for (;;) { for (xshmu_event *ev; (ev = xshmu_get_event(w));) { if (xshmu_as_die_event(ev)) { xshmu_close(w); return 0; } xshmu_mouse_event *mev = xshmu_as_mouse_event(ev); if (mev && mev->buttons != buttons) { if (mev->buttons) { /* click */ int x = (mev->x - 100) / 20, y = (mev->y - 5) / 20; if (0 <= x && x < 6 && 0 <= y && y < 8) { glyph[y] ^= 1 << x; /* Dump glyph */ printf("\""); for (int i = 0; i != 8; i++) { if (glyph[i] == '"' || glyph[i] == 28) printf("\\"); printf("%c", glyph[i] ^ (glyph[i] & ' ' ? 0 : '@')); } printf("\"\n"); } } buttons = mev->buttons; } } xshmu_pic fb = xshmu_framebuffer(w); fill(fb, 0x909090); for (int y = 0; y != 8; y++) { for (int x = 0; x != 6; x++) { fill(xshmu_subpic(fb, 100 + 20 * x, 5 + 20 * y, 18, 18), (glyph[y] & (1 << x)) ? -1 : 0); } } xshmu_flush(w); xshmu_wait(w); } }