From 522bee68b2f6955df0895a5c47a772970f84c045 Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 22 Jan 2021 10:24:52 -0800 Subject: [PATCH] Added colorpicker --- README.md | 1 + nasu.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6e2918b..d6c65b9 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,4 @@ To resume working on a tileset: - `mouse1` Paint - `mouse2` Line - `mouse1+mouse3` Erase +- `ctrl+mouse1` Color Picker diff --git a/nasu.c b/nasu.c index 920ecc8..785b36a 100644 --- a/nasu.c +++ b/nasu.c @@ -441,6 +441,7 @@ quit(void) void domouse(SDL_Event *event) { + int ctrl = SDL_GetModState() & KMOD_LCTRL || SDL_GetModState() & KMOD_RCTRL; switch(event->type) { case SDL_MOUSEBUTTONUP: if(event->button.button == SDL_BUTTON_LEFT) @@ -461,10 +462,11 @@ domouse(SDL_Event *event) line(brush.px, brush.py, screenpos(event->motion.x, brush.vx), screenpos(event->motion.y, brush.vy), brush.erase ? 0 : brush.color); brush.px = screenpos(event->motion.x, brush.vx); brush.py = screenpos(event->motion.y, brush.vy); - if(!BIGPIXEL) { + if(!BIGPIXEL) lookat((brush.px / 8) * 8, (brush.py / 8) * 8); - } - if(brush.down) { + if(ctrl) /* color picker */ + savemode(&brush.color, getchr(brush.px, brush.py)); + else if(brush.down) { if(brush.mode == 0) putchr(brush.px, brush.py, brush.erase ? 0 : brush.color); else @@ -476,7 +478,9 @@ domouse(SDL_Event *event) if(brush.down) { brush.x = screenpos(event->motion.x, brush.vx); brush.y = screenpos(event->motion.y, brush.vy); - if(!brush.mode) + if(ctrl) /* color picker */ + savemode(&brush.color, getchr(brush.px, brush.py)); + else if(!brush.mode) line(brush.px, brush.py, brush.x, brush.y, brush.erase ? 0 : brush.color); else fill(brush.x, brush.y, brush.mode, brush.size, brush.erase ? 0 : brush.color); @@ -515,7 +519,6 @@ dokey(SDL_Event *event) case SDLK_b: savemode(&BIGPIXEL, !BIGPIXEL); break; case SDLK_z: savemode(&brush.size, brush.size + (brush.size > 1 ? -1 : 0)); break; case SDLK_x: savemode(&brush.size, brush.size + (brush.size < 30 ? 1 : 0)); break; - case SDLK_UP: lookat(brush.vx, brush.vy - 1); break; case SDLK_DOWN: lookat(brush.vx, brush.vy + 1); break; case SDLK_LEFT: lookat(brush.vx - 1, brush.vy); break;