aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subprojects/d2tk/VERSION2
-rw-r--r--subprojects/d2tk/d2tk/base.h7
-rw-r--r--subprojects/d2tk/d2tk/hash.h10
-rw-r--r--subprojects/d2tk/example/example.c32
-rw-r--r--subprojects/d2tk/nanovg/src/nanovg.c5
-rw-r--r--subprojects/d2tk/nanovg/src/nanovg.h3
-rw-r--r--subprojects/d2tk/src/backend_cairo.c10
-rw-r--r--subprojects/d2tk/src/backend_nanovg.c14
-rw-r--r--subprojects/d2tk/src/base.c46
-rw-r--r--subprojects/d2tk/src/core.c57
-rw-r--r--subprojects/d2tk/src/core_internal.h2
-rw-r--r--subprojects/d2tk/src/mum.c68
-rw-r--r--subprojects/d2tk/test/base.c6
-rw-r--r--subprojects/d2tk/test/mock.c4
14 files changed, 168 insertions, 98 deletions
diff --git a/subprojects/d2tk/VERSION b/subprojects/d2tk/VERSION
index 8bb0d09..e9d9580 100644
--- a/subprojects/d2tk/VERSION
+++ b/subprojects/d2tk/VERSION
@@ -1 +1 @@
-0.1.747
+0.1.759
diff --git a/subprojects/d2tk/d2tk/base.h b/subprojects/d2tk/d2tk/base.h
index 5a213f1..3ba8d40 100644
--- a/subprojects/d2tk/d2tk/base.h
+++ b/subprojects/d2tk/d2tk/base.h
@@ -331,14 +331,15 @@ d2tk_base_cursor(d2tk_base_t *base, const d2tk_rect_t *rect);
D2TK_API d2tk_state_t
d2tk_base_button_label_image(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, ssize_t path_len, const char *path, const d2tk_rect_t *rect);
+ const char *lbl, d2tk_align_t align, ssize_t path_len, const char *path,
+ const d2tk_rect_t *rect);
#define d2tk_base_button_label_image_is_changed(...) \
d2tk_state_is_changed(d2tk_base_button_label_image(__VA_ARGS__))
D2TK_API d2tk_state_t
d2tk_base_button_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, const d2tk_rect_t *rect);
+ const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect);
#define d2tk_base_button_label_is_changed(...) \
d2tk_state_is_changed(d2tk_base_button_label(__VA_ARGS__))
@@ -370,7 +371,7 @@ d2tk_base_button(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect);
D2TK_API d2tk_state_t
d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, const d2tk_rect_t *rect, bool *value);
+ const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect, bool *value);
#define d2tk_base_toggle_label_is_changed(...) \
d2tk_state_is_changed(d2tk_base_toggle_label(__VA_ARGS__))
diff --git a/subprojects/d2tk/d2tk/hash.h b/subprojects/d2tk/d2tk/hash.h
index fc8d70f..be69e92 100644
--- a/subprojects/d2tk/d2tk/hash.h
+++ b/subprojects/d2tk/d2tk/hash.h
@@ -27,12 +27,22 @@
extern "C" {
#endif
+typedef struct _d2tk_hash_dict_t d2tk_hash_dict_t;
+
+struct _d2tk_hash_dict_t {
+ const void *key;
+ size_t len;
+};
+
D2TK_API uint64_t
d2tk_hash(const void *data, ssize_t nbytes);
D2TK_API uint64_t
d2tk_hash_foreach(const void *data, ssize_t nbytes, ...) __attribute__((sentinel));
+D2TK_API uint64_t
+d2tk_hash_dict(const d2tk_hash_dict_t *dict);
+
#ifdef __cplusplus
}
#endif
diff --git a/subprojects/d2tk/example/example.c b/subprojects/d2tk/example/example.c
index 2247646..9cce286 100644
--- a/subprojects/d2tk/example/example.c
+++ b/subprojects/d2tk/example/example.c
@@ -108,7 +108,7 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
const size_t lbl_len = snprintf(lbl, sizeof(lbl), "%03X", k);
if(d2tk_base_toggle_label_is_changed(
- base, id, lbl_len, lbl, bnd, &val->b))
+ base, id, lbl_len, lbl, D2TK_ALIGN_CENTERED, bnd, &val->b))
{
fprintf(stdout, "toggle %016"PRIx64" %s\n", id, val->b ? "ON" : "OFF");
};
@@ -119,7 +119,7 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
const size_t lbl_len = snprintf(lbl, sizeof(lbl), "%03X", k);
if(d2tk_base_button_label_is_changed(
- base, id, lbl_len, lbl, bnd))
+ base, id, lbl_len, lbl, D2TK_ALIGN_CENTERED, bnd))
{
fprintf(stdout, "button %016"PRIx64" DOWN\n", id);
}
@@ -421,6 +421,7 @@ _render_c_scroll(d2tk_base_t *base, const d2tk_rect_t *rect)
char lbl [32];
const size_t lbl_len = snprintf(lbl, sizeof(lbl), "%u-%03u", j, k);
if(d2tk_base_button_label_image_is_changed( base, id, lbl_len, lbl,
+ D2TK_ALIGN_MIDDLE | D2TK_ALIGN_LEFT,
-1, "libre-arrow-circle-right.png", bnd))
{
fprintf(stdout, "button %016"PRIx64" DOWN\n", id);
@@ -448,7 +449,8 @@ _render_c_pane(d2tk_base_t *base, const d2tk_rect_t *rect)
// 1st
if(x == 0)
{
- if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "1st", hrect))
+ if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "1st",
+ D2TK_ALIGN_CENTERED, hrect))
{
fprintf(stdout, "button 1st DOWN\n");
}
@@ -466,7 +468,8 @@ _render_c_pane(d2tk_base_t *base, const d2tk_rect_t *rect)
// 1st
if(y == 0)
{
- if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "2nd", vrect))
+ if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "2nd",
+ D2TK_ALIGN_CENTERED, vrect))
{
fprintf(stdout, "button 2nd DOWN\n");
}
@@ -475,7 +478,8 @@ _render_c_pane(d2tk_base_t *base, const d2tk_rect_t *rect)
}
// 2nd
- if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "3rd", vrect))
+ if(d2tk_base_button_label_is_changed(base, D2TK_ID, -1, "3rd",
+ D2TK_ALIGN_CENTERED, vrect))
{
fprintf(stdout, "button 3rd DOWN\n");
}
@@ -507,7 +511,7 @@ _render_c_layout(d2tk_base_t *base, const d2tk_rect_t *rect)
const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "%"PRIu32, vfrac[y]);
if(d2tk_base_button_label_is_changed(base, D2TK_ID_IDX(x*N + y),
- lbl_len, lbl, vrect))
+ lbl_len, lbl, D2TK_ALIGN_CENTERED, vrect))
{
fprintf(stdout, "button DOWN\n");
}
@@ -520,7 +524,7 @@ _render_c_layout(d2tk_base_t *base, const d2tk_rect_t *rect)
const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "%"PRIu32, hfrac[x]);
if(d2tk_base_button_label_is_changed(base, D2TK_ID_IDX(x*N + 0),
- lbl_len, lbl, hrect))
+ lbl_len, lbl, D2TK_ALIGN_CENTERED, hrect))
{
fprintf(stdout, "button DOWN\n");
}
@@ -611,7 +615,8 @@ _render_c_flowmatrix(d2tk_base_t *base, const d2tk_rect_t *rect)
const d2tk_id_t id = D2TK_ID_IDX(i);
bool *val = &toggle[i];
- state = d2tk_base_toggle_label(base, id, lbl_len, lbl, bnd, val);
+ state = d2tk_base_toggle_label(base, id, lbl_len, lbl,
+ D2TK_ALIGN_CENTERED, bnd, val);
if(d2tk_state_is_active(state))
{
d2tk_flowmatrix_set_src(flowm, id, &pos_nodes[i]);
@@ -886,7 +891,8 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
const char *icon = "libre-gui-folder.png";
if(d2tk_base_button_label_image_is_changed(base,
- D2TK_ID_IDX(k), nxt - ptr, ptr, -1, icon, bnd))
+ D2TK_ID_IDX(k), nxt - ptr, ptr,
+ D2TK_ALIGN_MIDDLE | D2TK_ALIGN_LEFT, -1, icon, bnd))
{
*nxt = '\0';
}
@@ -930,7 +936,8 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
: "libre-gui-file.png";
if(d2tk_base_button_label_image_is_changed(base,
- D2TK_ID_IDX(k), -1, itm->d_name, -1, icon, bnd))
+ D2TK_ID_IDX(k), -1, itm->d_name,
+ D2TK_ALIGN_MIDDLE | D2TK_ALIGN_LEFT, -1, icon, bnd))
{
if(is_dir)
{
@@ -1434,7 +1441,7 @@ _render_c_keyboard(d2tk_base_t *base, const d2tk_rect_t *rect)
: keybtn->name;
const d2tk_state_t state = d2tk_base_button_label(base,
- D2TK_ID_IDX(keybtn-keybtns), -1, lbl, &bnd);
+ D2TK_ID_IDX(keybtn-keybtns), -1, lbl, D2TK_ALIGN_CENTERED, &bnd);
if(d2tk_state_is_down(state))
{
@@ -1517,7 +1524,8 @@ d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
const unsigned b = d2tk_table_get_index(tab);
bool val = (b == bar);
- d2tk_base_toggle_label(base, D2TK_ID_IDX(b), -1, bar_lbl[b], hrect, &val);
+ d2tk_base_toggle_label(base, D2TK_ID_IDX(b), -1, bar_lbl[b],
+ D2TK_ALIGN_CENTERED, hrect, &val);
if(val)
{
bar = b;
diff --git a/subprojects/d2tk/nanovg/src/nanovg.c b/subprojects/d2tk/nanovg/src/nanovg.c
index f82f76c..f642788 100644
--- a/subprojects/d2tk/nanovg/src/nanovg.c
+++ b/subprojects/d2tk/nanovg/src/nanovg.c
@@ -841,6 +841,11 @@ void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data)
ctx->params.renderUpdateTexture(ctx->params.userPtr, image, 0,0, w,h, data);
}
+void nvgUpdateSubImage(NVGcontext* ctx, int image, const unsigned char* data, int x, int y, int w, int h)
+{
+ ctx->params.renderUpdateTexture(ctx->params.userPtr, image, x,y, w,h, data);
+}
+
void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h)
{
ctx->params.renderGetTextureSize(ctx->params.userPtr, image, w, h);
diff --git a/subprojects/d2tk/nanovg/src/nanovg.h b/subprojects/d2tk/nanovg/src/nanovg.h
index e3d7ee1..8aaec30 100644
--- a/subprojects/d2tk/nanovg/src/nanovg.h
+++ b/subprojects/d2tk/nanovg/src/nanovg.h
@@ -386,6 +386,9 @@ int nvgCreateImageARGB(NVGcontext* ctx, int w, int h, int imageFlags, const unsi
// Updates image data specified by image handle.
void nvgUpdateImage(NVGcontext* ctx, int image, const unsigned char* data);
+// Updates part image data specified by image handle.
+void nvgUpdateSubImage(NVGcontext* ctx, int image, const unsigned char* data, int x, int y, int w, int h);
+
// Returns the dimensions of a created image.
void nvgImageSize(NVGcontext* ctx, int image, int* w, int* h);
diff --git a/subprojects/d2tk/src/backend_cairo.c b/subprojects/d2tk/src/backend_cairo.c
index b1a8dee..a96d831 100644
--- a/subprojects/d2tk/src/backend_cairo.c
+++ b/subprojects/d2tk/src/backend_cairo.c
@@ -100,12 +100,14 @@ d2tk_cairo_pre(void *data, d2tk_core_t *core __attribute((unused)),
cairo_save(ctx);
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
cairo_surface_t *surf = cairo_image_surface_create_for_data(
(uint8_t *)pixels, CAIRO_FORMAT_ARGB32, w, h, w*sizeof(uint32_t));
+ //FIXME reuse/update surfaces
- cairo_rectangle(ctx, 0, 0, w, h);
+ cairo_rectangle(ctx, rect.x, rect.y, rect.w, rect.h);
cairo_clip(ctx);
cairo_new_sub_path(ctx);
@@ -132,7 +134,8 @@ d2tk_cairo_post(void *data, d2tk_core_t *core __attribute__((unused)),
#ifdef D2TK_DEBUG //FIXME needs multiple buffers to work
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
// brighten up the pixels for proper hilighting
for(d2tk_coord_t y = 0, Y = 0; y < h; y++, Y+=w)
@@ -148,6 +151,7 @@ d2tk_cairo_post(void *data, d2tk_core_t *core __attribute__((unused)),
cairo_surface_t *surf = cairo_image_surface_create_for_data(
(uint8_t *)pixels, CAIRO_FORMAT_ARGB32, w, h, w*sizeof(uint32_t));
+ //FIXME reuse/update suface
cairo_rectangle(ctx, 0, 0, w, h);
cairo_clip(ctx);
diff --git a/subprojects/d2tk/src/backend_nanovg.c b/subprojects/d2tk/src/backend_nanovg.c
index 6f9a411..ad48e16 100644
--- a/subprojects/d2tk/src/backend_nanovg.c
+++ b/subprojects/d2tk/src/backend_nanovg.c
@@ -210,21 +210,23 @@ d2tk_nanovg_pre(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
{
// draw mask
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
if(backend->mask)
{
- nvgUpdateImage(ctx, backend->mask, (const uint8_t *)pixels);
+ nvgUpdateSubImage(ctx, backend->mask, (const uint8_t *)pixels,
+ rect.x, rect.y, rect.w, rect.h);
}
else
{
backend->mask = nvgCreateImageRGBA(ctx, w, h, NVG_IMAGE_NEAREST,
(const uint8_t *)pixels);
}
-
+
const NVGpaint bg = nvgImagePattern(ctx, 0, 0, w, h, 0, backend->mask, 1.f);
nvgBeginPath(ctx);
- nvgRect(ctx, 0, 0, w, h);
+ nvgRect(ctx, rect.x, rect.y, rect.w, rect.h);
nvgStrokeWidth(ctx, 0);
nvgFillPaint(ctx, bg);
nvgFill(ctx);
@@ -271,7 +273,8 @@ d2tk_nanovg_post(void *data, d2tk_core_t *core __attribute__((unused)),
#ifdef D2TK_DEBUG
{
- uint32_t *pixels = d2tk_core_get_pixels(core);
+ d2tk_rect_t rect;
+ uint32_t *pixels = d2tk_core_get_pixels(core, &rect);
// brighten up the pixels for proper hilighting
for(d2tk_coord_t y = 0, Y = 0; y < h; y++, Y+=w)
@@ -284,6 +287,7 @@ d2tk_nanovg_post(void *data, d2tk_core_t *core __attribute__((unused)),
}
}
}
+
if(backend->mask)
{
nvgUpdateImage(ctx, backend->mask, (const uint8_t *)pixels);
diff --git a/subprojects/d2tk/src/base.c b/subprojects/d2tk/src/base.c
index 6abe25b..da1df31 100644
--- a/subprojects/d2tk/src/base.c
+++ b/subprojects/d2tk/src/base.c
@@ -1657,7 +1657,7 @@ d2tk_base_cursor(d2tk_base_t *base, const d2tk_rect_t *rect)
static inline void
_d2tk_base_draw_button(d2tk_core_t *core, ssize_t lbl_len, const char *lbl,
- ssize_t path_len, const char *path,
+ d2tk_align_t align, ssize_t path_len, const char *path,
const d2tk_rect_t *rect, d2tk_triple_t triple, const d2tk_style_t *style)
{
const bool has_lbl = lbl_len && lbl;
@@ -1673,12 +1673,16 @@ _d2tk_base_draw_button(d2tk_core_t *core, ssize_t lbl_len, const char *lbl,
path_len = strlen(path);
}
- const uint64_t hash = d2tk_hash_foreach(&triple, sizeof(d2tk_triple_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- (lbl ? lbl : path), (lbl ? lbl_len : path_len),
- (path ? path : NULL), (path ? path_len : 0),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &triple, sizeof(d2tk_triple_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &align, sizeof(d2tk_align_t) },
+ { (lbl ? lbl : path), (lbl ? lbl_len : path_len) },
+ { path, path_len },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1708,8 +1712,7 @@ _d2tk_base_draw_button(d2tk_core_t *core, ssize_t lbl_len, const char *lbl,
if(has_lbl)
{
const d2tk_coord_t h_2 = rect->h / 2;
- const d2tk_align_t lbl_align = D2TK_ALIGN_MIDDLE
- | (has_img ? D2TK_ALIGN_LEFT : D2TK_ALIGN_CENTER);
+ const d2tk_align_t lbl_align = align;
const size_t ref = d2tk_core_bbox_push(core, true, rect);
@@ -1740,7 +1743,8 @@ _d2tk_base_draw_button(d2tk_core_t *core, ssize_t lbl_len, const char *lbl,
D2TK_API d2tk_state_t
d2tk_base_button_label_image(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, ssize_t path_len, const char *path, const d2tk_rect_t *rect)
+ const char *lbl, d2tk_align_t align, ssize_t path_len, const char *path,
+ const d2tk_rect_t *rect)
{
d2tk_state_t state = d2tk_base_is_active_hot(base, id, rect, D2TK_FLAG_NONE);
@@ -1766,35 +1770,38 @@ d2tk_base_button_label_image(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
triple |= D2TK_TRIPLE_FOCUS;
}
- _d2tk_base_draw_button(base->core, lbl_len, lbl, path_len, path, rect, triple,
- d2tk_base_get_style(base));
+ _d2tk_base_draw_button(base->core, lbl_len, lbl, align, path_len, path, rect,
+ triple, d2tk_base_get_style(base));
return state;
}
D2TK_API d2tk_state_t
d2tk_base_button_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, const d2tk_rect_t *rect)
+ const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect)
{
- return d2tk_base_button_label_image(base, id, lbl_len, lbl, 0, NULL, rect);
+ return d2tk_base_button_label_image(base, id, lbl_len, lbl,
+ align, 0, NULL, rect);
}
D2TK_API d2tk_state_t
d2tk_base_button_image(d2tk_base_t *base, d2tk_id_t id, ssize_t path_len,
const char *path, const d2tk_rect_t *rect)
{
- return d2tk_base_button_label_image(base, id, 0, NULL, path_len, path, rect);
+ return d2tk_base_button_label_image(base, id, 0, NULL,
+ D2TK_ALIGN_NONE, path_len, path, rect);
}
D2TK_API d2tk_state_t
d2tk_base_button(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect)
{
- return d2tk_base_button_label_image(base, id, 0, NULL, 0, NULL, rect);
+ return d2tk_base_button_label_image(base, id, 0, NULL,
+ D2TK_ALIGN_NONE, 0, NULL, rect);
}
D2TK_API d2tk_state_t
d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
- const char *lbl, const d2tk_rect_t *rect, bool *value)
+ const char *lbl, d2tk_align_t align, const d2tk_rect_t *rect, bool *value)
{
d2tk_state_t state = d2tk_base_is_active_hot(base, id, rect, D2TK_FLAG_NONE);
@@ -1821,7 +1828,7 @@ d2tk_base_toggle_label(d2tk_base_t *base, d2tk_id_t id, ssize_t lbl_len,
triple |= D2TK_TRIPLE_FOCUS;
}
- _d2tk_base_draw_button(base->core, lbl_len, lbl, 0, NULL, rect, triple,
+ _d2tk_base_draw_button(base->core, lbl_len, lbl, align, 0, NULL, rect, triple,
d2tk_base_get_style(base));
return state;
@@ -1831,7 +1838,8 @@ D2TK_API d2tk_state_t
d2tk_base_toggle(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
bool *value)
{
- return d2tk_base_toggle_label(base, id, 0, NULL, rect, value);
+ return d2tk_base_toggle_label(base, id, 0, NULL,
+ D2TK_ALIGN_NONE, rect, value);
}
D2TK_API void
diff --git a/subprojects/d2tk/src/core.c b/subprojects/d2tk/src/core.c
index 79e76af..7910dd1 100644
--- a/subprojects/d2tk/src/core.c
+++ b/subprojects/d2tk/src/core.c
@@ -56,6 +56,7 @@ struct _d2tk_mem_t {
struct _d2tk_bitmap_t {
size_t size;
uint32_t *pixels;
+ uint32_t *template;
size_t nfills;
d2tk_coord_t x0;
d2tk_coord_t x1;
@@ -342,10 +343,26 @@ _d2tk_memcaches_gc(d2tk_core_t *core)
}
static inline void
-_d2tk_bitmap_resize(d2tk_bitmap_t *bitmap, d2tk_coord_t w, d2tk_coord_t h)
+_d2tk_bitmap_template_refill(d2tk_core_t *core)
{
- bitmap->size = w*h*sizeof(uint32_t);
+ d2tk_bitmap_t *bitmap = &core->bitmap;
+
+ for(d2tk_coord_t x = 0; x < core->w; x++)
+ {
+ bitmap->template[x] = core->bg_color;
+ }
+}
+
+static inline void
+_d2tk_bitmap_resize(d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h)
+{
+ d2tk_bitmap_t *bitmap = &core->bitmap;
+
+ const size_t stride = w*sizeof(uint32_t);
+ bitmap->size = h*stride;
bitmap->pixels = realloc(bitmap->pixels, bitmap->size);
+ bitmap->template = realloc(bitmap->template, stride);
+ _d2tk_bitmap_template_refill(core);
}
static inline void
@@ -353,14 +370,24 @@ _d2tk_bitmap_deinit(d2tk_bitmap_t *bitmap)
{
free(bitmap->pixels);
bitmap->pixels = NULL;
+ free(bitmap->template);
+ bitmap->template = NULL;
bitmap->size = 0;
bitmap->nfills = 0;
}
static inline void
-_d2tk_bitmap_reset(d2tk_bitmap_t *bitmap)
+_d2tk_bitmap_reset(d2tk_core_t *core)
{
- memset(bitmap->pixels, 0x0, bitmap->size);
+ d2tk_bitmap_t *bitmap = &core->bitmap;
+
+ const size_t stride = (bitmap->x1 - bitmap->x0)*sizeof(uint32_t);
+
+ for(d2tk_coord_t y = bitmap->y0, Y = y*core->w; y < bitmap->y1; y++, Y+=core->w)
+ {
+ memset(&bitmap->pixels[Y + bitmap->x0], 0x0, stride);
+ }
+
bitmap->nfills = 0;
bitmap->x0 = INT_MAX;
bitmap->x1 = INT_MIN;
@@ -402,12 +429,11 @@ _d2tk_bitmap_fill(d2tk_core_t *core, const d2tk_clip_t *clip)
d2tk_clip_t dst;
_d2tk_clip_clip(core, &dst, clip);
+ const size_t stride = (dst.x1 - dst.x0)*sizeof(uint32_t);
+
for(d2tk_coord_t y = dst.y0, Y = y*core->w; y < dst.y1; y++, Y+=core->w)
{
- for(d2tk_coord_t x = dst.x0; x < dst.x1; x++)
- {
- bitmap->pixels[Y + x] = core->bg_color;
- }
+ memcpy(&bitmap->pixels[Y + dst.x0], bitmap->template, stride);
}
// update area of interest
@@ -455,8 +481,16 @@ _d2tk_bbox_mask(d2tk_core_t *core, d2tk_com_t *com)
}
uint32_t *
-d2tk_core_get_pixels(d2tk_core_t *core)
+d2tk_core_get_pixels(d2tk_core_t *core, d2tk_rect_t *rect)
{
+ if(rect)
+ {
+ rect->x = core->bitmap.x0;
+ rect->y = core->bitmap.y0;
+ rect->w = core->bitmap.x1 - core->bitmap.x0;
+ rect->h = core->bitmap.y1 - core->bitmap.y0;
+ }
+
return core->bitmap.pixels;
}
@@ -714,6 +748,7 @@ void
d2tk_core_set_bg_color(d2tk_core_t *core, uint32_t rgba)
{
core->bg_color = htonl(rgba);
+ _d2tk_bitmap_template_refill(core);
}
uint32_t
@@ -1304,7 +1339,7 @@ d2tk_core_post(d2tk_core_t *core)
d2tk_com_t *oldcom = _d2tk_mem_get_com(oldmem);
// reset num of clipping clips
- _d2tk_bitmap_reset(bitmap);
+ _d2tk_bitmap_reset(core);
if(core->full_refresh)
{
@@ -1516,7 +1551,7 @@ d2tk_core_set_dimensions(d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h)
core->w = w;
core->h = h;
core->full_refresh = true;
- _d2tk_bitmap_resize(&core->bitmap, w, h);
+ _d2tk_bitmap_resize(core, w, h);
}
D2TK_API void
diff --git a/subprojects/d2tk/src/core_internal.h b/subprojects/d2tk/src/core_internal.h
index 91c1ef0..d875e8b 100644
--- a/subprojects/d2tk/src/core_internal.h
+++ b/subprojects/d2tk/src/core_internal.h
@@ -295,7 +295,7 @@ d2tk_com_next(d2tk_com_t *bbox);
(BBOX) = d2tk_com_next((BBOX)))
uint32_t *
-d2tk_core_get_pixels(d2tk_core_t *core);
+d2tk_core_get_pixels(d2tk_core_t *core, d2tk_rect_t *rect);
void
d2tk_core_set_bg_color(d2tk_core_t *core, uint32_t rgba);
diff --git a/subprojects/d2tk/src/mum.c b/subprojects/d2tk/src/mum.c
index d988418..146ea3c 100644
--- a/subprojects/d2tk/src/mum.c
+++ b/subprojects/d2tk/src/mum.c
@@ -26,67 +26,57 @@
__attribute__((always_inline))
static inline size_t
-_sz(const void *data, ssize_t nbytes)
+_len(const void *key, ssize_t len)
{
- if(nbytes == -1) // is a null-terminated string
- {
- return strlen((const char *)data);
- }
+ return (len == -1) ? strlen((const char *)key) : (size_t)len;
+}
- return nbytes;
+__attribute__((always_inline))
+static inline uint64_t
+_d2tk_hash(uint64_t hash, const void *key, size_t len)
+{
+ return _mum_hash_aligned(hash + len, key, len);
}
D2TK_API uint64_t
-d2tk_hash(const void *data, ssize_t nbytes)
+d2tk_hash(const void *key, ssize_t len)
{
- nbytes = _sz(data, nbytes);
+ len = _len(key, len);
- return mum_hash(data, nbytes, SEED);
+ return mum_hash(key, len, SEED);
}
D2TK_API uint64_t
-d2tk_hash_foreach(const void *data, ssize_t nbytes, ...)
+d2tk_hash_foreach(const void *key, ssize_t len, ...)
{
va_list args;
- const void *src;
-
- nbytes = _sz(data, nbytes);
+ uint64_t hash = mum_hash_init(SEED);
- // derive total temporary buffer size
- size_t sz = nbytes;
+ len = _len(key, len); //FIXME remove
+ hash = _d2tk_hash(hash, key, len);
- va_start(args, nbytes);
+ va_start(args, len);
- while( (src = va_arg(args, const void *)) )
+ while( (key = va_arg(args, const void *)) )
{
- sz += _sz(src, va_arg(args, int));
+ len = _len(key, va_arg(args, int)); //FIXME remove
+ hash = _d2tk_hash(hash, key, len);
}
va_end(args);
- // fill temporary bufffer
- uint8_t *dst = alloca(sz);
- if(dst)
- {
- size_t off = 0;
-
- memcpy(&dst[off], data, nbytes);
- off += nbytes;
-
- va_start(args, nbytes);
-
- while( (src = va_arg(args, const void *)) )
- {
- nbytes = _sz(src, va_arg(args, int));
-
- memcpy(&dst[off], src, nbytes);
- off += nbytes;
- }
+ return mum_hash_finish(hash);
+}
- va_end(args);
+D2TK_API uint64_t
+d2tk_hash_dict(const d2tk_hash_dict_t *dict)
+{
+ uint64_t hash = mum_hash_init(SEED);
- return mum_hash(dst, sz, SEED);
+ for( ; dict->key; dict++)
+ {
+ hash = _d2tk_hash(hash, dict->key, dict->len);
}
- return 0;
+ return mum_hash_finish(hash);
}
diff --git a/subprojects/d2tk/test/base.c b/subprojects/d2tk/test/base.c
index 9580977..87b57fe 100644
--- a/subprojects/d2tk/test/base.c
+++ b/subprojects/d2tk/test/base.c
@@ -1282,7 +1282,7 @@ _test_button_label_image()
assert(base);
const d2tk_state_t state = d2tk_base_button_label_image(base, D2TK_ID,
- -1, "label", -1, "image.png", &rect);
+ -1, "label", D2TK_ALIGN_CENTERED, -1, "image.png", &rect);
assert(state == (D2TK_STATE_HOT | D2TK_STATE_FOCUS | D2TK_STATE_FOCUS_IN
|D2TK_STATE_OVER) );
@@ -1301,7 +1301,7 @@ _test_button_label()
assert(base);
const d2tk_state_t state = d2tk_base_button_label(base, D2TK_ID,
- -1, "label", &rect);
+ -1, "label", D2TK_ALIGN_CENTERED, &rect);
assert(state == (D2TK_STATE_HOT | D2TK_STATE_FOCUS | D2TK_STATE_FOCUS_IN
| D2TK_STATE_OVER) );
@@ -1358,7 +1358,7 @@ _test_toggle_label()
bool val = false;
const d2tk_state_t state = d2tk_base_toggle_label(base, D2TK_ID,
- -1, "label", &rect, &val);
+ -1, "label", D2TK_ALIGN_CENTERED, &rect, &val);
assert(state == (D2TK_STATE_HOT | D2TK_STATE_FOCUS | D2TK_STATE_FOCUS_IN
| D2TK_STATE_OVER) );
assert(val == false);
diff --git a/subprojects/d2tk/test/mock.c b/subprojects/d2tk/test/mock.c
index 95ef666..7e77a43 100644
--- a/subprojects/d2tk/test/mock.c
+++ b/subprojects/d2tk/test/mock.c
@@ -45,7 +45,9 @@ _d2tk_mock_post(void *data, d2tk_core_t *core, d2tk_coord_t w, d2tk_coord_t h,
assert(h == DIM_H);
assert(pass == 0);
- assert(d2tk_core_get_pixels(core));
+ d2tk_rect_t rect;
+ assert(d2tk_core_get_pixels(core, &rect));
+ assert( (rect.w != 0) && (rect.h != 0) );
return false; // do NOT enter 3rd pass
}