@@ 26,7 26,7 @@ typedef struct Brush {
int theme[] = {0x000000, 0x72DEC2, 0xFFFFFF, 0x444444, 0x111111};
int WIDTH = 8 * HOR + PAD * 2;
-int HEIGHT = 8 * VER + PAD * 2;
+int HEIGHT = 8 * (VER + 2) + PAD * 2;
int FPS = 30, GUIDES = 1, ZOOM = 2;
unsigned char chrbuf[SZ];
@@ 37,6 37,11 @@ Uint32 *pixels;
Brush brush;
+/* Icons */
+
+unsigned char icon0[] = {0x38, 0x7c, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x00};
+unsigned char icon1[] = {0x38, 0x44, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00};
+
/* helpers */
int
@@ 223,6 228,13 @@ clear(Uint32 *dst)
}
void
+pixel(Uint32 *dst, int x, int y, int color)
+{
+ if(x >= 0 && x < WIDTH - 8 && y >= 0 && y < HEIGHT - 8)
+ dst[(y + PAD) * WIDTH + (x + PAD)] = color;
+}
+
+void
drawchr(Uint32 *dst, int x, int y, int id)
{
int v, h, offset = id * 16;
@@ 233,17 245,37 @@ drawchr(Uint32 *dst, int x, int y, int id)
int ch1 = chrbuf[offset + v];
int ch2 = chrbuf[offset + v + 8];
int clr = ((ch1 >> h) & 0x1) + (((ch2 >> h) & 0x1) << 1);
- int key = (py + PAD) * WIDTH + (px + PAD);
int guides = GUIDES && !clr && (x + y) % 2;
- dst[key] = theme[guides ? 4 : clr];
+ pixel(dst, px, py, theme[guides ? 4 : clr]);
+ }
+}
+
+void
+drawicon(Uint32 *dst, int x, int y, unsigned char *icon, int color)
+{
+ int v, h;
+ for(v = 0; v < 8; v++)
+ for(h = 0; h < 8; h++) {
+ int c = theme[(icon[v] >> h) & 0x1];
+ pixel(dst, x + h, y + v, c ? color : theme[0]);
}
}
void
+drawui(Uint32 *dst)
+{
+ int bottom = VER * 8 + 8;
+ drawicon(dst, 0, bottom, brush.color == 1 ? icon1 : icon0, theme[1]);
+ drawicon(dst, 8, bottom, brush.color == 2 ? icon1 : icon0, theme[2]);
+ drawicon(dst, 16, bottom, brush.color == 3 ? icon1 : icon0, theme[3]);
+}
+
+void
redraw(Uint32 *dst)
{
int x, y;
clear(dst);
+ drawui(dst);
for(y = 0; y < VER; ++y)
for(x = 0; x < HOR; ++x)
drawchr(dst, x, y, x + y * HOR);
@@ 275,6 307,7 @@ void
setcolor(Brush *b, int c)
{
b->color = c;
+ redraw(pixels);
printf("Set Color %d\n", b->color);
}
@@ 282,6 315,7 @@ void
setmode(Brush *b, int m)
{
b->mode = m;
+ redraw(pixels);
printf("Set Mode %d\n", b->mode);
}
@@ 291,6 325,7 @@ modsize(Brush *b, int mod)
int res = b->size + mod;
if(res > 0 && res < 30)
b->size = res;
+ redraw(pixels);
printf("Set Size %d\n", b->size);
}
@@ 386,6 421,16 @@ loadtheme(FILE *f)
}
void
+selectoption(int option)
+{
+ switch(option) {
+ case 0: setcolor(&brush, 1); break;
+ case 1: setcolor(&brush, 2); break;
+ case 2: setcolor(&brush, 3); break;
+ }
+}
+
+void
quit(void)
{
free(pixels);
@@ 425,6 470,8 @@ domouse(SDL_Event *event, Brush *b)
}
b->px = (event->motion.x - (PAD * ZOOM)) / ZOOM;
b->py = (event->motion.y - (PAD * ZOOM)) / ZOOM;
+ if(b->py >= VER * 8)
+ selectoption(abs(b->px / 8));
if(b->down) {
putchr(b->px - 1, b->py, b->erase ? 0 : b->color);
redraw(pixels);