aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-07-10 23:17:46 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-07-10 23:17:46 +0200
commitea894bf871383a1a3a6e0f78e073c493e0a49fad (patch)
tree9a6962382bf3e70f99d2eb67c50f6994cc113e9d
parent9be43ce6cf0c268fa0f1f92e7169fbbc02712d6e (diff)
downloadd2tk-master.tar.xz
base: add spinner_wave_float widget.HEADmaster
-rw-r--r--VERSION2
-rw-r--r--d2tk/base.h7
-rw-r--r--example/example.c21
-rw-r--r--src/base_bar.c2
-rw-r--r--src/base_spinner.c47
-rw-r--r--src/base_wave.c57
6 files changed, 122 insertions, 14 deletions
diff --git a/VERSION b/VERSION
index 80f7abe..735baec 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.1087
+0.1.1089
diff --git a/d2tk/base.h b/d2tk/base.h
index d48090d..0926b6d 100644
--- a/d2tk/base.h
+++ b/d2tk/base.h
@@ -595,6 +595,13 @@ d2tk_base_spinner_float(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect
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);
diff --git a/example/example.c b/example/example.c
index 819239d..a029469 100644
--- a/example/example.c
+++ b/example/example.c
@@ -254,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];
@@ -270,7 +271,7 @@ _render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
char lbl [32];
const size_t lbl_len = snprintf(lbl, sizeof(lbl), "Spinner/%02X", k);
- switch(k % 4)
+ switch(k % N)
{
case 0:
{
@@ -304,6 +305,22 @@ _render_c_spinner(d2tk_base_t *base, const d2tk_rect_t *rect)
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
diff --git a/src/base_bar.c b/src/base_bar.c
index d72d341..e5b5667 100644
--- a/src/base_bar.c
+++ b/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/src/base_spinner.c b/src/base_spinner.c
index f26fd8d..89ce31f 100644
--- a/src/base_spinner.c
+++ b/src/base_spinner.c
@@ -454,3 +454,50 @@ d2tk_base_spinner_bool(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
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/src/base_wave.c b/src/base_wave.c
index 8fff009..b9dddc6 100644
--- a/src/base_wave.c
+++ b/src/base_wave.c
@@ -39,24 +39,57 @@ _d2tk_base_draw_wave(d2tk_core_t *core, const d2tk_rect_t *rect,
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_core_color(core, style->stroke_color[D2TK_TRIPLE_ACTIVE_HOT_FOCUS]);
+ 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);
- if(nelem > rect->w)
+ 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 < rect->w; i++)
+ for(int32_t i = 0; i < bnd_inner.w; i++)
{
- const int32_t off = i * (nelem - 1) / (rect->w - 1);
+ 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 = rect->x + i,
- .y = rect->y + rel*rect->h,
+ .x = bnd_inner.x + i,
+ .y = bnd_inner.y + rel*bnd_inner.h,
.w = style->border_width,
.h = style->border_width
};
@@ -70,15 +103,15 @@ _d2tk_base_draw_wave(d2tk_core_t *core, const d2tk_rect_t *rect,
{
for(int32_t off = 0; off < nelem; off++)
{
- const int32_t i = off * (rect->w - 1) / (nelem - 1);
+ 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 = rect->x + i,
- .y = rect->y + rel*rect->h,
+ .x = bnd_inner.x + i,
+ .y = bnd_inner.y + rel*bnd_inner.h,
.w = style->border_width,
.h = style->border_width
};
@@ -89,6 +122,12 @@ _d2tk_base_draw_wave(d2tk_core_t *core, const d2tk_rect_t *rect,
}
}
+ 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);
}
}