@@ 424,76 424,76 @@ quit(void)
}
void
-domouse(SDL_Event *event, Brush *b)
+domouse(SDL_Event *event)
{
switch(event->type) {
case SDL_MOUSEBUTTONUP:
if(event->button.button == SDL_BUTTON_LEFT)
- b->down = 0;
+ brush.down = 0;
if(event->button.button == SDL_BUTTON_RIGHT)
- b->erase = 0;
+ brush.erase = 0;
break;
case SDL_MOUSEBUTTONDOWN:
if(event->button.button == SDL_BUTTON_LEFT)
- b->down = 1;
+ brush.down = 1;
if(event->button.button == SDL_BUTTON_RIGHT)
- b->erase = 1;
+ brush.erase = 1;
if(event->button.button == SDL_BUTTON_MIDDLE) {
- b->erase = 0;
- if(b->px != 0 && b->py != 0) {
- b->x = (event->motion.x - (PAD * ZOOM)) / ZOOM;
- b->y = (event->motion.y - (PAD * ZOOM)) / ZOOM;
- line(b->px - 1, b->py, b->x, b->y, b->erase ? 0 : b->color);
+ brush.erase = 0;
+ if(brush.px != 0 && brush.py != 0) {
+ brush.x = (event->motion.x - (PAD * ZOOM)) / ZOOM;
+ brush.y = (event->motion.y - (PAD * ZOOM)) / ZOOM;
+ line(brush.px - 1, brush.py, brush.x, brush.y, brush.erase ? 0 : brush.color);
redraw(pixels);
}
}
- b->px = (event->motion.x - (PAD * ZOOM)) / ZOOM;
- b->py = (event->motion.y - (PAD * ZOOM)) / ZOOM;
+ brush.px = (event->motion.x - (PAD * ZOOM)) / ZOOM;
+ brush.py = (event->motion.y - (PAD * ZOOM)) / ZOOM;
if(event->motion.y / ZOOM / 8 == VER + 2)
selectoption(event->motion.x / ZOOM / 8 - 1);
- if(b->down && b->mode == 0) {
- putchr(b->px - 1, b->py, b->erase ? 0 : b->color);
+ if(brush.down && brush.mode == 0) {
+ putchr(brush.px - 1, brush.py, brush.erase ? 0 : brush.color);
redraw(pixels);
}
break;
case SDL_MOUSEMOTION:
- if(b->down) {
- b->x = (event->motion.x - (PAD * ZOOM)) / ZOOM;
- b->y = (event->motion.y - (PAD * ZOOM)) / ZOOM;
- if(!b->mode)
- line(b->px - 1, b->py, b->x - 1, b->y, b->erase ? 0 : b->color);
+ if(brush.down) {
+ brush.x = (event->motion.x - (PAD * ZOOM)) / ZOOM;
+ brush.y = (event->motion.y - (PAD * ZOOM)) / ZOOM;
+ if(!brush.mode)
+ line(brush.px - 1, brush.py, brush.x - 1, brush.y, brush.erase ? 0 : brush.color);
else
- fill(b->x - 1, b->y, b->mode, b->size, b->erase ? 0 : b->color);
+ fill(brush.x - 1, brush.y, brush.mode, brush.size, brush.erase ? 0 : brush.color);
redraw(pixels);
- b->px = b->x;
- b->py = b->y;
+ brush.px = brush.x;
+ brush.py = brush.y;
}
break;
}
}
void
-dokey(SDL_Event *event, Brush *b)
+dokey(SDL_Event *event)
{
switch(event->key.keysym.sym) {
case SDLK_EQUALS:
case SDLK_PLUS: modzoom(1); break;
case SDLK_UNDERSCORE:
case SDLK_MINUS: modzoom(-1); break;
- case SDLK_1: setcolor(b, 1); break;
- case SDLK_2: setcolor(b, 2); break;
- case SDLK_3: setcolor(b, 3); break;
- case SDLK_4: setcolor(b, 0); break;
+ case SDLK_1: setcolor(&brush, 1); break;
+ case SDLK_2: setcolor(&brush, 2); break;
+ case SDLK_3: setcolor(&brush, 3); break;
+ case SDLK_4: setcolor(&brush, 0); break;
case SDLK_e: exportchr(); break;
case SDLK_r: renderbmp(); break;
- case SDLK_a: setmode(b, 0); break;
- case SDLK_s: setmode(b, 1); break;
- case SDLK_d: setmode(b, 2); break;
- case SDLK_f: setmode(b, 3); break;
- case SDLK_g: setmode(b, 4); break;
+ case SDLK_a: setmode(&brush, 0); break;
+ case SDLK_s: setmode(&brush, 1); break;
+ case SDLK_d: setmode(&brush, 2); break;
+ case SDLK_f: setmode(&brush, 3); break;
+ case SDLK_g: setmode(&brush, 4); break;
case SDLK_h: setguides(!GUIDES); break;
- case SDLK_z: modsize(b, -1); break;
- case SDLK_x: modsize(b, 1); break;
+ case SDLK_z: modsize(&brush, -1); break;
+ case SDLK_x: modsize(&brush, 1); break;
case SDLK_n: destroy(); break;
}
}
@@ 551,17 551,17 @@ main(int argc, char **argv)
SDL_Delay(ticknext - tick);
ticknext = tick + (1000 / FPS);
while(SDL_PollEvent(&event) != 0) {
- if(event.type == SDL_QUIT)
- quit();
- else if(event.type == SDL_MOUSEBUTTONUP ||
- event.type == SDL_MOUSEBUTTONDOWN ||
- event.type == SDL_MOUSEMOTION)
- domouse(&event, &brush);
- else if(event.type == SDL_KEYDOWN)
- dokey(&event, &brush);
- else if(event.type == SDL_WINDOWEVENT)
+ switch(event.type) {
+ case SDL_QUIT: quit(); break;
+ case SDL_MOUSEBUTTONUP:
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEMOTION: domouse(&event); break;
+ case SDL_KEYDOWN: dokey(&event); break;
+ case SDL_WINDOWEVENT:
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
redraw(pixels);
+ break;
+ }
}
}
quit();