ui improvements, grid and optimizations

This commit is contained in:
Sebastian
2024-10-20 23:42:38 +02:00
parent 186c15fb54
commit 3e14a4a179
9 changed files with 166 additions and 57 deletions
+103 -36
View File
@@ -86,7 +86,6 @@ int main(){
for(int i = 0; i < 10; i++){
nodes.emplace(nodes.end(), Node((float)(rand() % app.width*0.5 + app.width*0.25), (float)(rand() % app.height*0.5 + app.height*0.25), 15.0f));
std::cout << nodes.back().position.x << " " << nodes.back().position.y << std::endl;
}
for(int i = 0; i < 1; i++){
@@ -97,6 +96,9 @@ int main(){
Vec2D<float> drag_offset;
Vec2D<float> cam_drag_offset;
Vec2D<float> cam_mouse_drag_offset;
Node* connecting_from = nullptr;
double drag_timer = GetTime();
@@ -105,11 +107,30 @@ int main(){
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
Vec2D<float> mouse_pos = {(float)mp.x, (float)mp.y};
Vec2D<float> cam_pos = {camera.offset.x, camera.offset.y};
bool mouse_down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
bool mouse_clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
bool mouse_released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{
Vector2 delta = GetMouseDelta();
delta = Vector2Scale(delta, -1.0f/camera.zoom);
camera.target = Vector2Add(camera.target, delta);
}
float wheel = GetMouseWheelMove();
if (wheel != 0)
{
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
camera.offset = GetMousePosition();
camera.target = mouseWorldPos;
float scaleFactor = 1.0f + (0.25f*fabsf(wheel));
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
camera.zoom = Clamp(camera.zoom*scaleFactor, 0.125f, 64.0f);
}
if(mouse_clicked){
drag_start = mouse_pos;
}
@@ -122,6 +143,13 @@ int main(){
bool connecting = false;
bool dragging = false;
for(int x = -5000; x < 5000; x+=50){
for(int y = -5000; y < 5000; y+=50){
// DrawLine(-5000, i, 5000, i, (Color){80,80,80,100});
DrawPixel(x, y, (Color){120,120,120,200});
}
}
for(auto& n : nodes){
Vec2D<float> connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 14.0f);
float dist_connector = (connector_position - mouse_pos).length();
@@ -171,7 +199,13 @@ int main(){
drag_timer = GetTime();
}
if(mouse_down && n.picked_up){
if(GetTime() - drag_timer > 0.1) n.position = mouse_pos + drag_offset;
if(GetTime() - drag_timer > 0.1) {
if(IsKeyDown(KEY_LEFT_CONTROL)) {
n.position = (Vec2D<float>){round((mouse_pos.x+drag_offset.x)/50.0f)*50.0f, round((mouse_pos.y+drag_offset.y)/50.0f)*50.0f};
} else {
n.position = mouse_pos + drag_offset;
}
}
}
if(mouse_released && n.picked_up){
@@ -183,10 +217,10 @@ int main(){
}
}
n.draw(&mouse_pos);
n.draw(&mouse_pos, &camera);
}
cm.draw();
cm.draw(&mouse_pos, &camera);
for(auto& s : signals){
s.direction = (s.next->position - s.position).norm();
@@ -201,7 +235,7 @@ int main(){
s.next = n;
}
}
s.draw(&mouse_pos);
s.draw(&mouse_pos, &camera);
}
midi.update();
EndMode2D();
@@ -209,61 +243,94 @@ int main(){
// Main Config Window
GuiWindowBox((Rectangle){0,0,280,(float)app.height}, "config");
{
GuiLabel((Rectangle){20, 60, 240, 20}, "MIDI OUT");
GuiLabel((Rectangle){20, 55, 240, 20}, "MIDI OUT");
int i = 0;
for(auto& mo : midi.midi_out_ports){
GuiCheckBox((Rectangle){20, 80 + i*20.0f, 20, 20}, mo.port.port_name.c_str(), &mo.enabled);
i++;
}
if(GuiButton((Rectangle){20, 60, 240, 20}, "ADD SIGNAL")){
signals.emplace_back(Signal(nodes.front().position.x + 1, nodes.front().position.y + 1, 5.0f, 2.0f)); // position + 1 or else it does not render. why? no idea!
signals.back().next = &nodes[0];
signals.back().last = &nodes[0];
if(GuiButton((Rectangle){20, 100 + i*20.0f, 240, 20}, "ENABLE FOR ALL")) {
for(auto &midis : midi.midi_out_ports){
if(midis.enabled){
for(auto &n : nodes){
n.midi_outs[midis.number].enabled = true;
}
}
}
}
GuiLabel((Rectangle){20, 135 + i*20.0f, 240, 20}, "SIGNALS");
if(GuiButton((Rectangle){20, 160 + i*20.0f, 240, 20}, "ADD RANDOM SIGNAL")){
int ni = rand() % nodes.size();
signals.emplace_back(Signal(nodes[ni].position.x + 1, nodes[ni].position.y + 1, 5.0f, 2.0f)); // position + 1 or else it does not render. why? no idea!
signals.back().next = &nodes[ni];
signals.back().last = &nodes[ni];
}
GuiLabel((Rectangle){20, 185 + i*20.0f, 240, 20}, "NODES");
if(GuiButton((Rectangle){20, 215 + i*20.0f, 240, 20}, "ADD RANDOM NODE")){
nodes.emplace_back(Node((float)(rand() % app.width*0.5 + app.width*0.25), (float)(rand() % app.height*0.5 + app.height*0.25), 15.0f));
}
}
// Per Node Config Windows
for(auto& n : nodes){
if(n.config){
n.config = !GuiWindowBox((Rectangle){n.position.x + 10, n.position.y + 10,240,400}, "config");
int option = n.mode;
GuiComboBox((Rectangle){ n.position.x + 20, n.position.y + 40, 220, 20 }, "Round Robin;Random", &option);
n.mode = (Distribution)option;
Vector2 np = GetWorldToScreen2D((Vector2){n.position.x, n.position.y}, camera);
int y_midi = 60;
GuiLabel((Rectangle){n.position.x + 20, n.position.y + y_midi, 220, 20}, "MIDI OUT");
for(auto& mo : midi.midi_out_ports){
if(!n.midi_outs.contains(mo.number) && mo.enabled){
n.midi_outs[mo.number] = {mo.number, mo.port.port_name, false};
}
for(auto& mo : midi.midi_out_ports){
if(!n.midi_outs.contains(mo.number) && mo.enabled){
n.midi_outs[mo.number] = {mo.number, mo.port.port_name, false};
}
if(n.midi_outs.contains(mo.number) && !mo.enabled){
n.midi_outs.erase(mo.number);
}
}
if(n.config){
n.config = !GuiWindowBox((Rectangle){np.x + 10, np.y + 10, 240, 440}, "config");
int option = n.mode;
GuiToggleGroup((Rectangle){ np.x + 20, np.y + 40, 110, 20 }, "Round Robin;Random", &option);
n.mode = (Distribution)option;
GuiLabel((Rectangle){np.x + 20, np.y + 65, 220, 20}, "SIGNALS");
if(GuiButton((Rectangle){np.x + 20, np.y + 90, 220, 20}, "ADD SIGNAL")){
signals.emplace_back(Signal(n.position.x + 1, n.position.y + 1, 5.0f, 2.0f)); // position + 1 or else it does not render. why? no idea!
signals.back().next = &n;
signals.back().last = &n;
}
int y_midi = 120;
GuiLabel((Rectangle){np.x + 20, np.y + y_midi, 220, 20}, "MIDI OUT");
int i = 0;
for(auto& mo : n.midi_outs){
GuiCheckBox((Rectangle){n.position.x + 20, n.position.y + y_midi + 20 + i*20.0f, 20, 20}, mo.second.name.c_str(), &mo.second.enabled);
GuiCheckBox((Rectangle){np.x + 20, np.y + y_midi + 20 + i*20.0f, 20, 20}, mo.second.name.c_str(), &mo.second.enabled);
i++;
}
int y_channel = y_midi + 20 + i*20;
GuiLabel((Rectangle){n.position.x + 20, n.position.y + y_channel, 220, 20}, "CHANNEL");
GuiToggleGroup((Rectangle){n.position.x + 20, n.position.y + y_channel + 30, 25, 20}, "1;2;3;4;5;6;7;8\n9;10;11;12;13;14;15;16", &n.midi_channel);
int y_channel = y_midi + 30 + i*20;
GuiLabel((Rectangle){np.x + 20, np.y + y_channel, 220, 20}, "CHANNEL");
GuiToggleGroup((Rectangle){np.x + 20, np.y + y_channel + 30, 25, 20}, "1;2;3;4;5;6;7;8\n9;10;11;12;13;14;15;16", &n.midi_channel);
GuiLabel((Rectangle){n.position.x + 20, n.position.y + y_channel + 90, 100, 20}, "NOTE");
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 90, 100, 20}, "NOTE");
float v = n.midi_note;
GuiLabel((Rectangle){n.position.x + 210, n.position.y + y_channel + 90, 20, 20}, midi.midiNotes[(int)round(v)].c_str());
GuiLabel((Rectangle){n.position.x + 160, n.position.y + y_channel + 90, 40, 20}, std::format("{}",n.midi_note).c_str());
GuiSlider((Rectangle){n.position.x + 20, n.position.y + y_channel + 120, 220, 20}, "", "", &v, 0, 127);
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 90, 20, 20}, midi.midiNotes[(int)round(v)].c_str());
GuiLabel((Rectangle){np.x + 160, np.y + y_channel + 90, 40, 20}, std::format("{}",n.midi_note).c_str());
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 120, 220, 20}, "", "", &v, 0, 127);
n.midi_note = round(v);
GuiLabel((Rectangle){n.position.x + 20, n.position.y + y_channel + 150, 100, 20}, "VELOCITY");
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 150, 100, 20}, "VELOCITY");
v = n.midi_velocity;
GuiLabel((Rectangle){n.position.x + 210, n.position.y + y_channel + 150, 20, 20}, std::format("{}",n.midi_velocity).c_str());
GuiSlider((Rectangle){n.position.x + 20, n.position.y + y_channel + 180, 220, 20}, "", "", &v, 0, 127);
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 150, 20, 20}, std::format("{}",n.midi_velocity).c_str());
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 180, 220, 20}, "", "", &v, 0, 127);
n.midi_velocity = round(v);
GuiLabel((Rectangle){n.position.x + 20, n.position.y + y_channel + 210, 100, 20}, "GATE");
GuiLabel((Rectangle){np.x + 20, np.y + y_channel + 210, 100, 20}, "GATE");
v = n.midi_gate;
GuiLabel((Rectangle){n.position.x + 210, n.position.y + y_channel + 210, 20, 20}, std::format("{}",(float)n.midi_gate/1000.0f).c_str());
GuiSlider((Rectangle){n.position.x + 20, n.position.y + y_channel + 240, 220, 20}, "", "", &v, 0, 5000);
GuiLabel((Rectangle){np.x + 210, np.y + y_channel + 210, 20, 20}, std::format("{}",(float)n.midi_gate/1000.0f).c_str());
GuiSlider((Rectangle){np.x + 20, np.y + y_channel + 240, 220, 20}, "", "", &v, 0, 5000);
n.midi_gate = round(v);
//if(GuiValueBox((Rectangle){n.position.x + 100, n.position.y + y_channel + 40, 140, 20}, "VELOCITY", &n.midi_velocity, 0, 127, n.gui_midi_velocity_edit)) n.gui_midi_velocity_edit = !n.gui_midi_velocity_edit;