From 22842f9debb7f7d54a7583e0facd2881c11df839 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 18 Nov 2024 01:57:10 +0100 Subject: [PATCH] Drag selection working again - not much progress --- src/canvas.h | 5 ++--- src/draggable.h | 26 +++++++++++++++----------- src/graph-manager.h | 2 +- src/midi-node.h | 22 +++++++--------------- src/node.h | 12 +----------- src/selectable.h | 2 ++ 6 files changed, 28 insertions(+), 41 deletions(-) diff --git a/src/canvas.h b/src/canvas.h index 7663b9c..d823989 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -33,8 +33,7 @@ namespace VISEQ::APP::CANVAS { EndMode2D(); } - void select_rect(){ - + void selectNodes(){ if(state->mouse_left.clicked){ state->selection = (Rectangle){0,0,0,0}; select_start = state->screen_mouse; @@ -55,7 +54,7 @@ namespace VISEQ::APP::CANVAS { virtual void update() override { camera_delta = state->mouse_delta * (-1.0f/camera.zoom); if(hovering()) drag(); - if(state->istate == InteractionState::HOVER_CANVAS || state->istate == InteractionState::DRAW_SELECTION) select_rect(); + if(state->istate == InteractionState::HOVER_CANVAS || state->istate == InteractionState::DRAW_SELECTION) selectNodes(); float wheel = GetMouseWheelMove(); if(wheel != 0){ diff --git a/src/draggable.h b/src/draggable.h index 20584b9..c4146b1 100644 --- a/src/draggable.h +++ b/src/draggable.h @@ -19,7 +19,7 @@ namespace VISEQ::BASE { bool picked_up = false; virtual bool pickedUp() { - if(clicked() && held() && state->istate == APP::InteractionState::HOVER_NODE) { + if(clicked() && held() && (state->istate == APP::InteractionState::HOVER_NODE || state->istate == APP::InteractionState::DRAG_NODE)) { picked_up = true; drag_offset = position - state->screen_mouse; } @@ -40,16 +40,20 @@ namespace VISEQ::BASE { virtual void select() override { selected = (state->keys_down.shift && selected) || CheckCollisionPointRec(position, state->selection); - /**/ - /*//std::cout << "select" << std::endl;*/ - /*if(CheckCollisionPointRec(position, state->selection)) {*/ - /* in_selection_rect = true;*/ - /*} else {*/ - /* in_selection_rect = false;*/ - /*}*/ - /*if(released() && in_selection_rect) selected = true;*/ - /*if(released() && !in_selection_rect) selected = false;*/ } - + + virtual void update() override { + if((held() && !picked_up) || (clicked() && !state->keys_down.shift)) select(); + if(entered()) state->istate = APP::InteractionState::HOVER_NODE; + if(exited()) state->istate = APP::InteractionState::HOVER_CANVAS; + if(pickedUp()){ + drag(); + state->istate = APP::InteractionState::DRAG_NODE; + } + if(released() && picked_up){ + putDown(); + state->istate = APP::InteractionState::HOVER_CANVAS; + } + } }; } diff --git a/src/graph-manager.h b/src/graph-manager.h index e076c06..2aef888 100644 --- a/src/graph-manager.h +++ b/src/graph-manager.h @@ -45,7 +45,7 @@ namespace VISEQ::GRAPH { EDGES::VEC_SPTR_Edge remove_edges; EDGES::VEC_SPTR_Edge split_edges; - VEC_SPTR_Node selected_nodes; + //VEC_SPTR_Node selected_nodes; std::map counter; diff --git a/src/midi-node.h b/src/midi-node.h index b814d63..afebd6f 100644 --- a/src/midi-node.h +++ b/src/midi-node.h @@ -87,7 +87,7 @@ namespace VISEQ::GRAPH::NODES { void interact(){ float wheel = GetMouseWheelMove(); - if(IsKeyDown(KEY_LEFT_CONTROL) && !IsKeyDown(KEY_LEFT_ALT)){ + if(state->keys_down.ctrl && !state->keys_down.alt){ switch(GraphItem::state->node_mode){ case 0:{ midi_note += wheel; @@ -108,14 +108,14 @@ namespace VISEQ::GRAPH::NODES { if(midi_pitch_bend < 0 ) midi_pitch_bend = 0; if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383; - } else if(IsKeyDown(KEY_LEFT_SHIFT) && !IsKeyDown(KEY_LEFT_ALT)) { + } else if(state->keys_down.shift && !state->keys_down.alt) { midi_velocity += wheel; if(midi_velocity < 0 ) midi_velocity = 127; if(midi_velocity > 127 ) midi_velocity = 0; - } else if(IsKeyDown(KEY_LEFT_ALT)) { + } else if(state->keys_down.alt) { switch(GraphItem::state->node_mode){ case 0:{ - float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f); + float incr = (float)wheel * (state->keys_down.shift ? 100.0f : state->keys_down.ctrl ? 1000.0f : 10.0f); midi_gate += incr; if(midi_gate < 0 ) midi_gate = 0; break;} @@ -125,7 +125,7 @@ namespace VISEQ::GRAPH::NODES { if(midi_cc_value > 127 ) midi_cc_value = 127; break;} case 2:{ - float incr = (float)wheel * (IsKeyDown(KEY_LEFT_SHIFT) ? 100.0f : IsKeyDown(KEY_LEFT_CONTROL) ? 1000.0f : 10.0f); + float incr = (float)wheel * (state->keys_down.shift ? 100.0f : state->keys_down.ctrl ? 1000.0f : 10.0f); midi_pitch_bend += incr; if(midi_pitch_bend < 0 ) midi_pitch_bend = 0; if(midi_pitch_bend > 16383 ) midi_pitch_bend = 16383; @@ -167,7 +167,7 @@ namespace VISEQ::GRAPH::NODES { break;} } if(!picked_up && !selected && !in_selection_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color); - //if(selected || picked_up || in_selection_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255}); + if(picked_up || in_selection_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255}); if(selected) DrawCircle(position.x, position.y, radius, (Color){255, 153, 187, 255}); if(distributionMode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_PINK); @@ -175,7 +175,7 @@ namespace VISEQ::GRAPH::NODES { if(selected) DrawCircleLinesV(position, radius+8, (Color){158, 255, 210, 255}); - if(IsKeyDown(KEY_LEFT_ALT)){ + if(state->keys_down.alt){ float value = 0; int offset_gate = 0; switch(mode){ @@ -212,14 +212,6 @@ namespace VISEQ::GRAPH::NODES { } } - /*Vec2Df connector = position - ((position - mouse)).norm() * (radius + RADIUS);*/ - /*float opacity = 150.0f - Clamp(position.dist(mouse), 0.0f, 150.0f);*/ - /**/ - /*if(hover_connect){*/ - /* DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, 255});*/ - /*} else {*/ - /* DrawCircle(connector.x, connector.y, 8.0f, (Color){108, 153, 187, (unsigned char)opacity});*/ - /*}*/ if(highlighted) DrawCircleLinesV(position, radius+2, (Color){255, 0, 0, 200}); DrawText(std::format("{}", id).c_str(), position.x + 20.0f, position.y + 20.0f, 10, WHITE); } diff --git a/src/node.h b/src/node.h index 15a869c..7f83d68 100644 --- a/src/node.h +++ b/src/node.h @@ -69,17 +69,7 @@ namespace VISEQ::GRAPH::NODES { } void update() override{ - if((held() && !picked_up) || (clicked() && !state->keys_down.shift)) select(); - if(entered()) state->istate = APP::InteractionState::HOVER_NODE; - if(exited()) state->istate = APP::InteractionState::HOVER_CANVAS; - if(pickedUp()){ - drag(); - state->istate = APP::InteractionState::DRAG_NODE; - } - if(released() && picked_up){ - putDown(); - state->istate = APP::InteractionState::HOVER_CANVAS; - } + BASE::Draggable::update(); int free_connectors = 0; for(auto c : connectors){ diff --git a/src/selectable.h b/src/selectable.h index 6f28cff..0acf119 100644 --- a/src/selectable.h +++ b/src/selectable.h @@ -1,6 +1,7 @@ #pragma once #include "interactable.h" +#include "vmath.h" namespace VISEQ::BASE { class Selectable : public Interactable{ @@ -13,6 +14,7 @@ namespace VISEQ::BASE { bool copied = false; bool highlighted = false; bool erase = false; + Vec2Df selection_offset; virtual bool clicked() override { return (selected || hovering()) && IsMouseButtonPressed(MOUSE_BUTTON_LEFT);