aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/canvas.h7
-rw-r--r--src/cdraw.c123
-rw-r--r--src/ui.c26
-rw-r--r--src/ui.h1
4 files changed, 124 insertions, 33 deletions
diff --git a/src/canvas.h b/src/canvas.h
index ae45dfa..21b1d67 100644
--- a/src/canvas.h
+++ b/src/canvas.h
@@ -2,11 +2,12 @@
/* TODO: move to config.h */
#define HISTLENGTH 2000
+#define LAYERNAMELEN 30
struct Layer {
unsigned int *pix;
unsigned int visible;
- char name[128];
+ char name[LAYERNAMELEN+1];
};
struct Canvas {
@@ -22,6 +23,10 @@ struct Canvas {
uint *pres_pix;
Action history[HISTLENGTH];
int hist_s, hist_e, hist_i, hist_isend;
+
+
+ /* Variables used for various editing states */
+ unsigned int a;
};
typedef struct Layer Layer;
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;
}
}
diff --git a/src/ui.c b/src/ui.c
index 9a49fc4..adc9fc8 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -329,6 +329,32 @@ ui_mousel_up(int x, int y)
}
}
+int
+ui_mouser_down(int x, int y)
+{
+ ui_focus_panel_change(x, y);
+
+ if (main_ui->focus_panel == NULL)
+ return 0;
+
+ switch (main_ui->focus_panel->type) {
+ case UI_PANELTYPE_TIMELINE:
+ if (cur_canvas == NULL)
+ return 0;
+ x = x - fpan->geom.x - 8;
+ y = y - fpan->geom.y - 8;
+ y /= 22;
+ if (y < 0 || y >= cur_canvas->layer_arr_cnt) break;
+ if (x > 22 && x <= 162) {
+ cur_canvas->a = cur_canvas->layer_arr_cnt-y-1;
+ return 1;
+ }
+ break;
+ }
+
+ return 0;
+}
+
void
ui_mouse_move(int x, int y)
{
diff --git a/src/ui.h b/src/ui.h
index 19c8881..d8e419a 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -32,5 +32,6 @@ void ui_redraw_panel(unsigned char);
void ui_present();
void ui_mousel_up(int, int);
void ui_mousel_down(int, int);
+int ui_mouser_down(int, int);
void ui_mouse_move(int, int);
unsigned char ui_theme_load(const char *);