From 6e8119be3bdd4ac54cdb08667c39f4a1d3047270 Mon Sep 17 00:00:00 2001 From: Krow Savcik Date: Sat, 13 Jul 2024 13:33:57 +0300 Subject: feature: layers's name are editable now --- src/cdraw.c | 123 ++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 32 deletions(-) (limited to 'src/cdraw.c') diff --git a/src/cdraw.c b/src/cdraw.c index fab4fa7..2e0097a 100644 --- a/src/cdraw.c +++ b/src/cdraw.c @@ -25,6 +25,11 @@ typedef struct { #include "config.h" +enum CDRAW_STATES { + CDRAW_STATE_NORMAL, + CDRAW_STATE_LNAME, /* Editing layer name */ +} cdraw_state; + SDL_Window *win; void *ren; void *font; @@ -113,6 +118,8 @@ main_window_init(const char *s) cur_canvas = canvas_import_png(s, ren); } + cdraw_state = CDRAW_STATE_NORMAL; + SDL_StopTextInput(); ui_redraw_panel(UI_PANELTYPE_CANVAS); if (cur_canvas == NULL) return 1; @@ -125,46 +132,98 @@ main_event_handle() { static uint8 q, r; static SDL_Event event; + char *text; q = r = 0; while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - q = 1; - break; - case SDL_WINDOWEVENT: - switch (event.window.event) { - case SDL_WINDOWEVENT_RESIZED: - r = 1; - /* FALLTROUGH */ - case SDL_WINDOWEVENT_MOVED: - break; + switch (cdraw_state) { + case CDRAW_STATE_NORMAL: + switch (event.type) { + case SDL_QUIT: + q = 1; + break; + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + r = 1; + /* FALLTROUGH */ + case SDL_WINDOWEVENT_MOVED: + break; + } + break; + case SDL_MOUSEBUTTONDOWN: + switch (event.button.button) { + case SDL_BUTTON_LEFT: + ui_mousel_down(event.button.x, event.button.y); + break; + case SDL_BUTTON_RIGHT: + if (ui_mouser_down(event.button.x, event.button.y)) { + cdraw_state = CDRAW_STATE_LNAME; + SDL_StartTextInput(); + } + break; + } + break; + case SDL_MOUSEBUTTONUP: + switch (event.button.button) { + case SDL_BUTTON_LEFT: + ui_mousel_up(event.button.x, event.button.y); + is_drawing = 0; + break; + } + break; + case SDL_MOUSEMOTION: + mouseX = event.motion.x; + mouseY = event.motion.y; + ui_mouse_move(mouseX, mouseY); + break; + case SDL_KEYDOWN: + keypress(&event.key.keysym); + break; } break; - case SDL_MOUSEBUTTONDOWN: - switch (event.button.button) { - case SDL_BUTTON_LEFT: - ui_mousel_down(event.button.x, event.button.y); + + /* Input while editing layer name */ + case CDRAW_STATE_LNAME: + switch (event.type) { + case SDL_QUIT: + q = 1; + break; + case SDL_WINDOWEVENT: + switch (event.window.event) { + case SDL_WINDOWEVENT_RESIZED: + r = 1; + /* FALLTROUGH */ + case SDL_WINDOWEVENT_MOVED: + break; + } + break; + case SDL_MOUSEBUTTONDOWN: + cdraw_state = CDRAW_STATE_NORMAL; + break; + case SDL_KEYDOWN: + switch(event.key.keysym.sym) { + case SDLK_BACKSPACE: + if (cur_canvas == NULL) break; + text = cur_canvas->layers[cur_canvas->a]->name; + if (strlen(text)) + text[strlen(text)-1] = '\0'; + ui_redraw_panel(UI_PANELTYPE_TIMELINE); break; - case SDL_BUTTON_RIGHT: + case SDLK_ESCAPE: + case SDLK_RETURN: + cdraw_state = CDRAW_STATE_NORMAL; break; + } + break; + case SDL_TEXTINPUT: + if (cur_canvas == NULL) break; + text = cur_canvas->layers[cur_canvas->a]->name; + if (strlen(text) >= LAYERNAMELEN) break; + strncat(text, event.text.text, LAYERNAMELEN - strlen(text)); + ui_redraw_panel(UI_PANELTYPE_TIMELINE); + break; } break; - case SDL_MOUSEBUTTONUP: - switch (event.button.button) { - case SDL_BUTTON_LEFT: - ui_mousel_up(event.button.x, event.button.y); - is_drawing = 0; - break; - } - break; - case SDL_MOUSEMOTION: - mouseX = event.motion.x; - mouseY = event.motion.y; - ui_mouse_move(mouseX, mouseY); - break; - case SDL_KEYDOWN: - keypress(&event.key.keysym); - break; } } -- cgit v1.2.3