aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-05-03 08:22:50 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-05-03 08:23:20 +0200
commit8947f95505846b3e1f1a4f05be5a363c1421f048 (patch)
treef3e4b4cf940104d809e28e5c230b2a63ff2aca5c /example
parente3723bcc634a22b85a3e526ad40bf621b8cfd974 (diff)
downloadd2tk-8947f95505846b3e1f1a4f05be5a363c1421f048.tar.xz
examples: support drag&drop in sequencer.
Diffstat (limited to 'example')
-rw-r--r--example/example.c88
1 files changed, 84 insertions, 4 deletions
diff --git a/example/example.c b/example/example.c
index b2ccc06..caaea41 100644
--- a/example/example.c
+++ b/example/example.c
@@ -229,6 +229,9 @@ _render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
#define NN (N*N)
const unsigned M = N * rect->h / rect->w;
static val_t value [N*N];
+ static bool drag = false;
+ static d2tk_pos_t from_pos;
+ static d2tk_pos_t to_pos;
d2tk_style_t style = *d2tk_base_get_default_style();
style.border_width = 1;
@@ -239,8 +242,8 @@ _render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
D2TK_BASE_TABLE(rect, N, M, tab)
{
const unsigned k = d2tk_table_get_index(tab);
- const unsigned x = d2tk_table_get_index_x(tab);
- const unsigned y = d2tk_table_get_index_y(tab);
+ const d2tk_coord_t x = d2tk_table_get_index_x(tab);
+ const d2tk_coord_t y = d2tk_table_get_index_y(tab);
const d2tk_rect_t *bnd = d2tk_table_get_rect(tab);
const d2tk_id_t id = D2TK_ID_IDX(k);
@@ -268,9 +271,86 @@ _render_c_seq(d2tk_base_t *base, const d2tk_rect_t *rect)
continue;
}
- if(d2tk_base_toggle_is_changed(base, id, bnd, &val->b))
+ bool clone = val->b;
+
+ const uint32_t col_active = style.fill_color[D2TK_TRIPLE_ACTIVE];
+
+ if(drag)
+ {
+ const d2tk_coord_t y0 = from_pos.y <= to_pos.y ? from_pos.y : to_pos.y;
+ const d2tk_coord_t y1 = from_pos.y > to_pos.y ? from_pos.y : to_pos.y;
+ const d2tk_coord_t x0 = from_pos.x <= to_pos.x ? from_pos.x : to_pos.x;
+ const d2tk_coord_t x1 = from_pos.x > to_pos.x ? from_pos.x : to_pos.x;
+
+ for(d2tk_coord_t Y = y0; Y <= y1; Y++)
+ {
+ for(d2tk_coord_t X = x0; X <= x1; X++)
+ {
+ if( (y == from_pos.y) && (x == from_pos.x) )
+ {
+ continue;
+ }
+
+ if( (y != Y) || (x != X) )
+ {
+ continue;
+ }
+
+ clone = true;
+
+ style.fill_color[D2TK_TRIPLE_ACTIVE] = 0x9f00cfff;
+ break;
+ }
+ }
+ }
+
+ const d2tk_state_t state = d2tk_base_toggle(base, id, bnd, &clone);
+
+ style.fill_color[D2TK_TRIPLE_ACTIVE] = col_active;
+
+ if(d2tk_state_is_changed(state))
+ {
+ val->b = clone;
+ }
+
+ if(d2tk_state_is_down(state))
+ {
+ drag = true;
+
+ from_pos.x = to_pos.x = x;
+ from_pos.y = to_pos.y = y;
+
+ fprintf(stdout, "toggle %016"PRIx64" DOWN\n", id);
+ }
+
+ if(drag && d2tk_state_is_over(state))
+ {
+ to_pos.x = x;
+ to_pos.y = y;
+ }
+
+ if(d2tk_state_is_up(state))
{
- fprintf(stdout, "toggle %016"PRIx64" %s\n", id, val->b ? "ON" : "OFF");
+ drag = false;
+
+ const d2tk_coord_t y0 = from_pos.y <= to_pos.y ? from_pos.y : to_pos.y;
+ const d2tk_coord_t y1 = from_pos.y > to_pos.y ? from_pos.y : to_pos.y;
+ const d2tk_coord_t x0 = from_pos.x <= to_pos.x ? from_pos.x : to_pos.x;
+ const d2tk_coord_t x1 = from_pos.x > to_pos.x ? from_pos.x : to_pos.x;
+
+ for(d2tk_coord_t Y = y0; Y <= y1; Y++)
+ {
+ const d2tk_coord_t O = N*Y;
+
+ for(d2tk_coord_t X = x0; X <= x1; X++)
+ {
+ const d2tk_coord_t K = O + X;
+
+ value[K] = *val;
+ }
+ }
+
+ fprintf(stdout, "toggle %016"PRIx64" UP\n", id);
}
}