aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-05 21:03:35 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-05 21:03:35 +0200
commitfc076b70f6bb8c6a44be04d688473b471f855cb0 (patch)
tree4d73699834a8701e01440fb4da132ef99faf2ce5
parent9c09a3f3c2c5d2e040a45d342a384d44513b5b3e (diff)
parent3a61526a6707ca9b68750fe14cad9850093dafb9 (diff)
downloadtracker.lv2-fc076b70f6bb8c6a44be04d688473b471f855cb0.zip
tracker.lv2-fc076b70f6bb8c6a44be04d688473b471f855cb0.tar.gz
tracker.lv2-fc076b70f6bb8c6a44be04d688473b471f855cb0.tar.bz2
tracker.lv2-fc076b70f6bb8c6a44be04d688473b471f855cb0.tar.xz
Merge commit '3a61526a6707ca9b68750fe14cad9850093dafb9'
-rw-r--r--subprojects/d2tk/VERSION2
-rw-r--r--subprojects/d2tk/d2tk/base.h8
-rw-r--r--subprojects/d2tk/example/example.c54
-rw-r--r--subprojects/d2tk/src/base.c272
-rw-r--r--subprojects/d2tk/src/mum.c13
-rw-r--r--subprojects/d2tk/test/base.c88
-rw-r--r--subprojects/d2tk/test/core.c22
7 files changed, 316 insertions, 143 deletions
diff --git a/subprojects/d2tk/VERSION b/subprojects/d2tk/VERSION
index d6039d6..75dd97f 100644
--- a/subprojects/d2tk/VERSION
+++ b/subprojects/d2tk/VERSION
@@ -1 +1 @@
-0.1.767
+0.1.775
diff --git a/subprojects/d2tk/d2tk/base.h b/subprojects/d2tk/d2tk/base.h
index 76bbf24..b51b3fe 100644
--- a/subprojects/d2tk/d2tk/base.h
+++ b/subprojects/d2tk/d2tk/base.h
@@ -105,6 +105,8 @@ typedef enum _d2tk_flag_t {
D2TK_FLAG_LAYOUT_Y_REL = D2TK_FLAG_LAYOUT_Y | D2TK_FLAG_LAYOUT_REL,
D2TK_FLAG_LAYOUT_X_ABS = D2TK_FLAG_LAYOUT_X | D2TK_FLAG_LAYOUT_ABS,
D2TK_FLAG_LAYOUT_Y_ABS = D2TK_FLAG_LAYOUT_Y | D2TK_FLAG_LAYOUT_ABS,
+ D2TK_FLAG_TABLE_ABS = (1 << 8),
+ D2TK_FLAG_TABLE_REL = (1 << 9),
} d2tk_flag_t;
#define D2TK_ID_IDX(IDX) ((d2tk_id_t)__LINE__ << 16) | (IDX)
@@ -124,7 +126,7 @@ extern const size_t d2tk_pane_sz;
D2TK_API d2tk_table_t *
d2tk_table_begin(const d2tk_rect_t *rect, unsigned N, unsigned M,
- d2tk_table_t *tab);
+ d2tk_flag_t flag, d2tk_table_t *tab);
D2TK_API bool
d2tk_table_not_end(d2tk_table_t *tab);
@@ -144,8 +146,8 @@ d2tk_table_get_index_y(d2tk_table_t *tab);
D2TK_API const d2tk_rect_t *
d2tk_table_get_rect(d2tk_table_t *tab);
-#define D2TK_BASE_TABLE(RECT, N, M, TAB) \
- for(d2tk_table_t *(TAB) = d2tk_table_begin((RECT), (N), (M), \
+#define D2TK_BASE_TABLE(RECT, N, M, FLAG, TAB) \
+ for(d2tk_table_t *(TAB) = d2tk_table_begin((RECT), (N), (M), (FLAG), \
alloca(d2tk_table_sz)); \
d2tk_table_not_end((TAB)); \
(TAB) = d2tk_table_next((TAB)))
diff --git a/subprojects/d2tk/example/example.c b/subprojects/d2tk/example/example.c
index be4c257..b410d8e 100644
--- a/subprojects/d2tk/example/example.c
+++ b/subprojects/d2tk/example/example.c
@@ -56,6 +56,7 @@ union _val_t {
typedef enum _bar_t {
BAR_MIX,
BAR_SEQ,
+ BAR_TABLE_ABS,
BAR_SCROLL,
BAR_PANE,
BAR_LAYOUT,
@@ -74,6 +75,7 @@ static bar_t bar = BAR_MIX;
static const char *bar_lbl [BAR_MAX] = {
[BAR_MIX] = "Mix of many",
[BAR_SEQ] = "Sequencer",
+ [BAR_TABLE_ABS] = "Table Abs",
[BAR_SCROLL] = "Scrollbar",
[BAR_PANE] = "Pane",
[BAR_LAYOUT] = "Layout",
@@ -93,7 +95,7 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
#define M 24
static val_t value [N*M];
- D2TK_BASE_TABLE(rect, N, M, tab)
+ D2TK_BASE_TABLE(rect, N, M, D2TK_FLAG_TABLE_REL, tab)
{
const unsigned k = d2tk_table_get_index(tab);
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
@@ -255,7 +257,7 @@ _render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
style.rounding = 0;
d2tk_base_set_style(base, &style);
- D2TK_BASE_TABLE(rect, N, M, tab)
+ D2TK_BASE_TABLE(rect, N, M, D2TK_FLAG_TABLE_REL, tab)
{
const unsigned k = d2tk_table_get_index(tab);
const d2tk_coord_t x = d2tk_table_get_index_x(tab);
@@ -376,6 +378,34 @@ _render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
}
static inline void
+_render_c_table_abs(d2tk_base_t *base, const d2tk_rect_t *rect)
+{
+ static int32_t ntile = 64;
+
+ if(d2tk_base_get_ctrl(base))
+ {
+ if(d2tk_base_get_down(base))
+ {
+ ntile >>= 1;
+ }
+ else if(d2tk_base_get_up(base))
+ {
+ ntile <<= 1;
+ }
+ }
+
+ d2tk_clip_int32(16, &ntile, 256);
+
+ D2TK_BASE_TABLE(rect, ntile, ntile, D2TK_FLAG_TABLE_ABS, tab)
+ {
+ const d2tk_rect_t *rect = d2tk_table_get_rect(tab);
+ const unsigned k = d2tk_table_get_index(tab);
+
+ d2tk_base_button(base, D2TK_ID_IDX(k), rect);
+ }
+}
+
+static inline void
_render_c_scroll(d2tk_base_t *base, const d2tk_rect_t *rect)
{
#define N 12 // number of columns
@@ -391,7 +421,7 @@ _render_c_scroll(d2tk_base_t *base, const d2tk_rect_t *rect)
const float hoffset = d2tk_scrollbar_get_offset_x(hscroll);
const d2tk_rect_t *row = d2tk_scrollbar_get_rect(hscroll);
- D2TK_BASE_TABLE(row, N_2, 1, tcol)
+ D2TK_BASE_TABLE(row, N_2, 1, D2TK_FLAG_TABLE_REL, tcol)
{
const unsigned j = d2tk_table_get_index_x(tcol) + hoffset;
const d2tk_rect_t *col = d2tk_table_get_rect(tcol);
@@ -404,7 +434,7 @@ _render_c_scroll(d2tk_base_t *base, const d2tk_rect_t *rect)
d2tk_base_set_style(base, &style);
- D2TK_BASE_TABLE(sub, 1, O, tlist)
+ D2TK_BASE_TABLE(sub, 1, O, D2TK_FLAG_TABLE_REL, tlist)
{
const unsigned k = d2tk_table_get_index_y(tlist) + voffset;
const d2tk_rect_t *bnd = d2tk_table_get_rect(tlist);
@@ -663,7 +693,7 @@ _render_c_meter(d2tk_base_t *base, const d2tk_rect_t *rect)
const float fx = (float)x / w;
const float fy = (float)y / h;
- D2TK_BASE_TABLE(rect, N, M, tab)
+ D2TK_BASE_TABLE(rect, N, M, D2TK_FLAG_TABLE_REL, tab)
{
const unsigned k = d2tk_table_get_index(tab);
const unsigned a = d2tk_table_get_index_x(tab);
@@ -696,7 +726,7 @@ _render_c_frame(d2tk_base_t *base, const d2tk_rect_t *rect)
#define N 4
static bool val [N];
- D2TK_BASE_TABLE(rect, N, N, tab)
+ D2TK_BASE_TABLE(rect, N, N, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd_outer = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -840,7 +870,7 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
struct dirent *list = _file_list_new(root, &nlist, false);
d2tk_style_t style = *d2tk_base_get_default_style();
- D2TK_BASE_TABLE(rect, 2, 1, brow)
+ D2TK_BASE_TABLE(rect, 2, 1, D2TK_FLAG_TABLE_REL, brow)
{
const unsigned r = d2tk_table_get_index(brow);
const d2tk_rect_t *col = d2tk_table_get_rect(brow);
@@ -867,7 +897,7 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
d2tk_base_set_style(base, &style);
- D2TK_BASE_TABLE(row, 1, M, tab)
+ D2TK_BASE_TABLE(row, 1, M, D2TK_FLAG_TABLE_REL, tab)
{
const unsigned k = d2tk_table_get_index(tab) + voffset;
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
@@ -915,7 +945,7 @@ _render_c_browser(d2tk_base_t *base, const d2tk_rect_t *rect)
d2tk_base_set_style(base, &style);
- D2TK_BASE_TABLE(row, 1, M, tab)
+ D2TK_BASE_TABLE(row, 1, M, D2TK_FLAG_TABLE_REL, tab)
{
const unsigned k = d2tk_table_get_index(tab) + voffset;
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
@@ -1519,7 +1549,7 @@ d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
case 0:
{
- D2TK_BASE_TABLE(vrect, BAR_MAX, 1, tab)
+ D2TK_BASE_TABLE(vrect, BAR_MAX, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *hrect = d2tk_table_get_rect(tab);
const unsigned b = d2tk_table_get_index(tab);
@@ -1545,6 +1575,10 @@ d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
_render_c_seq(base, vrect);
} break;
+ case BAR_TABLE_ABS:
+ {
+ _render_c_table_abs(base, vrect);
+ } break;
case BAR_SCROLL:
{
_render_c_scroll(base, vrect);
diff --git a/subprojects/d2tk/src/base.c b/subprojects/d2tk/src/base.c
index 3c37398..496e459 100644
--- a/subprojects/d2tk/src/base.c
+++ b/subprojects/d2tk/src/base.c
@@ -322,19 +322,37 @@ _d2tk_base_get_atom(d2tk_base_t *base, d2tk_id_t id, d2tk_atom_type_t type)
D2TK_API d2tk_table_t *
d2tk_table_begin(const d2tk_rect_t *rect, unsigned N, unsigned M,
- d2tk_table_t *tab)
+ d2tk_flag_t flag, d2tk_table_t *tab)
{
+ unsigned w;
+ unsigned h;
+
tab->x = 0;
tab->y = 0;
- tab->N = N;
- tab->NM = N*M;
tab->k = 0;
tab->x0 = rect->x;
+ if(flag & D2TK_FLAG_TABLE_REL)
+ {
+ w = rect->w / N;
+ h = rect->h / M;
+ }
+ else
+ {
+ w = N;
+ h = M;
+
+ N = rect->w / N;
+ M = rect->h / M;
+ }
+
+ tab->N = N;
+ tab->NM = N*M;
+
tab->rect.x = rect->x;
tab->rect.y = rect->y;
- tab->rect.w = rect->w / N;
- tab->rect.h = rect->h / M;
+ tab->rect.w = w;
+ tab->rect.h = h;
return tab;
}
@@ -394,19 +412,29 @@ D2TK_API d2tk_frame_t *
d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
ssize_t lbl_len, const char *lbl, d2tk_frame_t *frm)
{
+ const bool has_lbl = lbl_len && lbl;
+
const d2tk_style_t *style = d2tk_base_get_style(base);
d2tk_core_t *core = base->core;
const d2tk_coord_t h = 17; //FIXME
+ if(has_lbl && (lbl_len == -1) ) // zero-terminated string
+ {
+ lbl_len = strlen(lbl);
+ }
+
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { lbl, lbl_len },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
+
d2tk_rect_shrink(&frm->rect, rect, 2*style->padding);
frm->rect.y += h;
frm->rect.h -= h;
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- lbl, lbl_len,
- NULL);
-
D2TK_CORE_WIDGET(core, hash, widget)
{
d2tk_rect_t bnd_outer;
@@ -417,11 +445,6 @@ d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
if(lbl)
{
- if(lbl_len == -1) // zero terminated string
- {
- lbl_len = strlen(lbl);
- }
-
bnd_inner.h = h;
d2tk_core_begin_path(core);
@@ -1155,13 +1178,16 @@ _d2tk_draw_scrollbar(d2tk_core_t *core, d2tk_state_t hstate, d2tk_state_t vstate
const d2tk_rect_t *hbar, const d2tk_rect_t *vbar, const d2tk_style_t *style,
d2tk_flag_t flags)
{
- const uint64_t hash = d2tk_hash_foreach(&hstate, sizeof(d2tk_state_t),
- &vstate, sizeof(d2tk_state_t),
- hbar, sizeof(d2tk_rect_t),
- vbar, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &flags, sizeof(d2tk_flag_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &hstate, sizeof(d2tk_state_t) },
+ { &vstate, sizeof(d2tk_state_t) },
+ { hbar, sizeof(d2tk_rect_t) },
+ { vbar, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &flags, sizeof(d2tk_flag_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1409,11 +1435,14 @@ static void
_d2tk_draw_pane(d2tk_core_t *core, d2tk_state_t state, const d2tk_rect_t *sub,
const d2tk_style_t *style, d2tk_flag_t flags)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- sub, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &flags, sizeof(d2tk_flag_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { sub, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &flags, sizeof(d2tk_flag_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1619,9 +1648,12 @@ d2tk_base_cursor(d2tk_base_t *base, const d2tk_rect_t *rect)
d2tk_core_t *core = base->core;
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(rect),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(rect) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1856,9 +1888,12 @@ d2tk_base_image(d2tk_base_t *base, ssize_t path_len, const char *path,
path_len = strlen(path);
}
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- (path ? path : NULL), (path ? path_len : 0),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { (path ? path : NULL), (path ? path_len : 0) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1880,12 +1915,15 @@ d2tk_base_bitmap(d2tk_base_t *base, uint32_t w, uint32_t h, uint32_t stride,
const uint32_t *argb, uint64_t rev, const d2tk_rect_t *rect,
d2tk_align_t align)
{
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- &w, sizeof(uint32_t),
- &h, sizeof(uint32_t),
- &stride, sizeof(uint32_t),
- &rev, sizeof(uint64_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { &w, sizeof(uint32_t) },
+ { &h, sizeof(uint32_t) },
+ { &stride, sizeof(uint32_t) },
+ { &rev, sizeof(uint64_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1903,9 +1941,12 @@ D2TK_API void
d2tk_base_custom(d2tk_base_t *base, uint32_t size, const void *data,
const d2tk_rect_t *rect, d2tk_core_custom_t custom)
{
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- data, size, //FIXME
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) } ,
+ { data, size }, //FIXME
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1923,11 +1964,14 @@ static inline void
_d2tk_base_draw_meter(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_state_t state, int32_t value, const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &value, sizeof(int32_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &value, sizeof(int32_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2132,13 +2176,16 @@ _d2tk_base_draw_combo(d2tk_core_t *core, ssize_t nitms, const char **itms,
const d2tk_rect_t *rect, d2tk_state_t state, int32_t value,
const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &value, sizeof(int32_t),
- &nitms, sizeof(ssize_t),
- itms, sizeof(const char **), //FIXME we should actually cache the labels
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &value, sizeof(int32_t) },
+ { &nitms, sizeof(ssize_t) },
+ { itms, sizeof(const char **) }, //FIXME we should actually cache the labels
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2360,12 +2407,15 @@ _d2tk_base_draw_text_field(d2tk_core_t *core, d2tk_state_t state,
const d2tk_rect_t *rect, const d2tk_style_t *style, char *value,
d2tk_align_t align)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &align, sizeof(d2tk_align_t),
- value, -1,
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &align, sizeof(d2tk_align_t) },
+ { value, strlen(value) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2545,27 +2595,32 @@ D2TK_API d2tk_state_t
d2tk_base_label(d2tk_base_t *base, ssize_t lbl_len, const char *lbl,
float mul, const d2tk_rect_t *rect, d2tk_align_t align)
{
+ const bool has_lbl = lbl_len && lbl;
+
+ if(has_lbl && (lbl_len == -1) ) // zero terminated string
+ {
+ lbl_len = strlen(lbl);
+ }
+
const d2tk_style_t *style = d2tk_base_get_style(base);
- d2tk_core_t *core = base->core;
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { lbl, lbl_len },
+ { &mul, sizeof(float) },
+ { &align, sizeof(d2tk_align_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- lbl, lbl_len,
- &mul, sizeof(float),
- &align, sizeof(d2tk_align_t),
- NULL);
+ d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
{
d2tk_rect_t bnd;
d2tk_rect_shrink(&bnd, rect, style->padding);
- if(lbl_len == -1) // zero terminated string
- {
- lbl_len = strlen(lbl);
- }
-
const d2tk_triple_t triple = D2TK_TRIPLE_NONE;
const size_t ref = d2tk_core_bbox_push(core, true, rect);
@@ -2614,11 +2669,14 @@ d2tk_base_dial_bool(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
const d2tk_style_t *style = d2tk_base_get_style(base);
d2tk_core_t *core = base->core;
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- value, sizeof(bool),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { value, sizeof(bool) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2684,11 +2742,14 @@ static inline void
_d2tk_base_draw_dial(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_state_t state, float rel, const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &rel, sizeof(float),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &rel, sizeof(float) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -3079,11 +3140,14 @@ _d2tk_flowmatrix_connect(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
d2tk_base_get_mouse_pos(base, &dst.x, &dst.y);
}
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- src_pos, sizeof(d2tk_pos_t),
- dst_pos ? dst_pos : &dst, sizeof(d2tk_pos_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { src_pos, sizeof(d2tk_pos_t) },
+ { dst_pos ? dst_pos : &dst, sizeof(d2tk_pos_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
@@ -3322,11 +3386,14 @@ d2tk_flowmatrix_node_begin(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- pos, sizeof(d2tk_pos_t),
- node, sizeof(d2tk_flowmatrix_node_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { pos, sizeof(d2tk_pos_t) },
+ { node, sizeof(d2tk_flowmatrix_node_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -3475,15 +3542,18 @@ d2tk_flowmatrix_arc_begin(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- &N, sizeof(unsigned),
- &M, sizeof(unsigned),
- src, sizeof(d2tk_pos_t),
- dst, sizeof(d2tk_pos_t),
- pos, sizeof(d2tk_pos_t),
- arc, sizeof(d2tk_flowmatrix_arc_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { &N, sizeof(unsigned) },
+ { &M, sizeof(unsigned) },
+ { src, sizeof(d2tk_pos_t) },
+ { dst, sizeof(d2tk_pos_t) },
+ { pos, sizeof(d2tk_pos_t) },
+ { arc, sizeof(d2tk_flowmatrix_arc_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
diff --git a/subprojects/d2tk/src/mum.c b/subprojects/d2tk/src/mum.c
index 146ea3c..49825a3 100644
--- a/subprojects/d2tk/src/mum.c
+++ b/subprojects/d2tk/src/mum.c
@@ -25,13 +25,6 @@
#define SEED 12345
__attribute__((always_inline))
-static inline size_t
-_len(const void *key, ssize_t len)
-{
- return (len == -1) ? strlen((const char *)key) : (size_t)len;
-}
-
-__attribute__((always_inline))
static inline uint64_t
_d2tk_hash(uint64_t hash, const void *key, size_t len)
{
@@ -41,8 +34,6 @@ _d2tk_hash(uint64_t hash, const void *key, size_t len)
D2TK_API uint64_t
d2tk_hash(const void *key, ssize_t len)
{
- len = _len(key, len);
-
return mum_hash(key, len, SEED);
}
@@ -52,15 +43,13 @@ d2tk_hash_foreach(const void *key, ssize_t len, ...)
va_list args;
uint64_t hash = mum_hash_init(SEED);
- len = _len(key, len); //FIXME remove
hash = _d2tk_hash(hash, key, len);
va_start(args, len);
while( (key = va_arg(args, const void *)) )
{
- len = _len(key, va_arg(args, int)); //FIXME remove
- hash = _d2tk_hash(hash, key, len);
+ hash = _d2tk_hash(hash, key, va_arg(args, size_t));
}
va_end(args);
diff --git a/subprojects/d2tk/test/base.c b/subprojects/d2tk/test/base.c
index f8701bf..6145113 100644
--- a/subprojects/d2tk/test/base.c
+++ b/subprojects/d2tk/test/base.c
@@ -49,7 +49,7 @@ _expose_hot(d2tk_base_t *base, const d2tk_rect_t *rect, unsigned n, unsigned p)
};
#undef hot_over
- D2TK_BASE_TABLE(rect, n, 1, tab)
+ D2TK_BASE_TABLE(rect, n, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -164,7 +164,7 @@ _expose_mouse_fwd_focus(d2tk_base_t *base, const d2tk_rect_t *rect, unsigned n,
#undef focus_up
#undef focus_down
- D2TK_BASE_TABLE(rect, n, 1, tab)
+ D2TK_BASE_TABLE(rect, n, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -292,7 +292,7 @@ _expose_mouse_bwd_focus(d2tk_base_t *base, const d2tk_rect_t *rect, unsigned n,
#undef focus_up
#undef focus_down
- D2TK_BASE_TABLE(rect, n, 1, tab)
+ D2TK_BASE_TABLE(rect, n, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -409,7 +409,7 @@ _expose_key_fwd_focus(d2tk_base_t *base, const d2tk_rect_t *rect, unsigned n,
};
#undef invar
- D2TK_BASE_TABLE(rect, n, 1, tab)
+ D2TK_BASE_TABLE(rect, n, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -515,7 +515,7 @@ _expose_key_bwd_focus(d2tk_base_t *base, const d2tk_rect_t *rect, unsigned n,
};
#undef invar
- D2TK_BASE_TABLE(rect, n, 1, tab)
+ D2TK_BASE_TABLE(rect, n, 1, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -710,7 +710,44 @@ _test_get_set()
}
static void
-_test_table()
+_test_state_dump()
+{
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_NONE),
+ "................") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_DOWN),
+ "...............1") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_UP),
+ "..............1.") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_ACTIVE),
+ ".............1..") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_HOT),
+ "............1...") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_FOCUS),
+ "...........1....") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_FOCUS_IN),
+ "..........1.....") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_FOCUS_OUT),
+ ".........1......") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_SCROLL_DOWN),
+ "........1.......") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_SCROLL_UP),
+ ".......1........") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_SCROLL_LEFT),
+ "......1.........") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_SCROLL_RIGHT),
+ ".....1..........") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_MOTION),
+ "....1...........") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_CHANGED),
+ "...1............") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_ENTER),
+ "..1.............") == 0);
+ assert(strcmp(d2tk_state_dump(D2TK_STATE_OVER),
+ ".1..............") == 0);
+}
+
+static void
+_test_table_rel()
{
#define N 12
#define M 8
@@ -722,7 +759,7 @@ _test_table()
const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
assert(base);
- D2TK_BASE_TABLE(&rect, N, M, tab)
+ D2TK_BASE_TABLE(&rect, N, M, D2TK_FLAG_TABLE_REL, tab)
{
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const unsigned k = d2tk_table_get_index(tab);
@@ -743,6 +780,39 @@ _test_table()
}
static void
+_test_table_abs()
+{
+#define N 12
+#define M 8
+ d2tk_mock_ctx_t ctx = {
+ .check = NULL
+ };
+
+ d2tk_base_t *base = d2tk_base_new(&d2tk_mock_driver_lazy, &ctx);
+ const d2tk_rect_t rect = D2TK_RECT(0, 0, DIM_W, DIM_H);
+ assert(base);
+
+ D2TK_BASE_TABLE(&rect, N, M, D2TK_FLAG_TABLE_ABS, tab)
+ {
+ const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
+ const int k = d2tk_table_get_index(tab);
+ const int x = d2tk_table_get_index_x(tab);
+ const int y = d2tk_table_get_index_y(tab);
+
+ assert(bnd);
+ assert(bnd->x == x*N);
+ assert(bnd->y == y*M);
+ assert(bnd->w == N);
+ assert(bnd->h == M);
+ assert(y*(DIM_W/N) + x == k);
+ }
+
+ d2tk_base_free(base);
+#undef M
+#undef N
+}
+
+static void
_test_frame()
{
d2tk_mock_ctx_t ctx = {
@@ -1838,7 +1908,9 @@ main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
_test_key_fwd_focus();
_test_key_bwd_focus();
_test_get_set();
- _test_table();
+ _test_state_dump();
+ _test_table_rel();
+ _test_table_abs();
_test_frame();
_test_layout_relative_x();
_test_layout_relative_y();
diff --git a/subprojects/d2tk/test/core.c b/subprojects/d2tk/test/core.c
index 76c7a3f..5f77aea 100644
--- a/subprojects/d2tk/test/core.c
+++ b/subprojects/d2tk/test/core.c
@@ -27,25 +27,31 @@
static void
_test_hash()
{
+ const uint32_t bar = 12;
const char *foo = "barbarbarbar";
- const uint64_t hash1 = d2tk_hash(foo, -1);
+ const uint64_t hash1 = d2tk_hash(&bar, sizeof(bar));
const uint64_t hash2 = d2tk_hash(foo, strlen(foo));
- assert(hash1 == hash2);
+ assert(hash1 != hash2);
}
static void
_test_hash_foreach()
{
- const char *foo = "barbarbarbar";
- const char *bar = "foofoofoofoo";
+ const uint32_t bar = 12;
+ const char *foo = "foofoofoofoo";
+
+ const d2tk_hash_dict_t dict [] = {
+ { foo, strlen(foo) },
+ { &bar, sizeof(bar) },
+ { NULL, 0 }
+ };
+
+ const uint64_t hash1 = d2tk_hash_dict(dict);
- const uint64_t hash1 = d2tk_hash_foreach(foo, -1,
- bar, -1,
- NULL);
const uint64_t hash2 = d2tk_hash_foreach(foo, strlen(foo),
- bar, strlen(bar),
+ &bar, sizeof(bar),
NULL);
assert(hash1 == hash2);