aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrow Savcik <krow@savcik.xyz>2024-02-16 18:09:29 +0200
committerKrow Savcik <krow@savcik.xyz>2024-02-16 18:09:29 +0200
commitdc9a97424933e43b69996c0cbab8ecc01cfe72d0 (patch)
treea10b9f1e45685b6455961c870daf0bb6682f19db
parent306691b02acce8711ad82c8efc736164e1fe7cd2 (diff)
improved: layers now have names
-rw-r--r--src/canvas.c22
-rw-r--r--src/canvas.h5
-rw-r--r--src/ui.c59
-rw-r--r--src/user.c4
4 files changed, 64 insertions, 26 deletions
diff --git a/src/canvas.c b/src/canvas.c
index f3ee6ec..2cc2e58 100644
--- a/src/canvas.c
+++ b/src/canvas.c
@@ -17,7 +17,7 @@ uint8 is_drawing;
#define HNEXT(i) (i == HISTLENGTH-1 ? 0 : i+1)
#define HPREV(i) (i == 0 ? HISTLENGTH-1 : i-1)
-static Layer *layer_create(uint, uint);
+static Layer *layer_create(uint, uint, uint);
static void layer_destroy(Layer *);
static uint canvas_fill_bfs(Canvas *, int, int, uint, uint);
static uint canvas_blend_color(uint, uint);
@@ -66,7 +66,7 @@ canvas_init(uint w, uint h, void *ren)
c->history[i].type = ACT_NULL;
c->pres_pix = malloc(w * h * sizeof(* c->pres_pix));
- c->layers[0] = layer_create(w, h);
+ c->layers[0] = layer_create(w, h, 1);
for (i = 0; i < c->w * c->h; ++i)
c->pres_pix[i] = 0;
@@ -427,7 +427,7 @@ canvas_export_png(Canvas *c, const char *path, void *ren)
}
void
-canvas_add_layer(Canvas *c, unsigned char pos)
+canvas_add_layer(Canvas *c, uint pos)
{
int i;
if (c == NULL)
@@ -444,7 +444,7 @@ canvas_add_layer(Canvas *c, unsigned char pos)
}
c->layer_arr_cnt++;
- c->layers[pos] = layer_create(c->w, c->h);
+ c->layers[pos] = layer_create(c->w, c->h, c->layer_arr_cnt);
}
void
@@ -481,12 +481,14 @@ canvas_set_proj_path(Canvas *c, const char *path)
}
static Layer *
-layer_create(uint w, uint h)
+layer_create(uint w, uint h, uint cnt)
{
Layer *res;
int i;
/* TODO: better error handling and maybe allocating together? */
res = malloc(sizeof *res);
+ if (res == NULL)
+ return NULL;
res->visible = 1;
res->pix = malloc(h * w * sizeof(* res->pix));
@@ -498,6 +500,16 @@ layer_create(uint w, uint h)
for (i = 0; i < w*h; ++i)
res->pix[i] = 0;
+ strcpy(res->name, "Layer ");
+ i = 10000000;
+ while (i) {
+ if (cnt / i) {
+ res->name[strlen(res->name)+1] = '\0';
+ res->name[strlen(res->name)] = ((cnt/i)%10) + '0';
+ }
+ i /= 10;
+ }
+
return res;
}
diff --git a/src/canvas.h b/src/canvas.h
index 7595473..5735aba 100644
--- a/src/canvas.h
+++ b/src/canvas.h
@@ -6,10 +6,11 @@
struct Layer {
unsigned int *pix;
unsigned int visible;
+ char name[128];
};
struct Canvas {
- unsigned char layer_arr_cnt, layer_arr_sz;
+ unsigned int layer_arr_cnt, layer_arr_sz;
unsigned int cur_col, cur_layer;
unsigned int w, h, zoom;
char *proj_path;
@@ -41,7 +42,7 @@ void canvas_point_draw(Canvas *, long int, long int);
void canvas_mousel_up(Canvas *);
void canvas_mousel_down(Canvas *, long int, long int);
void canvas_mouse_move(Canvas *, long int, long int);
-void canvas_add_layer(Canvas *, unsigned char);
+void canvas_add_layer(Canvas *, unsigned int);
void canvas_move_x(Canvas *, long int);
void canvas_move_y(Canvas *, long int);
void canvas_refresh(Canvas *);
diff --git a/src/ui.c b/src/ui.c
index 130c464..dd9c9fe 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -3,7 +3,9 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
+#define SBDF_USESDL
#include "ui.h"
+#include "sbdf.h"
#include "cdraw.h"
#include "types.h"
#include "action.h"
@@ -295,12 +297,17 @@ ui_mousel_down(int x, int y)
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);
+ if (x <= 22) {
+ 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);
+ } else if (x <= 162) {
+ y = cur_canvas->layer_arr_cnt-y-1;
+ y -= (int)(cur_canvas->cur_layer);
+ user_layer_chng(&y);
+ }
break;
}
}
@@ -674,25 +681,45 @@ ui_panel_timeline_redraw(UIPanelTimeline *p)
SDL_RenderClear(ren);
if (cur_canvas != NULL) {
dest.x = 2;
- dest.w = dest.h = 20;
+ dest.h = 20;
+ dest.w = 162;
dest.y = (cur_canvas->layer_arr_cnt - 1 - cur_canvas->cur_layer) * 22 + 2;
SDL_SetRenderDrawColor(ren, INTTOCOLA(0x657392ff));
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;
+ dest.y = 6 + (cur_canvas->layer_arr_cnt - 1 - i) * 22;
+ dest.x = 6;
+ dest.h = 24;
+ dest.w = 166;
+ SDL_RenderSetViewport(ren, &dest);
+ SDL_SetRenderDrawColor(ren, INTTOCOLA(0x131313ff));
+ SDL_RenderDrawLine(ren, 2, 0, 21, 0);
+ SDL_RenderDrawLine(ren, 2, 1, 21, 1);
+ SDL_RenderDrawLine(ren, 0, 2, 0, 21);
+ SDL_RenderDrawLine(ren, 1, 2, 1, 21);
+ SDL_RenderDrawLine(ren, 2, 22, 21, 22);
+ SDL_RenderDrawLine(ren, 2, 23, 21, 23);
+ SDL_RenderDrawLine(ren, 22, 2, 22, 21);
+ SDL_RenderDrawLine(ren, 23, 2, 23, 21);
+ SDL_RenderDrawLine(ren, 24, 0, 163, 0);
+ SDL_RenderDrawLine(ren, 24, 1, 163, 1);
+ SDL_RenderDrawLine(ren, 24, 22, 163, 22);
+ SDL_RenderDrawLine(ren, 24, 23, 163, 23);
+ SDL_RenderDrawLine(ren, 164, 2, 164, 21);
+ SDL_RenderDrawLine(ren, 165, 2, 165, 21);
+ SDL_SetRenderDrawColor(ren, INTTOCOLA(0x000000ff));
+ dest.y = dest.x = 2;
+ dest.w = dest.h = 20;
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);
+ dest.y = 6 + (cur_canvas->layer_arr_cnt - 1 - i) * 22;
+ dest.x = 30;
+ dest.w = 140;
+ dest.h = 24;
+ SDL_RenderSetViewport(ren, &dest);
+ SBDF_SDLPrint(ren, font, cur_canvas->layers[i]->name, 2, 5);
}
}
SDL_RenderSetViewport(ren, NULL);
diff --git a/src/user.c b/src/user.c
index dc2ffaf..54ae60d 100644
--- a/src/user.c
+++ b/src/user.c
@@ -170,7 +170,6 @@ user_testing_layer_add(const Arg *x)
/* TODO: temp function */
if (cur_canvas == NULL) return;
canvas_add_layer(cur_canvas, -1);
- fprintf(stdout, "%s:%u: added layer\n", __FILE__, __LINE__);
cur_canvas->cur_layer = cur_canvas->layer_arr_cnt-1;
ui_redraw_panel(UI_PANELTYPE_CANVAS);
ui_redraw_panel(UI_PANELTYPE_TIMELINE);
@@ -181,10 +180,9 @@ user_layer_chng(const Arg *x)
{
if (cur_canvas == NULL) return;
cur_canvas->cur_layer += (unsigned int)cur_canvas->layer_arr_cnt;
- cur_canvas->cur_layer += (x->i % cur_canvas->layer_arr_cnt);
+ cur_canvas->cur_layer += (x->i % (int)cur_canvas->layer_arr_cnt);
cur_canvas->cur_layer %= cur_canvas->layer_arr_cnt;
- fprintf(stdout, "%s:%u: changed to layer %u\n", __FILE__, __LINE__, cur_canvas->cur_layer);
ui_redraw_panel(UI_PANELTYPE_CANVAS);
ui_redraw_panel(UI_PANELTYPE_TIMELINE);
}