From cdc0fb7075bdcc1eaaa39b8199d783c6b7e4adb1 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 8 Nov 2024 01:43:06 +0100 Subject: [PATCH] working on node ui --- src/config-node.h | 84 +++++++++++++++++++++++++++++++++++++++++++++++ src/edge.h | 2 ++ src/main.cpp | 22 +++++++++++-- src/ui.h | 1 - 4 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/config-node.h b/src/config-node.h index 62b35c2..f91760b 100644 --- a/src/config-node.h +++ b/src/config-node.h @@ -2,6 +2,7 @@ #include "datatypes.h" #include "node.h" +#include "raymath.h" namespace VISEQ::GRAPH::NODES { @@ -11,9 +12,92 @@ namespace VISEQ::GRAPH::NODES { NodeType nodeType = NodeType::CONFIGNODE; MIDI::MidiNote midiNote; + MIDI::MidiCC midiCC; + MIDI::MidiPitchBend midiPitchBend; + MIDI::MidiPolyPressure midiPolyPressure; + MIDI::MidiPC midiPC; + int mode = 0; virtual NodeType getNodeType() const override {return nodeType;} + void draw(Vec2Df mouse, Camera2D cam) override { + DrawRing(position, radius, radius+4, 0, 360, 24, (Color){60, 60, 60, 255}); + DrawRing(position, radius, radius+4, 0.0f - 90.0f, (360.0f/127.0f) * midiNote.velocity - 90.0f, 24, (Color){158, 134, 200, 255}); + DrawCircleLinesV(position, radius + 4, (Color){100, 100, 100, 255}); + + float fade = 0; + + float midi_gate_map = round((255.f / midiNote.gate) * fade); + + Color gate_color = VS_COLOR_GREEN; + + switch(mode){ + case 0:{ + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){180, 210, 115, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); + break;} + case 1:{ + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){229, 181, 103, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); + break;} + case 2:{ + gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE); + break;} + } + if(!dragging && !selected && !in_rect && !hovering) DrawCircle(position.x, position.y, radius, gate_color); + if(selected || dragging || in_rect || hovering) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255}); + + 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}); + + if(IsKeyDown(KEY_LEFT_ALT)){ + float value = 0; + int offset_gate = 0; + switch(mode){ + case 0: + value = (float)midiNote.gate/1000.0f; + offset_gate = MeasureText(std::format("{:.2f}", value).c_str(), 12); + DrawText(std::format("{:.2f}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE ); + break; + case 1: + value = (float)midiCC.value; + offset_gate = MeasureText(std::format("{}", value).c_str(), 12); + DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE ); + break; + case 2: + value = (float)midiPitchBend.value; + offset_gate = MeasureText(std::format("{}", value).c_str(), 12); + DrawText(std::format("{}",value).c_str(), position.x-offset_gate/2.0f, position.y-5, 12, WHITE ); + break; + } + } else { + switch(mode){ + case 0:{ + int offset = MeasureText(MIDI::Notes[(int)midiNote.note].c_str(), 12); + DrawText(MIDI::Notes[midiNote.note].c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE ); + break;} + case 1:{ + int offset = MeasureText(std::format("{}", midiCC.value).c_str(), 12); + DrawText(std::format("{}", midiCC.value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE ); + break;} + case 2:{ + int offset = MeasureText(std::format("{}", midiPitchBend.value).c_str(), 12); + DrawText(std::format("{}", midiPitchBend.value).c_str(), position.x-offset/2.0f, position.y-5, 12, WHITE ); + break;} + } + } + + Vec2Df connector = position - ((position - mouse)).norm() * (radius + 30); + 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/edge.h b/src/edge.h index 87315aa..fa3c3a3 100644 --- a/src/edge.h +++ b/src/edge.h @@ -32,6 +32,8 @@ namespace VISEQ::GRAPH::EDGES { float switches_offset = 25.0f; virtual bool GActive() {return active;} + + virtual EdgeType getEdgeType() const {return edgeType;} std::shared_ptr getNextNode(std::shared_ptr origin){ return start == origin ? end : start; diff --git a/src/main.cpp b/src/main.cpp index ce5d311..3bea790 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,15 +154,19 @@ int main(){ app.sm.startSignalThread(); - enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, SCALE_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES}; + enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, ADD_NODES_MENU, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, SCALE_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES}; InteractionState istate = HOVER_CANVAS; + Vec2Df node_menu_position; + Vec2Df select_start; Rectangle selection; Vec2Df scale_start; Vec2Df scale_rectangle; + float drag_distance = 0; + VEC_SPTR_Node copied_nodes; @@ -200,7 +204,7 @@ int main(){ if(hovering_connectors.empty()) n->hover_connect = false; } - if(!mouse_down && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::HOVER_CANVAS; + if(istate != InteractionState::ADD_NODES_MENU && !mouse_down && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty()) istate = InteractionState::HOVER_CANVAS; if((mouse_clicked || mouse_down || mouse_released) && !mouse_right_down && dragging_nodes.empty() && connecting_nodes.empty() && hovering_nodes.empty() && hovering_connectors.empty() && istate != InteractionState::SCALE_SELECTION) istate = InteractionState::DRAW_SELECTION; if(!hovering_nodes.empty() && !mouse_down && !mouse_right_down) istate = InteractionState::HOVER_NODE; @@ -271,11 +275,25 @@ int main(){ for(auto &n : app.gm.nodes){ n->hover_connect = false; } + if(mouse_right_clicked){ + drag_distance = 0; + } if(mouse_right_down) { camera.target = Vector2Add(camera.target, delta); + drag_distance += delta.length(); + } + if(mouse_right_released && drag_distance < 5) { + node_menu_position = mouse_pos; + istate = InteractionState::ADD_NODES_MENU; } break; } + case InteractionState::ADD_NODES_MENU: + { + DrawCircleV(node_menu_position, 30, VS_COLOR_LIGHTGREY); + DrawCircleLines(node_menu_position.x, node_menu_position.y, 32, VS_COLOR_DARKGREY); + + } case InteractionState::DRAW_SELECTION: { if(mouse_clicked){ diff --git a/src/ui.h b/src/ui.h index bbacbb9..52071a5 100644 --- a/src/ui.h +++ b/src/ui.h @@ -196,7 +196,6 @@ namespace VISEQ::APP::UI{ void draw(Vec2Df *mouse_pos, Camera2D *camera){ drawSideBar(); - drawPropertiesBar(); drawPerNodeConfig(camera); }