diff options
author | Krow Savcik <krow@savcik.xyz> | 2024-02-13 12:00:11 +0200 |
---|---|---|
committer | Krow Savcik <krow@savcik.xyz> | 2024-02-13 12:00:11 +0200 |
commit | 8b8e1cab080dfea106bebe9d4eeecf5812182e94 (patch) | |
tree | 1ced4cdeecf7b49db78f69b6f65f334221bdac13 /src/ui.c | |
parent | 67abc25311d9dc7d12b28d07aaa37fcaf9b5fee5 (diff) |
feature: add basic layer support
Diffstat (limited to 'src/ui.c')
-rw-r--r-- | src/ui.c | 65 |
1 files changed, 63 insertions, 2 deletions
@@ -40,6 +40,10 @@ static const SDL_Rect ui_buttons_rect[] = { {84, 82, 28, 28}, /* Undo */ {84, 110, 28, 28}, /* Redo */ }; +static const SDL_Rect ui_timeline_rect[] = { + {112, 0, 20, 20}, + {112, 20, 20, 20}, +}; struct UIPanel { uint8 type, redraw; @@ -136,7 +140,7 @@ ui_create(const char *path) /* ui_panel_divider_init(&main_ui->p_divs[0], 5, 10, 100, 1, &main_ui->p_canvas, &main_ui->p_timeline); */ ui_panel_divider_init(&main_ui->p_divs[0], 5, 5, 120, 0, &main_ui->p_divs[1], &main_ui->p_divs[2]); ui_panel_divider_init(&main_ui->p_divs[1], 0, 8, 22+31*((tool_array_size()+2)/3), 3, &main_ui->p_palette, &main_ui->p_buttons); - ui_panel_divider_init(&main_ui->p_divs[2], 0, 5, 70, 3, &main_ui->p_canvas, &main_ui->p_timeline); + ui_panel_divider_init(&main_ui->p_divs[2], 0, 5, 120, 3, &main_ui->p_canvas, &main_ui->p_timeline); ui_resize(); } @@ -285,6 +289,19 @@ ui_mousel_down(int x, int y) break; } break; + case UI_PANELTYPE_TIMELINE: + if (cur_canvas == NULL) + return; + x = x - fpan->geom.x - 8; + y = y - fpan->geom.y - 8; + y /= 22; + if (x > 22) break; + if (y < 0 || y >= cur_canvas->layer_arr_cnt) break; + cur_canvas->layers[cur_canvas->layer_arr_cnt-1-y]->visible ^= 1; + canvas_refresh(cur_canvas); + ui_redraw_panel(UI_PANELTYPE_TIMELINE); + ui_redraw_panel(UI_PANELTYPE_CANVAS); + break; } } @@ -362,6 +379,11 @@ ui_focus_panel(int x, int y) && x - r->x < r->w && y - r->y < r->h) return &main_ui->p_canvas.head; + r = &main_ui->p_timeline.head.geom; + if (r->x <= x && r->y <= y + && x - r->x < r->w && y - r->y < r->h) + return &main_ui->p_timeline.head; + return NULL; } @@ -455,7 +477,7 @@ ui_panel_redraw(UIPanel *p) ui_panel_buttons_redraw((UIPanelButtons *)p); break; case UI_PANELTYPE_TIMELINE: - ui_panel_draw_frame(p); + ui_panel_timeline_redraw((UIPanelTimeline *)p); break; default: fprintf(stderr, "%s:%d:ui_panel_redraw: No redraw fuction for %u\n", __FILE__, __LINE__, p->type); @@ -638,6 +660,45 @@ ui_panel_timeline_init(UIPanelTimeline *p) return ui_panel_init((UIPanel *)p, UI_PANELTYPE_TIMELINE); } +static uint8 +ui_panel_timeline_redraw(UIPanelTimeline *p) +{ + SDL_Rect dest; + int i; + dest.x = 6; + dest.y = 6; + dest.w = p->head.geom.w - 12; + dest.h = p->head.geom.h - 12; + SDL_RenderSetViewport(ren, &dest); + SDL_SetRenderDrawColor(ren, 199, 207, 221, 255); + SDL_RenderClear(ren); + if (cur_canvas != NULL) { + dest.x = 2; + dest.w = dest.h = 20; + dest.y = (cur_canvas->layer_arr_cnt - 1 - cur_canvas->cur_layer) * 22 + 2; + SDL_SetRenderDrawColor(ren, 101, 115, 146, 255); + SDL_RenderFillRect(ren, &dest); + SDL_SetRenderDrawColor(ren, 19, 19, 19, 255); + for (i = 0; i < cur_canvas->layer_arr_cnt; i++) { + dest.y = (cur_canvas->layer_arr_cnt - 1 - i) * 22 + 2; + if (cur_canvas->layers[i]->visible) + SDL_RenderCopy(ren, main_ui->theme, &ui_timeline_rect[0], &dest); + else + SDL_RenderCopy(ren, main_ui->theme, &ui_timeline_rect[1], &dest); + SDL_RenderDrawLine(ren, 2, i*22, 21, i*22); + SDL_RenderDrawLine(ren, 2, i*22+1, 21, i*22+1); + SDL_RenderDrawLine(ren, 0, i*22+2, 0, i*22+21); + SDL_RenderDrawLine(ren, 1, i*22+2, 1, i*22+21); + SDL_RenderDrawLine(ren, 2, i*22+22, 21, i*22+22); + SDL_RenderDrawLine(ren, 2, i*22+23, 21, i*22+23); + SDL_RenderDrawLine(ren, 22, i*22+2, 22, i*22+21); + SDL_RenderDrawLine(ren, 23, i*22+2, 23, i*22+21); + } + } + SDL_RenderSetViewport(ren, NULL); + ui_panel_draw_frame(&p->head); +} + /* Panel divider functions */ static uint8 ui_panel_divider_init(UIPanelDivider *p, int fw, int lw, int of, uint8 st, UIPanel *p1, UIPanel *p2) |