|
|
|
|
@ -61,6 +61,8 @@ inspt(Point* p, int w, int h)
|
|
|
|
|
return p->x >= 0 && p->y >= 0 && p->x < w && p->y < h; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Draw */ |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
pixel(uint32_t* dst, Point p, int c) |
|
|
|
|
{ |
|
|
|
|
@ -87,7 +89,7 @@ draw(uint32_t* dst, int id, int color)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
redraw(void) |
|
|
|
|
redraw(uint32_t* dst) |
|
|
|
|
{ |
|
|
|
|
int b, i, j, id = 0, ch1, ch2, color; |
|
|
|
|
for(b = 0; b < 4096; b += 16) |
|
|
|
|
@ -96,15 +98,17 @@ redraw(void)
|
|
|
|
|
ch1 = buffer[b + i]; |
|
|
|
|
ch2 = buffer[b + i + 8]; |
|
|
|
|
color = ((ch1 >> j) & 0x1) + (((ch2 >> j) & 0x1) << 1); |
|
|
|
|
draw(pixels, id, color); |
|
|
|
|
draw(dst, id, color); |
|
|
|
|
id++; |
|
|
|
|
} |
|
|
|
|
SDL_UpdateTexture(gTexture, NULL, pixels, WIDTH * sizeof(uint32_t)); |
|
|
|
|
SDL_UpdateTexture(gTexture, NULL, dst, WIDTH * sizeof(uint32_t)); |
|
|
|
|
SDL_RenderClear(gRenderer); |
|
|
|
|
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); |
|
|
|
|
SDL_RenderPresent(gRenderer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Chr */ |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
write(int tx, int ty, int px, int py, int color) |
|
|
|
|
{ |
|
|
|
|
@ -128,35 +132,35 @@ write(int tx, int ty, int px, int py, int color)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
edit(Point* p, int color) |
|
|
|
|
edit(int x, int y, int color) |
|
|
|
|
{ |
|
|
|
|
Point p1; |
|
|
|
|
setpt(&p1, p->x - PAD, p->y - PAD); |
|
|
|
|
if(!inspt(&p1, 8 * HOR * ZOOM, 8 * VER * ZOOM)) |
|
|
|
|
if(x < 0 || y < 0 || x > 8 * HOR * ZOOM || y > 8 * VER * ZOOM) |
|
|
|
|
return; |
|
|
|
|
write( |
|
|
|
|
p1.x / (8 * ZOOM), |
|
|
|
|
p1.y / (8 * ZOOM), |
|
|
|
|
(p1.x / ZOOM) % 8, |
|
|
|
|
(p1.y / ZOOM) % 8, |
|
|
|
|
x / (8 * ZOOM), |
|
|
|
|
y / (8 * ZOOM), |
|
|
|
|
(x / ZOOM) % 8, |
|
|
|
|
(y / ZOOM) % 8, |
|
|
|
|
color); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Brush */ |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|
patt(int mode, int size, Point p) |
|
|
|
|
patt(int x, int y, int mode, int size) |
|
|
|
|
{ |
|
|
|
|
if(mode == 1) |
|
|
|
|
return ((p.x + p.y) % 4) == 0 && ((p.y - p.x) % 4) == 0; |
|
|
|
|
return ((x + y) % 4) == 0 && ((y - x) % 4) == 0; |
|
|
|
|
if(mode == 2) |
|
|
|
|
return ((p.x + p.y) % 2) == 0 && ((p.y - p.x) % 2) == 0; |
|
|
|
|
return ((x + y) % 2) == 0 && ((y - x) % 2) == 0; |
|
|
|
|
if(mode == 3) |
|
|
|
|
return 1; |
|
|
|
|
if(mode == 4) |
|
|
|
|
return p.y % size == 0; |
|
|
|
|
return y % size == 0; |
|
|
|
|
if(mode == 5) |
|
|
|
|
return p.x % size == 0; |
|
|
|
|
return x % size == 0; |
|
|
|
|
if(mode == 6) |
|
|
|
|
return (p.x + p.y) % size == 0 || (p.x - p.y) % size == 0; |
|
|
|
|
return (x + y) % size == 0 || (x - y) % size == 0; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -168,11 +172,11 @@ fill(Brush* b, int mode, int size, Point p0, int color)
|
|
|
|
|
for(x = -size / 2; x < size; ++x) |
|
|
|
|
for(y = -size / 2; y < size; ++y) { |
|
|
|
|
setpt(&p, p0.x + x, p0.y + y); |
|
|
|
|
if(patt(mode, size, p)) |
|
|
|
|
edit(&p, color); |
|
|
|
|
if(patt(p.x, p.y, mode, size)) |
|
|
|
|
edit(p.x - PAD, p.y - PAD, color); |
|
|
|
|
} |
|
|
|
|
b->edit = 1; |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -182,7 +186,7 @@ line(Point* p0, Point* p1, int color)
|
|
|
|
|
double dy = -abs(p1->y - p0->y), sy = p0->y < p1->y ? 1 : -1; |
|
|
|
|
double err = dx + dy, e2; |
|
|
|
|
for(;;) { |
|
|
|
|
edit(p0, color); |
|
|
|
|
edit(p0->x - PAD, p0->y - PAD, color); |
|
|
|
|
if(p0->x == p1->x && p0->y == p1->y) |
|
|
|
|
break; |
|
|
|
|
e2 = 2 * err; |
|
|
|
|
@ -195,7 +199,7 @@ line(Point* p0, Point* p1, int color)
|
|
|
|
|
p0->y += sy; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -212,7 +216,7 @@ erase(Brush* b)
|
|
|
|
|
buffer[(id * 16) + i + 8] = 0x00; |
|
|
|
|
} |
|
|
|
|
b->edit = 1; |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -236,7 +240,7 @@ create(void)
|
|
|
|
|
int i; |
|
|
|
|
for(i = 0; i < 4096; ++i) |
|
|
|
|
buffer[i] = 0x00; |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -259,7 +263,7 @@ load(char* path)
|
|
|
|
|
if(!fread(buffer, sizeof(buffer), 1, f)) |
|
|
|
|
error("Load", "Invalid file size"); |
|
|
|
|
fclose(f); |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -334,7 +338,7 @@ dokey(SDL_Event* event, Brush* b)
|
|
|
|
|
break; |
|
|
|
|
case SDLK_h: |
|
|
|
|
GUIDES = !GUIDES; |
|
|
|
|
redraw(); |
|
|
|
|
redraw(pixels); |
|
|
|
|
break; |
|
|
|
|
case SDLK_1: |
|
|
|
|
b->mode = 0; |
|
|
|
|
|