@@ 25,14 25,14 @@ typedef struct {
} Document;
typedef struct Brush {
- int x, y, px, py;
+ int x, y, px, py, vx, vy;
int mode, size, color;
int down, erase;
} Brush;
int WIDTH = 8 * HOR + 8 * PAD * 2;
int HEIGHT = 8 * (VER + 2) + 8 * PAD * 2;
-int FPS = 30, GUIDES = 1, ZOOM = 2;
+int FPS = 30, GUIDES = 1, BIGPIXEL = 0, ZOOM = 2;
Document doc;
Brush brush;
@@ 52,6 52,8 @@ Uint8 icons[][8] = {
{0xaa, 0x54, 0xaa, 0x54, 0xaa, 0x54, 0xaa, 0x00},
{0x38, 0x7c, 0xee, 0xd6, 0xee, 0x7c, 0x38, 0x00},
{0x44, 0xba, 0x44, 0x44, 0x44, 0xba, 0x44, 0x00},
+ {0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00},
+ {0xee, 0xaa, 0xee, 0x00, 0xee, 0xaa, 0xee, 0x00},
{0x00, 0x00, 0x00, 0x82, 0x44, 0x38, 0x00, 0x00}, /* eye open */
{0x00, 0x38, 0x44, 0x92, 0x28, 0x10, 0x00, 0x00} /* eye closed */
};
@@ 79,6 81,18 @@ distance(int ax, int ay, int bx, int by)
return (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
}
+int
+screenpos(int pos, int offset)
+{
+ pos -= (PAD * 8 * ZOOM);
+ pos /= ZOOM;
+ if(BIGPIXEL) {
+ pos /= 8;
+ pos += offset;
+ }
+ return pos;
+}
+
Uint8
chex(char c)
{
@@ 238,11 252,23 @@ drawchr(Uint32 *dst, int x, int y, int id)
int ch2 = doc.data[offset + v + 8];
int clr = ((ch1 >> h) & 0x1) + (((ch2 >> h) & 0x1) << 1);
int guides = GUIDES && !clr && (x + y) % 2;
- putpixel(dst, px, py, guides ? 4 : clr);
+ putpixel(dst, px - 1, py, guides ? 4 : clr);
}
}
void
+drawbigchr(Uint32 *dst, int x, int y, int id)
+{
+ int v, h;
+ for(v = 0; v < 8; v++)
+ for(h = 0; h < 8; h++)
+ putpixel(dst,
+ x * 8 + h,
+ y * 8 + v,
+ id == 0 && GUIDES && (x + y) % 2 ? 4 : id);
+}
+
+void
drawicon(Uint32 *dst, int x, int y, Uint8 *icon, int fg, int bg)
{
int v, h;
@@ 265,7 291,8 @@ drawui(Uint32 *dst)
drawicon(dst, 6 * 8, bottom, icons[4], brush.mode == 2 ? 1 : 2, 0);
drawicon(dst, 7 * 8, bottom, icons[5], brush.mode == 3 ? 1 : 2, 0);
drawicon(dst, 8 * 8, bottom, icons[6], brush.mode == 4 ? 1 : 2, 0);
- drawicon(dst, 10 * 8, bottom, icons[GUIDES ? 8 : 7], GUIDES ? 1 : 2, 0);
+ drawicon(dst, 10 * 8, bottom, icons[BIGPIXEL ? 7 : 8], BIGPIXEL ? 1 : 2, 0);
+ drawicon(dst, 11 * 8, bottom, icons[GUIDES ? 10 : 9], GUIDES ? 1 : 2, 0);
}
void
@@ 276,7 303,10 @@ redraw(Uint32 *dst)
drawui(dst);
for(y = 0; y < VER; ++y)
for(x = 0; x < HOR; ++x)
- drawchr(dst, x, y, x + y * HOR);
+ if(BIGPIXEL)
+ drawbigchr(dst, x, y, getchr(x + brush.vx, y + brush.vy));
+ else
+ drawchr(dst, x, y, x + y * HOR);
SDL_UpdateTexture(gTexture, NULL, dst, WIDTH * sizeof(Uint32));
SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
@@ 318,6 348,13 @@ setmode(Brush *b, int m)
}
void
+setbigmode(int m)
+{
+ BIGPIXEL = m;
+ redraw(pixels);
+}
+
+void
modsize(Brush *b, int mod)
{
int res = b->size + mod;
@@ 416,7 453,8 @@ selectoption(int option)
case 6: setmode(&brush, 2); break;
case 7: setmode(&brush, 3); break;
case 8: setmode(&brush, 4); break;
- case 10: setguides(!GUIDES); break;
+ case 10: setbigmode(!BIGPIXEL); break;
+ case 11: setguides(!GUIDES); break;
}
}
@@ 456,27 494,31 @@ domouse(SDL_Event *event)
if(event->button.button == SDL_BUTTON_MIDDLE) {
brush.erase = 0;
if(brush.px != 0 && brush.py != 0) {
- brush.x = (event->motion.x - (PAD * 8 * ZOOM)) / ZOOM;
- brush.y = (event->motion.y - (PAD * 8 * ZOOM)) / ZOOM;
- line(brush.px - 1, brush.py, brush.x, brush.y, brush.erase ? 0 : brush.color);
+ brush.x = screenpos(event->motion.x, brush.vx);
+ brush.y = screenpos(event->motion.y, brush.vy);
+ line(brush.px, brush.py, brush.x, brush.y, brush.erase ? 0 : brush.color);
redraw(pixels);
}
}
- brush.px = (event->motion.x - (PAD * 8 * ZOOM)) / ZOOM;
- brush.py = (event->motion.y - (PAD * 8 * ZOOM)) / ZOOM;
+ brush.px = screenpos(event->motion.x, brush.vx);
+ brush.py = screenpos(event->motion.y, brush.vy);
if(brush.down && brush.mode == 0) {
- putchr(brush.px - 1, brush.py, brush.erase ? 0 : brush.color);
+ if(!BIGPIXEL) {
+ brush.vx = (brush.px / 8) * 8;
+ brush.vy = (brush.py / 8) * 8;
+ }
+ putchr(brush.px, brush.py, brush.erase ? 0 : brush.color);
redraw(pixels);
}
break;
case SDL_MOUSEMOTION:
if(brush.down) {
- brush.x = (event->motion.x - (PAD * 8 * ZOOM)) / ZOOM;
- brush.y = (event->motion.y - (PAD * 8 * ZOOM)) / ZOOM;
+ brush.x = screenpos(event->motion.x, brush.vx);
+ brush.y = screenpos(event->motion.y, brush.vy);
if(!brush.mode)
- line(brush.px - 1, brush.py, brush.x - 1, brush.y, brush.erase ? 0 : brush.color);
+ line(brush.px, brush.py, brush.x, brush.y, brush.erase ? 0 : brush.color);
else
- fill(brush.x - 1, brush.y, brush.mode, brush.size, brush.erase ? 0 : brush.color);
+ fill(brush.x, brush.y, brush.mode, brush.size, brush.erase ? 0 : brush.color);
redraw(pixels);
brush.px = brush.x;
brush.py = brush.y;
@@ 521,6 563,10 @@ dokey(SDL_Event *event)
if(ctrl)
setguides(!GUIDES);
break;
+ case SDLK_b:
+ if(ctrl)
+ setbigmode(!BIGPIXEL);
+ break;
case SDLK_z: modsize(&brush, -1); break;
case SDLK_x: modsize(&brush, 1); break;
case SDLK_n: