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/canvas.c | |
parent | 67abc25311d9dc7d12b28d07aaa37fcaf9b5fee5 (diff) |
feature: add basic layer support
Diffstat (limited to 'src/canvas.c')
-rw-r--r-- | src/canvas.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/canvas.c b/src/canvas.c index 47f9b92..3a016d7 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -483,22 +483,23 @@ canvas_set_proj_path(Canvas *c, const char *path) static Layer * layer_create(uint w, uint h) { - Layer *res; - int i; + Layer *res; + int i; /* TODO: better error handling and maybe allocating together? */ - res = malloc(sizeof *res); + res = malloc(sizeof *res); - res->pix = malloc(h * w * sizeof(* res->pix)); - if (res->pix == NULL) { - fprintf(stderr, "Error creating layer\n"); - layer_destroy(res); - return NULL; - } + res->visible = 1; + res->pix = malloc(h * w * sizeof(* res->pix)); + if (res->pix == NULL) { + fprintf(stderr, "Error creating layer\n"); + layer_destroy(res); + return NULL; + } - for (i = 0; i < w*h; ++i) - res->pix[i] = 0; + for (i = 0; i < w*h; ++i) + res->pix[i] = 0; - return res; + return res; } static void @@ -575,7 +576,8 @@ canvas_point_redraw(Canvas *c, long int x, long int y) c->pres_pix[COORD(x, y)] = 0; for (i = 0; i < c->layer_arr_cnt; i++) - c->pres_pix[COORD(x, y)] = canvas_blend_color(c->pres_pix[COORD(x, y)], c->layers[i]->pix[COORD(x, y)]); + if (c->layers[i]->visible) + c->pres_pix[COORD(x, y)] = canvas_blend_color(c->pres_pix[COORD(x, y)], c->layers[i]->pix[COORD(x, y)]); } static void |