diff options
Diffstat (limited to 'src/canvas.c')
-rw-r--r-- | src/canvas.c | 22 |
1 files changed, 17 insertions, 5 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; } |