1 Commits

Author SHA1 Message Date
Sebastian 159255adda midi node design changes 2026-07-19 02:38:33 +02:00
9 changed files with 49 additions and 110 deletions
+3 -5
View File
@@ -2,7 +2,6 @@
#include "datatypes.h"
//#include "interaction-event.h"
#include "interaction-event.h"
#include "state.h"
#include "draggable.h"
#include "raylib.h"
@@ -22,14 +21,14 @@ namespace VISEQ::APP::CANVAS {
}
void Canvas::pickUp() {
std::cout << "canvas pickUp" << std::endl;
//std::cout << "canvas pickUp" << std::endl;
BASE::Draggable::pickUp();
select_start = SCREEN_MOUSE;
state->pushEvent({getPtr(), Interaction::DESELECT});
}
void Canvas::putDown() {
std::cout << "canvas putDown" << std::endl;
//std::cout << "canvas putDown" << std::endl;
BASE::Draggable::putDown();
state->pushEvent({getPtr(), Interaction::SELECT});
}
@@ -60,9 +59,8 @@ namespace VISEQ::APP::CANVAS {
if(state->mouse_right.down) {
camera.target = Vector2Add(camera.target, camera_delta);
}
if(clicked()) state->pushEvent({getPtr(), APP::Interaction::DESELECT});
if(hovering() && held() && !pickedUp()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
+1 -1
View File
@@ -38,7 +38,7 @@ namespace VISEQ::GRAPH {
void Connector::update() {
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(hovering() && held() && !pickedUp()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
if(connected) {
+8 -24
View File
@@ -9,49 +9,33 @@ namespace VISEQ::BASE {
return is_hovering && !hovering();
}
bool Draggable::clicked() {
if(hovering() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
last_tp = std::chrono::high_resolution_clock::now();
}
std::chrono::duration<double, std::micro> diff = std::chrono::high_resolution_clock::now() - last_tp;
if(released() && diff.count() < 100000){
std::cout << "draggable clicked" << std::endl;
return true;
}
return false;
}
bool Draggable::pickedUp() {
bool Draggable::pickedUp() {
return held() && picked_up;
}
void Draggable::pickUp() {
std::chrono::duration<double, std::micro> diff = std::chrono::high_resolution_clock::now() - last_tp;
if(held() && diff.count() > 100000){
std::cout << "draggable pickedUp" << std::endl;
picked_up = true;
}
void Draggable::pickUp() {
picked_up = true;
drag_offset = position - SCREEN_MOUSE;
}
void Draggable::pickUp(Vec2Df selection_origin) {
void Draggable::pickUp(Vec2Df selection_origin) {
picked_up = true;
drag_offset = position - selection_origin;
}
void Draggable::drag(Vec2Df new_position) {
void Draggable::drag(Vec2Df new_position) {
position = new_position;
}
void Draggable::putDown() {
void Draggable::putDown() {
picked_up = false;
}
bool Draggable::select() {
bool Draggable::select() {
return CheckCollisionPointRec(position, state->selection);
}
void Draggable::deselect() {
void Draggable::deselect() {
selected = false;
}
}
-4
View File
@@ -4,7 +4,6 @@
#include "selectable.h"
#include "state.h"
#include "vmath.h"
#include <chrono>
namespace VISEQ::BASE {
class Draggable : public Movable, public Selectable{
@@ -20,11 +19,8 @@ namespace VISEQ::BASE {
bool picked_up = false;
std::chrono::time_point<std::chrono::high_resolution_clock> last_tp;
virtual bool entered() override;
virtual bool exited() override;
virtual bool clicked() override;
virtual bool pickedUp();
virtual void pickUp() override;
virtual void pickUp(Vec2Df selection_origin) override;
+2 -3
View File
@@ -90,7 +90,6 @@ namespace VISEQ::GRAPH{
if(!KEYS_DOWN.shift) selected_nodes.clear();
selected_nodes.insert(selected_nodes.end(), temp_nodes.begin(), temp_nodes.end());
std::for_each(selected_nodes.begin(), selected_nodes.end(), [](WPTR_Node n){n.lock()->selected = true;});
std::cout << "selected " << selected_nodes.size() << " nodes" << std::endl;
}
void GraphManager::deselect(){
@@ -383,8 +382,8 @@ namespace VISEQ::GRAPH{
// Dynamic opacity by distance to mouse
unsigned char opacity = 150.0f - Clamp(center_handle.dist(mouse_pos), 0.0f, 130.0f);
//unsigned char opacity_from = 250.0f - Clamp(from_to_handle.dist(mouse_pos), 0.0f, 220.0f);
//unsigned char opacity_to = 250.0f - Clamp(to_from_handle.dist(mouse_pos), 0.0f, 220.0f);
unsigned char opacity_from = 250.0f - Clamp(from_to_handle.dist(mouse_pos), 0.0f, 220.0f);
unsigned char opacity_to = 250.0f - Clamp(to_from_handle.dist(mouse_pos), 0.0f, 220.0f);
float opacity_normalized = Clamp((float)opacity / 255.0f, .0f, 1.0f);
//float opacity_from_normalized = Clamp((float)opacity_from / 255.0f, .0f, 1.0f);
+20 -54
View File
@@ -2,14 +2,11 @@
#include "connector.h"
#include "datatypes.h"
#include "interaction-event.h"
#include "node.h"
#include "raylib.h"
#include "state.h"
#include <algorithm>
#include <memory>
#include <ostream>
#include <ranges>
namespace VISEQ::INTERACTION{
@@ -36,7 +33,7 @@ namespace VISEQ::INTERACTION{
gm->cycleModeOfSelectedNodes(false);
}
if(!KEYS_DOWN.ctrl && IsKeyPressed(KEY_V)){
if(IsKeyPressed(KEY_V)){
state->draw_edge_lengths = !state->draw_edge_lengths;
}
}
@@ -44,7 +41,7 @@ namespace VISEQ::INTERACTION{
void InteractionManager::draw(){
doInteraction();
scaleSelection();
if(gm->getSelection().size() > 1){
if(!gm->getSelection().empty()){
DrawRectangleRoundedLines(state->bounding_box, 0.1f, 3, VS_COLOR_LIGHTGREY);
scale_handle->draw();
}
@@ -136,37 +133,16 @@ namespace VISEQ::INTERACTION{
bool exit = false;
bool once = false;
bool connect_once = false;
bool blocking = false;
//std::cout << state->mouse_z << std::endl;
state->mouse_z = canvas->z_index;
//auto sorted_queue = state->event_queue
auto nodes_queue = state->event_queue | RANGE_FILTER([](APP::InteractionEvent e) { return e.item->getType() == GraphItemType::NODE; }) | std::ranges::to<std::deque<APP::InteractionEvent>>();
auto connector_queue = state->event_queue | RANGE_FILTER([](APP::InteractionEvent e) { return e.item->getType() == GraphItemType::CONNECTOR; }) | std::ranges::to<std::deque<APP::InteractionEvent>>();
auto canvas_queue = state->event_queue | RANGE_FILTER([](APP::InteractionEvent e) { return e.item->getType() == GraphItemType::CANVAS; }) | std::ranges::to<std::deque<APP::InteractionEvent>>();
std::sort(nodes_queue.begin(), nodes_queue.end(), [](APP::InteractionEvent a, APP::InteractionEvent b){return a.item->z_index > b.item->z_index;});
std::deque<APP::InteractionEvent> state_queue;
state_queue.append_range(nodes_queue);
state_queue.append_range(connector_queue);
state_queue.append_range(canvas_queue);
state->event_queue.clear();
std::cout << state_queue.size() << std::endl;
for(auto e : state_queue){
for(auto e : state->event_queue){
if(!connect_once && e.action == APP::Interaction::CONNECT){
blocking = true;
APP::InteractionEvent partner;
bool found = false;
for(auto ei : state->event_queue){
if(ei.action == APP::Interaction::HOVER && ei.item->getType() == GraphItemType::CONNECTOR) {
//std::cout << "YEAH" << std::endl;
std::cout << "YEAH" << std::endl;
partner = ei;
found = true;
break;
@@ -190,16 +166,12 @@ namespace VISEQ::INTERACTION{
connect_once = true;
break;
}
if(e.item->getType() == GraphItemType::NODE){
if(e.action == APP::Interaction::DRAG) blocking = true;
}
}
while(state_queue.size() > 0 && !exit){
auto e = state_queue.front();
while(state->event_queue.size() > 0 && !exit){
auto e = state->event_queue.front();
if(e.action == APP::Interaction::CLICK){
gm->addToSelection();
std::cout << "click" << std::endl;
}
if(e.action == APP::Interaction::RIGHTCLICK){
gm->addToSelection();
@@ -211,10 +183,19 @@ namespace VISEQ::INTERACTION{
state->mouse_z = e.item->z_index;
}
if(e.item->getType() == GraphItemType::CANVAS) {
if(e.action == APP::Interaction::SELECT) {
gm->select();
canvas->clearSelectionRect();
}
if(e.action == APP::Interaction::DESELECT) {
gm->deselect();
}
}
if(!once && e.item->getType() == GraphItemType::NODE){
auto node = std::dynamic_pointer_cast<Node>(e.item);
if(!blocking && e.action == APP::Interaction::PICKUP) {
std::cout << "node pickup" << std::endl;
if(e.action == APP::Interaction::PICKUP) {
node->pickUp();
if(node->selected){
for(auto s : gm->getSelection()){
@@ -224,8 +205,6 @@ namespace VISEQ::INTERACTION{
once = true;
}
if(e.action == APP::Interaction::DRAG) {
blocking = true;
std::cout << "node drag" << std::endl;
if(KEYS_DOWN.ctrl) node->drag(MOD_MOUSE);
else if(KEYS_DOWN.shift) {
snapPolar(node);
@@ -237,9 +216,9 @@ namespace VISEQ::INTERACTION{
s->drag(MOD_MOUSE + s->drag_offset);
}
}
once = true;
}
if(e.action == APP::Interaction::PUTDOWN) {
std::cout << "node putdown" << std::endl;
node->putDown();
if(node->selected){
for(auto s : gm->getSelection()){
@@ -248,19 +227,6 @@ namespace VISEQ::INTERACTION{
}
}
}
if(!blocking && !once && e.item->getType() == GraphItemType::CANVAS) {
if(e.action == APP::Interaction::SELECT) {
std::cout << "canvas select" << std::endl;
gm->select();
canvas->clearSelectionRect();
}
if(e.action == APP::Interaction::DESELECT) {
std::cout << "canvas deselect" << std::endl;
gm->deselect();
}
}
if(exit) break;
if(!once && (e.item->getType() == GraphItemType::CONNECTOR || e.item->getType() == GraphItemType::CANVAS || e.item->getType() == GraphItemType::HANDLE)) {
@@ -287,8 +253,8 @@ namespace VISEQ::INTERACTION{
}
}
state_queue.pop_front();
state->event_queue.pop_front();
}
state_queue.clear();
state->event_queue.clear();
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ namespace VISEQ::INTERACTION{
virtual void update() override {
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(hovering() && held() && !pickedUp()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
}
+12 -8
View File
@@ -264,21 +264,25 @@ namespace VISEQ::GRAPH::NODES {
break;}
}
DrawRing(position, radius, radius + 4, 0, 360, 24, VS_COLOR_DARKGREY);
//DrawRing(position, radius, radius + 4, 0.0f - 90.0f, (360.0f/127.0f) * getNotes().velocity - 90.0f, 24, (Color){158, 134, 200, 255});
if(!selected) DrawCircleLinesV(position, radius + 4, VS_COLOR_GREY);
if(!selected) DrawCircle(position.x, position.y, radius, state->settings.mode_colors[mode]);
if(selected) DrawCircle(position.x, position.y, radius, VS_COLOR_LIGHTBLUE);
float trigger_alpha = (1.f / getNotes().gate) * fade;
DrawCircle(position.x, position.y, radius, ColorLerp(state->settings.mode_colors[mode], VS_COLOR_RED, trigger_alpha));
if(hovering()) DrawCircleLinesV(position, radius + 4, VS_COLOR_PINK);
if(picked_up || (in_selection_rect && MOUSE_LEFT.down) || selected) DrawCircleLinesV(position, radius + 4, VS_COLOR_LIGHTBLUE);
//if(selected) DrawCircle(position.x, position.y, radius, (Color){255, 153, 187, 255});
if(!selected && !pickedUp() && !hovering()) DrawRing(position, radius, radius + 3, 0, 360, 24, VS_COLOR_GREY);
DrawRing(position, radius, radius + 3, 0, 360, 24, ColorLerp(VS_COLOR_GREY, VS_COLOR_RED, trigger_alpha));
if(selected) DrawRing(position, radius, radius + 3, 0, 360, 24, VS_COLOR_RED);
if(picked_up || (in_selection_rect && MOUSE_LEFT.down) || selected) DrawRing(position, radius, radius + 3, 0, 360, 24, VS_COLOR_LIGHTBLUE);
if(hovering()) DrawRing(position, radius, radius + 3, 0, 360, 24, VS_COLOR_PINK);
DrawCircleLinesV(position, radius + 3, VS_COLOR_LIGHTGREY);
//if(hovering()) DrawCircleLinesV(position, radius + 4, VS_COLOR_PINK);
if(distributionMode == Distribution::RANDOM) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_PINK);
if(distributionMode == Distribution::ROUNDROBIN) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_YELLOW);
//if(selected) DrawCircleLinesV(position, radius+8, (Color){158, 255, 210, 255});
VMATH::Vec2D<float> desc_position = position + VMATH::Vec2D<float>(radius + 7.0f, radius + 7.0f);
switch(mode){
+1 -9
View File
@@ -5,7 +5,6 @@
#include "connector.h"
#include "datatypes.h"
#include "interaction-event.h"
#include "state.h"
#include "vmath.h"
@@ -48,16 +47,9 @@ namespace VISEQ::GRAPH::NODES {
void Node::update() {
if(hovering()) state->pushEvent({getPtr(), APP::Interaction::HOVER});
if(clicked()) {
selected = true;
state->pushEvent({getPtr(), APP::Interaction::CLICK});
}
if(hovering() && held() && !pickedUp()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
if(hovering() && MOUSE_RIGHT.clicked) {
selected = true;
config = true;