aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-07-13 21:22:58 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-07-13 21:22:58 +0200
commit30b7a4919ae0f1bb8fab4b8c2c59735c4e9906ef (patch)
treeff747d68bde378d6408399f36d65c3e099e52bff
parent5161c75c5d3af968b5f5292cef282f10993db94d (diff)
parent11bac5914fa6b90c1f6cbc6cc37830c586ef14ad (diff)
downloadsynthpod-30b7a4919ae0f1bb8fab4b8c2c59735c4e9906ef.tar.xz
Merge commit '11bac5914fa6b90c1f6cbc6cc37830c586ef14ad'
-rw-r--r--subprojects/d2tk/VERSION2
-rw-r--r--subprojects/d2tk/d2tk/base.h25
-rw-r--r--subprojects/d2tk/example/example.c96
-rw-r--r--subprojects/d2tk/meson.build1
-rw-r--r--subprojects/d2tk/src/backend_cairo.c15
-rw-r--r--subprojects/d2tk/src/backend_nanovg.c5
-rw-r--r--subprojects/d2tk/src/base_bar.c2
-rw-r--r--subprojects/d2tk/src/base_spinner.c171
-rw-r--r--subprojects/d2tk/src/base_wave.c146
-rw-r--r--subprojects/d2tk/src/frontend_fbdev.c13
10 files changed, 433 insertions, 43 deletions
diff --git a/subprojects/d2tk/VERSION b/subprojects/d2tk/VERSION
index 810aa9d1..735baec8 100644
--- a/subprojects/d2tk/VERSION
+++ b/subprojects/d2tk/VERSION
@@ -1 +1 @@
-0.1.1069
+0.1.1089
diff --git a/subprojects/d2tk/d2tk/base.h b/subprojects/d2tk/d2tk/base.h
index 4e4238cc..0926b6d1 100644
--- a/subprojects/d2tk/d2tk/base.h
+++ b/subprojects/d2tk/d2tk/base.h
@@ -567,8 +567,15 @@ d2tk_base_dial_double(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
d2tk_state_is_changed(d2tk_base_dial_double(__VA_ARGS__))
D2TK_API d2tk_state_t
+d2tk_base_spinner_bool(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ ssize_t lbl_len, const char *lbl, bool *value);
+
+#define d2tk_base_spinner_bool_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_spinner_bool(__VA_ARGS__))
+
+D2TK_API d2tk_state_t
d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
- int32_t min, int32_t *value, int32_t max);
+ ssize_t lbl_len, const char *lbl, int32_t min, int32_t *value, int32_t max);
#define d2tk_base_spinner_int32_is_changed(...) \
d2tk_state_is_changed(d2tk_base_spinner_int32(__VA_ARGS__))
@@ -582,18 +589,32 @@ d2tk_base_bar_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
D2TK_API d2tk_state_t
d2tk_base_spinner_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
- float min, float *value, float max);
+ ssize_t lbl_len, const char *lbl, float min, float *value, float max);
#define d2tk_base_spinner_float_is_changed(...) \
d2tk_state_is_changed(d2tk_base_spinner_float(__VA_ARGS__))
D2TK_API d2tk_state_t
+d2tk_base_spinner_wave_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ ssize_t lbl_len, const char *lbl, float min, const float *value, int32_t nelem, float max);
+
+#define d2tk_base_spinner_wave_float_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_spinner_wave_float(__VA_ARGS__))
+
+D2TK_API d2tk_state_t
d2tk_base_bar_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
float min, float *value, float max);
#define d2tk_base_bar_float_is_changed(...) \
d2tk_state_is_changed(d2tk_base_bar_float(__VA_ARGS__))
+D2TK_API d2tk_state_t
+d2tk_base_wave_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ float min, const float *value, int32_t nelem, float max);
+
+#define d2tk_base_wave_float_is_changed(...) \
+ d2tk_state_is_changed(d2tk_base_wave_float(__VA_ARGS__))
+
D2TK_API d2tk_flowmatrix_t *
d2tk_flowmatrix_begin(d2tk_base_t *base, const d2tk_rect_t *rect, d2tk_id_t id,
d2tk_flowmatrix_t *flowmatrix);
diff --git a/subprojects/d2tk/example/example.c b/subprojects/d2tk/example/example.c
index ce80f48a..a0294696 100644
--- a/subprojects/d2tk/example/example.c
+++ b/subprojects/d2tk/example/example.c
@@ -40,6 +40,7 @@ union _val_t {
typedef enum _bar_t {
BAR_MIX,
BAR_SPINNER,
+ BAR_WAVE,
BAR_SEQ,
BAR_TABLE_ABS,
BAR_SCROLL,
@@ -62,10 +63,11 @@ typedef enum _bar_t {
BAR_MAX
} bar_t;
-static bar_t bar = BAR_PTY;
+static bar_t bar = BAR_MIX;
static const char *bar_lbl [BAR_MAX] = {
[BAR_MIX] = "Mix of many",
[BAR_SPINNER] = "Spinner",
+ [BAR_WAVE] = "Wave",
[BAR_SEQ] = "Sequencer",
[BAR_TABLE_ABS] = "Table Abs",
[BAR_SCROLL] = "Scrollbar",
@@ -252,9 +254,10 @@ _render_c_mix(d2tk_base_t *base, const d2tk_rect_t *rect)
static inline void
_render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
{
-#define N 8
+#define N 6
#define M 24
static union {
+ bool b32;
int32_t i32;
float f32;
} val [N*M];
@@ -265,36 +268,59 @@ _render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
const unsigned k = d2tk_table_get_index(tab);
const d2tk_id_t id = D2TK_ID_IDX(k);
- switch(k % 4)
+ char lbl [32];
+ const size_t lbl_len = snprintf(lbl, sizeof(lbl), "Spinner/%02X", k);
+
+ switch(k % N)
{
case 0:
{
- if(d2tk_base_spinner_int32_is_changed(base, id, trect, 0, &val[k].i32, 99))
+ if(d2tk_base_spinner_int32_is_changed(base, id, trect, lbl_len, lbl,
+ 0, &val[k].i32, 99))
{
fprintf(stdout, "spinner %016"PRIx64" %"PRIi32"\n", id, val[k].i32);
}
} break;
case 1:
{
- if(d2tk_base_spinner_float_is_changed(base, id, trect, -1.f, &val[k].f32, 0.f))
+ if(d2tk_base_spinner_float_is_changed(base, id, trect, lbl_len, lbl,
+ -1.f, &val[k].f32, 0.f))
{
fprintf(stdout, "spinner %016"PRIx64" %f\n", id, val[k].f32);
}
} break;
case 2:
{
- if(d2tk_base_spinner_int32_is_changed(base, id, trect, -99, &val[k].i32, 33))
+ if(d2tk_base_spinner_int32_is_changed(base, id, trect, lbl_len, lbl,
+ -99, &val[k].i32, 33))
{
fprintf(stdout, "spinner %016"PRIx64" %"PRIi32"\n", id, val[k].i32);
}
} break;
case 3:
{
- if(d2tk_base_spinner_float_is_changed(base, id, trect, -0.5f, &val[k].f32, 1.f))
+ if(d2tk_base_spinner_float_is_changed(base, id, trect, 0, NULL,
+ -0.5f, &val[k].f32, 1.f))
{
fprintf(stdout, "spinner %016"PRIx64" %f\n", id, val[k].f32);
}
} break;
+ case 4:
+ {
+ if(d2tk_base_spinner_wave_float_is_changed(base, id, trect, lbl_len, lbl,
+ -0.5f, (const float *)val, N*M, 1.f))
+ {
+ fprintf(stdout, "spinner %016"PRIx64" %f\n", id, val[k].f32);
+ }
+ } break;
+ case 5:
+ {
+ if(d2tk_base_spinner_bool_is_changed(base, id, trect, lbl_len, lbl,
+ &val[k].b32))
+ {
+ fprintf(stdout, "spinner %016"PRIx64" %s\n", id, val[k].b32 ? "true" : "false");
+ }
+ } break;
}
}
#undef N
@@ -302,6 +328,58 @@ _render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
}
static inline void
+_render_c_wave(d2tk_base_t *base, const d2tk_rect_t *rect)
+{
+#define N 18
+#define M 8192
+ static const float value1 [N] = {
+ 0.2f, 0.1f,
+ 0.3f, 0.2f,
+ 0.4f, 0.3f,
+ 0.5f, 0.4f,
+ 0.6f, 0.5f,
+ 0.7f, 0.6f,
+ 0.8f, 0.7f,
+ 0.9f, 0.8f,
+ 1.0f, 0.9f
+ };
+ static float value2 [M];
+ static bool init2 = false;
+
+ if(!init2)
+ {
+ for(unsigned i = 0; i < M; i++)
+ {
+ value2[i] = sinf(2*M_PI/M*i);
+ }
+
+ init2 = true;
+ }
+
+ const d2tk_coord_t vfrac [2] = { 1, 1 };
+ D2TK_BASE_LAYOUT(rect, 2, vfrac, D2TK_FLAG_LAYOUT_Y_REL, vlay)
+ {
+ const d2tk_rect_t *vrect = d2tk_layout_get_rect(vlay);
+ const unsigned k = d2tk_layout_get_index(vlay);
+
+ switch(k)
+ {
+ case 0:
+ {
+ d2tk_base_wave_float(base, D2TK_ID, vrect, 0.f, value1, N, 1.f);
+ } break;
+ case 1:
+ {
+ d2tk_base_wave_float(base, D2TK_ID, vrect, -1.f, value2, M, 1.f);
+ } break;
+ }
+ }
+
+#undef M
+#undef N
+}
+
+static inline void
_render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
{
#define N (8*12)
@@ -1212,6 +1290,10 @@ d2tk_example_run(d2tk_base_t *base, d2tk_coord_t w, d2tk_coord_t h)
{
_render_c_spinner(base, vrect);
} break;
+ case BAR_WAVE:
+ {
+ _render_c_wave(base, vrect);
+ } break;
case BAR_SEQ:
{
_render_c_seq(base, vrect);
diff --git a/subprojects/d2tk/meson.build b/subprojects/d2tk/meson.build
index e13ad992..33e49c56 100644
--- a/subprojects/d2tk/meson.build
+++ b/subprojects/d2tk/meson.build
@@ -143,6 +143,7 @@ lib_srcs = [
join_paths('src', 'base_dial.c'),
join_paths('src', 'base_spinner.c'),
join_paths('src', 'base_bar.c'),
+ join_paths('src', 'base_wave.c'),
join_paths('src', 'base_flowmatrix.c')
]
diff --git a/subprojects/d2tk/src/backend_cairo.c b/subprojects/d2tk/src/backend_cairo.c
index 268f2f23..af002ba8 100644
--- a/subprojects/d2tk/src/backend_cairo.c
+++ b/subprojects/d2tk/src/backend_cairo.c
@@ -316,8 +316,9 @@ _d2tk_cairo_surf_draw(cairo_t *ctx, cairo_surface_t *surf, d2tk_coord_t xo,
if(w > rect->w)
{
- scale = (float)rect->w / w;
- h *= scale;
+ const float scale_t = (float)rect->w / w;
+ scale *= scale_t;
+ h *= scale_t;
w = rect->w;
}
@@ -729,15 +730,17 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
// bitswap and premultiply pixel data
for(unsigned i = 0; i < W*H*sizeof(uint32_t); i += sizeof(uint32_t))
{
+ // get alpha channel
const uint8_t a = pixels[i+3];
+
+ // premultiply with alpha channel
const uint8_t r = ( (uint16_t)pixels[i+0] * a ) >> 8;
const uint8_t g = ( (uint16_t)pixels[i+1] * a ) >> 8;
const uint8_t b = ( (uint16_t)pixels[i+2] * a ) >> 8;
- pixels[i+0] = b;
- pixels[i+1] = g;
- pixels[i+2] = r;
- pixels[i+3] = a;
+ // merge and byteswap to correct endianness
+ uint32_t *pix = (uint32_t *)&pixels[i];
+ *pix = (a << 24) | (r << 16) | (g << 8) | b;
}
cairo_surface_t *surf = cairo_image_surface_create_for_data(pixels,
diff --git a/subprojects/d2tk/src/backend_nanovg.c b/subprojects/d2tk/src/backend_nanovg.c
index e74b33d2..c804b5c7 100644
--- a/subprojects/d2tk/src/backend_nanovg.c
+++ b/subprojects/d2tk/src/backend_nanovg.c
@@ -382,8 +382,9 @@ _d2tk_nanovg_surf_draw(NVGcontext *ctx, int img, d2tk_coord_t xo,
if(w > rect->w)
{
- scale = (float)rect->w / w;
- h *= scale;
+ const float scale_t = (float)rect->w / w;
+ scale *= scale_t;
+ h *= scale_t;
w = rect->w;
}
diff --git a/subprojects/d2tk/src/base_bar.c b/subprojects/d2tk/src/base_bar.c
index d72d341c..e5b56675 100644
--- a/subprojects/d2tk/src/base_bar.c
+++ b/subprojects/d2tk/src/base_bar.c
@@ -92,13 +92,11 @@ _d2tk_base_draw_bar(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_core_begin_path(core);
d2tk_core_rect(core, &bnd_inner_inactive);
d2tk_core_color(core, style->fill_color[triple_inactive]);
- d2tk_core_stroke_width(core, 0);
d2tk_core_fill(core);
d2tk_core_begin_path(core);
d2tk_core_rect(core, &bnd_inner_active);
d2tk_core_color(core, style->fill_color[triple_active]);
- d2tk_core_stroke_width(core, 0);
d2tk_core_fill(core);
d2tk_core_begin_path(core);
diff --git a/subprojects/d2tk/src/base_spinner.c b/subprojects/d2tk/src/base_spinner.c
index 12c970a6..89ce31f7 100644
--- a/subprojects/d2tk/src/base_spinner.c
+++ b/subprojects/d2tk/src/base_spinner.c
@@ -201,7 +201,7 @@ _d2tk_base_spinner_inc(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect)
D2TK_API d2tk_state_t
d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
- int32_t min, int32_t *value, int32_t max)
+ ssize_t lbl_len, const char *lbl, int32_t min, int32_t *value, int32_t max)
{
d2tk_state_t state = D2TK_STATE_NONE;
const d2tk_style_t *style = d2tk_base_get_style(base);
@@ -247,14 +247,43 @@ d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect
d2tk_style_t style = *old_style;
style.font_face = FONT_CODE_MEDIUM;
- d2tk_base_set_style(base, &style);
+ const bool grow = d2tk_state_is_focused(substate)
+ || d2tk_state_is_hot(substate);
- char lbl [16];
- const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "%+"PRIi32, *value);
- d2tk_base_label(base, lbl_len, lbl, 0.75f, &bnd,
- D2TK_ALIGN_MIDDLE | D2TK_ALIGN_RIGHT);
+ if(grow)
+ {
+ d2tk_base_set_style(base, &style);
+
+ char lbl2 [16];
+ const ssize_t lbl2_len = snprintf(lbl2, sizeof(lbl2), "%+"PRIi32, *value);
+ d2tk_base_label(base, lbl2_len, lbl2, 0.66f, &bnd,
+ D2TK_ALIGN_BOTTOM | D2TK_ALIGN_RIGHT);
+
+ d2tk_base_set_style(base, old_style);
+
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.33f, &bnd,
+ D2TK_ALIGN_TOP | D2TK_ALIGN_LEFT);
+ }
+ }
+ else
+ {
+ d2tk_base_set_style(base, &style);
+
+ char lbl2 [16];
+ const ssize_t lbl2_len = snprintf(lbl2, sizeof(lbl2), "%+"PRIi32, *value);
+ d2tk_base_label(base, lbl2_len, lbl2, 0.33f, &bnd,
+ D2TK_ALIGN_BOTTOM | D2TK_ALIGN_RIGHT);
- d2tk_base_set_style(base, old_style);
+ d2tk_base_set_style(base, old_style);
+
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.66f, &bnd,
+ D2TK_ALIGN_TOP| D2TK_ALIGN_LEFT);
+ }
+ }
} break;
case 2:
{
@@ -281,7 +310,7 @@ d2tk_base_spinner_int32(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect
D2TK_API d2tk_state_t
d2tk_base_spinner_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
- float min, float *value, float max)
+ ssize_t lbl_len, const char *lbl, float min, float *value, float max)
{
d2tk_state_t state = D2TK_STATE_NONE;
const d2tk_style_t *style = d2tk_base_get_style(base);
@@ -327,14 +356,43 @@ d2tk_base_spinner_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect
d2tk_style_t style = *old_style;
style.font_face = FONT_CODE_MEDIUM;
- d2tk_base_set_style(base, &style);
+ const bool grow = d2tk_state_is_focused(substate)
+ || d2tk_state_is_hot(substate);
+
+ if(grow)
+ {
+ d2tk_base_set_style(base, &style);
+
+ char lbl2 [16];
+ const ssize_t lbl2_len = snprintf(lbl2, sizeof(lbl2), "%+.4f", *value);
+ d2tk_base_label(base, lbl2_len, lbl2, 0.66f, &bnd,
+ D2TK_ALIGN_BOTTOM | D2TK_ALIGN_RIGHT);
+
+ d2tk_base_set_style(base, old_style);
+
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.33f, &bnd,
+ D2TK_ALIGN_TOP | D2TK_ALIGN_LEFT);
+ }
+ }
+ else
+ {
+ d2tk_base_set_style(base, &style);
+
+ char lbl2 [16];
+ const ssize_t lbl2_len = snprintf(lbl2, sizeof(lbl2), "%+.4f", *value);
+ d2tk_base_label(base, lbl2_len, lbl2, 0.33f, &bnd,
+ D2TK_ALIGN_BOTTOM | D2TK_ALIGN_RIGHT);
- char lbl [16];
- const ssize_t lbl_len = snprintf(lbl, sizeof(lbl), "%+.4f", *value);
- d2tk_base_label(base, lbl_len, lbl, 0.75f, &bnd,
- D2TK_ALIGN_MIDDLE | D2TK_ALIGN_RIGHT);
+ d2tk_base_set_style(base, old_style);
- d2tk_base_set_style(base, old_style);
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.66f, &bnd,
+ D2TK_ALIGN_TOP | D2TK_ALIGN_LEFT);
+ }
+ }
} break;
case 2:
{
@@ -358,3 +416,88 @@ d2tk_base_spinner_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect
return state;
}
+
+D2TK_API d2tk_state_t
+d2tk_base_spinner_bool(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ ssize_t lbl_len, const char *lbl, bool *value)
+{
+ d2tk_state_t state = D2TK_STATE_NONE;
+ const d2tk_style_t *style = d2tk_base_get_style(base);
+ const d2tk_coord_t h2 = rect->h/2 + style->padding*3;
+ const d2tk_coord_t fract [3] = { h2, 0, rect->h };
+ D2TK_BASE_LAYOUT(rect, 3, fract, D2TK_FLAG_LAYOUT_X_ABS, lay)
+ {
+ const unsigned k = d2tk_layout_get_index(lay);
+ const d2tk_rect_t *lrect= d2tk_layout_get_rect(lay);
+ const d2tk_id_t itrid = D2TK_ID_IDX(k);
+ const d2tk_id_t subid = (itrid << 32) | id;
+
+ switch(k)
+ {
+ case 1:
+ {
+ d2tk_rect_t bnd;
+ d2tk_rect_shrink(&bnd, lrect, style->padding*5);
+
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.66f, &bnd,
+ D2TK_ALIGN_TOP | D2TK_ALIGN_LEFT);
+ }
+ } break;
+ case 2:
+ {
+ state = d2tk_base_dial_bool(base, subid, lrect, value);
+ } break;
+ }
+ }
+
+ return state;
+}
+
+D2TK_API d2tk_state_t
+d2tk_base_spinner_wave_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ ssize_t lbl_len, const char *lbl, float min, const float *value, int32_t nelem, float max)
+{
+ d2tk_state_t state = D2TK_STATE_NONE;
+ const d2tk_style_t *style = d2tk_base_get_style(base);
+ const d2tk_coord_t h2 = rect->h/2 + style->padding*3;
+ const d2tk_coord_t fract [3] = { h2, 0, h2 };
+ D2TK_BASE_LAYOUT(rect, 3, fract, D2TK_FLAG_LAYOUT_X_ABS, lay)
+ {
+ const unsigned k = d2tk_layout_get_index(lay);
+ const d2tk_rect_t *lrect= d2tk_layout_get_rect(lay);
+ const d2tk_id_t itrid = D2TK_ID_IDX(k);
+ const d2tk_id_t subid = (itrid << 32) | id;
+
+ switch(k)
+ {
+ case 0:
+ {
+ //FIXME decrease viewport
+ } break;
+ case 1:
+ {
+ const d2tk_state_t substate = d2tk_base_wave_float(base, subid, lrect,
+ min, value, nelem, max);
+
+ state |= substate;
+
+ d2tk_rect_t bnd;
+ d2tk_rect_shrink(&bnd, lrect, style->padding*5);
+
+ if(lbl_len && lbl)
+ {
+ d2tk_base_label(base, lbl_len, lbl, 0.66f, &bnd,
+ D2TK_ALIGN_TOP | D2TK_ALIGN_LEFT);
+ }
+ } break;
+ case 2:
+ {
+ //FIXME increase viewport
+ } break;
+ }
+ }
+
+ return state;
+}
diff --git a/subprojects/d2tk/src/base_wave.c b/subprojects/d2tk/src/base_wave.c
new file mode 100644
index 00000000..b9dddc6b
--- /dev/null
+++ b/subprojects/d2tk/src/base_wave.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2018-2019 Hanspeter Portner (dev@open-music-kontrollers.ch)
+ *
+ * This is free software: you can redistribute it and/or modify
+ * it under the terms of the Artistic License 2.0 as published by
+ * The Perl Foundation.
+ *
+ * This source is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Artistic License 2.0 for more details.
+ *
+ * You should have received a copy of the Artistic License 2.0
+ * along the source as a COPYING file. If not, obtain it from
+ * http://www.perlfoundation.org/artistic_license_2_0.
+ */
+
+#include <inttypes.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "base_internal.h"
+
+static inline void
+_d2tk_base_draw_wave(d2tk_core_t *core, const d2tk_rect_t *rect,
+ d2tk_state_t state, const d2tk_style_t *style, float min,
+ const float *value, int32_t nelem, float max)
+{
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { &state , sizeof(d2tk_state_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &min, sizeof(float) },
+ { value, sizeof(float)*nelem },
+ { &max, sizeof(float) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
+
+ D2TK_CORE_WIDGET(core, hash, widget)
+ {
+ d2tk_triple_t triple = D2TK_TRIPLE_NONE;
+ d2tk_triple_t triple_active = D2TK_TRIPLE_ACTIVE;
+ d2tk_triple_t triple_inactive = D2TK_TRIPLE_NONE;
+
+ if(d2tk_state_is_active(state))
+ {
+ triple |= D2TK_TRIPLE_ACTIVE;
+ }
+
+ if(d2tk_state_is_hot(state))
+ {
+ triple |= D2TK_TRIPLE_HOT;
+ triple_active |= D2TK_TRIPLE_HOT;
+ triple_inactive |= D2TK_TRIPLE_HOT;
+ }
+
+ if(d2tk_state_is_focused(state))
+ {
+ triple |= D2TK_TRIPLE_FOCUS;
+ triple_active |= D2TK_TRIPLE_FOCUS;
+ triple_inactive |= D2TK_TRIPLE_FOCUS;
+ }
+
+ const size_t ref = d2tk_core_bbox_push(core, true, rect);
+ const float range_1 = 1.f / (max - min);
+
+ d2tk_rect_t bnd_outer;
+ d2tk_rect_t bnd_inner;
+ d2tk_rect_shrink(&bnd_outer, rect, style->padding);
+ d2tk_rect_shrink(&bnd_inner, &bnd_outer, 2*style->padding);
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rect(core, &bnd_inner);
+ d2tk_core_color(core, style->fill_color[triple_inactive]);
+ d2tk_core_fill(core);
+
+ d2tk_core_color(core, style->fill_color[triple_active]);
+
+ if(nelem > bnd_inner.w)
+ {
+ for(int32_t i = 0; i < bnd_inner.w; i++)
+ {
+ const int32_t off = i * (nelem - 1) / (bnd_inner.w - 1);
+ if(value[off] == HUGE_VAL)
+ {
+ continue;
+ }
+ const float rel = 1.f - (value[off] - min)*range_1;
+ const d2tk_rect_t point = {
+ .x = bnd_inner.x + i,
+ .y = bnd_inner.y + rel*bnd_inner.h,
+ .w = style->border_width,
+ .h = style->border_width
+ };
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rect(core, &point);
+ d2tk_core_fill(core);
+ }
+ }
+ else
+ {
+ for(int32_t off = 0; off < nelem; off++)
+ {
+ const int32_t i = off * (bnd_inner.w - 1) / (nelem - 1);
+ if(value[off] == HUGE_VAL)
+ {
+ continue;
+ }
+ const float rel = 1.f - (value[off] - min) * range_1;
+ const d2tk_rect_t point = {
+ .x = bnd_inner.x + i,
+ .y = bnd_inner.y + rel*bnd_inner.h,
+ .w = style->border_width,
+ .h = style->border_width
+ };
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rect(core, &point);
+ d2tk_core_fill(core);
+ }
+ }
+
+ d2tk_core_begin_path(core);
+ d2tk_core_rect(core, &bnd_outer);
+ d2tk_core_color(core, style->stroke_color[triple]);
+ d2tk_core_stroke_width(core, style->border_width);
+ d2tk_core_stroke(core);
+
+ d2tk_core_bbox_pop(core, ref);
+ }
+}
+
+D2TK_API d2tk_state_t
+d2tk_base_wave_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
+ float min, const float *value, int32_t nelem, float max)
+{
+ d2tk_state_t state = d2tk_base_is_active_hot(base, id, rect,
+ D2TK_FLAG_SCROLL);
+
+ _d2tk_base_draw_wave(base->core, rect, state, d2tk_base_get_style(base),
+ min, value, nelem, max);
+
+ return state;
+}
diff --git a/subprojects/d2tk/src/frontend_fbdev.c b/subprojects/d2tk/src/frontend_fbdev.c
index 9bcdf231..e237ee56 100644
--- a/subprojects/d2tk/src/frontend_fbdev.c
+++ b/subprojects/d2tk/src/frontend_fbdev.c
@@ -213,16 +213,11 @@ _d2tk_frontend_expose(d2tk_frontend_t *fbdev)
D2TK_API int
d2tk_frontend_step(d2tk_frontend_t *fbdev)
{
- while(true)
- {
- libinput_dispatch(fbdev->li);
- struct libinput_event *ev = libinput_get_event(fbdev->li);
-
- if(!ev)
- {
- break;
- }
+ libinput_dispatch(fbdev->li);
+ struct libinput_event *ev;
+ while ( ( ev = libinput_get_event(fbdev->li) ) )
+ {
switch(libinput_event_get_type(ev))
{
case LIBINPUT_EVENT_NONE: