aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-11-24 00:50:45 +0100
committerkdx <kikoodx@paranoici.org>2023-11-24 00:50:45 +0100
commitc570c514bcd0de80070ce9c5d21e46f0b056e105 (patch)
tree68818d1c7e3613768f5b1d85aec593067ef96fc4
parentfc890352edb1e1d14aff51d5a3b76a99c43fabd3 (diff)
downloadaancyk-c570c514bcd0de80070ce9c5d21e46f0b056e105.tar.gz
make editor clicked state an enum
-rw-r--r--inc/editor.h6
-rw-r--r--src/editor.c19
2 files changed, 22 insertions, 3 deletions
diff --git a/inc/editor.h b/inc/editor.h
index 16b7e54..bd889a4 100644
--- a/inc/editor.h
+++ b/inc/editor.h
@@ -1,5 +1,11 @@
#pragma once
#include "root.h"
+enum {
+ EDCLICK_PICK = 1,
+ EDCLICK_DRAW,
+ EDCLICK_ERASE,
+};
+
void editor_redraw(Window *this, Root *root);
void editor_event(Window *this, Root *root, SDL_Event *e);
diff --git a/src/editor.c b/src/editor.c
index 2aed6be..5c9f80a 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -37,7 +37,20 @@ editor_redraw(Window *this, Root *root)
w * root->cfg->tile_width + 2,
h * root->cfg->tile_height + 2
};
- window_set_draw_color(this, 255, 255, 0, 255);
+ switch (this->clicked) {
+ case EDCLICK_PICK:
+ window_set_draw_color(this, 255, 255, 0, 255);
+ break;
+ case EDCLICK_DRAW:
+ window_set_draw_color(this, 255, 255, 255, 255);
+ break;
+ case EDCLICK_ERASE:
+ window_set_draw_color(this, 255, 0, 0, 255);
+ break;
+ default:
+ window_set_draw_color(this, 255, 0, 255, 255);
+ break;
+ }
window_draw_rect(this, &rect);
}
}
@@ -88,11 +101,11 @@ _ev_mouse(Window *this, Root *root)
Input *const input = &this->input;
if (input_button_pressed(input, SDL_BUTTON_LEFT) &&
input_key_down(input, SDL_SCANCODE_LCTRL)) {
- this->clicked = true;
+ this->clicked = EDCLICK_PICK;
this->clicked_x = this->mouse_x;
this->clicked_y = this->mouse_y;
} else if (input_button_released(input, SDL_BUTTON_LEFT) &&
- this->clicked) {
+ this->clicked == EDCLICK_PICK) {
this->clicked = false;
const int x = min(this->clicked_x, this->mouse_x);
const int y = min(this->clicked_y, this->mouse_y);