good progress, signals not going to next node
This commit is contained in:
@@ -113,12 +113,6 @@ Vec2D<T> operator*(const Vec2D<T>& left, T scalar){
|
||||
return Vec2D<T>(left.x * scalar, left.y * scalar);
|
||||
};
|
||||
|
||||
struct Color{
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
};
|
||||
|
||||
/*template <typename T>*/
|
||||
/*bool contains(T X, T Y) {*/
|
||||
/* for (unsigned int i=0;i<Coords.size()-2;i+=2)*/
|
||||
|
||||
+145
-80
@@ -6,24 +6,31 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SFML/Graphics/Text.hpp"
|
||||
/*Background: (46, 46, 46); #2e2e2e*/
|
||||
/*Comments: (121, 121, 121); #797979*/
|
||||
/*White: (214, 214, 214); #d6d6d6*/
|
||||
/*Yellow: (229, 181, 103); #e5b567*/
|
||||
/*Green: (180, 210, 115); #b4d273*/
|
||||
/*Orange: (232, 125, 62); #e87d3e*/
|
||||
/*Purple: (158, 134, 200); #9e86c8*/
|
||||
/*Pink: (176, 82, 121); #b05279*/
|
||||
/*Blue: (108, 153, 187); #6c99bb*/
|
||||
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "raygui/raygui.h"
|
||||
#include "raygui/dark/style_dark.h"
|
||||
|
||||
#include "libremidi/libremidi.hpp"
|
||||
#include "libremidi/message.hpp"
|
||||
#include "libremidi/observer_configuration.hpp"
|
||||
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Main.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/OpenGL.hpp>
|
||||
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
|
||||
#include "node.h"
|
||||
#include "signal.h"
|
||||
@@ -37,20 +44,47 @@ std::vector<libremidi::output_port> midi_out_ports;
|
||||
std::vector<Node> nodes;
|
||||
std::vector<Signal> signals;
|
||||
|
||||
//std::map<Movable*, std::vector<Node*>> connections;
|
||||
|
||||
Vec2D<float> mouse_pos;
|
||||
Vec2D<float> drag_start;
|
||||
|
||||
bool mouse_pressed = false;
|
||||
bool mouse_clicked = false;
|
||||
bool mouse_touched = false;
|
||||
bool mouse_dragging = false;
|
||||
|
||||
enum States {IDLE, CONFIG};
|
||||
|
||||
struct AppState{
|
||||
int width;
|
||||
int height;
|
||||
States state;
|
||||
} app;
|
||||
|
||||
int main(){
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({2560,1440}), "VISEQ");
|
||||
window.setFramerateLimit(120);
|
||||
InitWindow(2560, 1440, "VISEQ");
|
||||
|
||||
GuiLoadStyleDark();
|
||||
|
||||
int monitor = 0; //GetCurrentMonitor();
|
||||
|
||||
SetWindowMonitor(monitor);
|
||||
|
||||
app.width = GetMonitorWidth(monitor);
|
||||
app.height = GetMonitorHeight(monitor);
|
||||
|
||||
Camera2D camera = { 0 };
|
||||
camera.target = (Vector2){ app.width/2.0f, app.height/2.0f };
|
||||
camera.offset = (Vector2){ app.width/2.0f, app.height/2.0f };
|
||||
camera.rotation = 0.0f;
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
SetTargetFPS(120);
|
||||
|
||||
ToggleFullscreen();
|
||||
|
||||
for(const libremidi::input_port& port : obs.get_input_ports()){
|
||||
midi_in_ports.push_back(port);
|
||||
@@ -61,96 +95,127 @@ int main(){
|
||||
}
|
||||
|
||||
for(int i = 0; i < 10; i++){
|
||||
nodes.emplace(nodes.end(), Node((float)(rand() % 2000 + 280), (float)(rand() % 1000 + 220), 15.0f));
|
||||
nodes.emplace(nodes.end(), Node((float)(rand() % 2160 + 200), (float)(rand() % 1040 + 200), 15.0f));
|
||||
}
|
||||
|
||||
for(int i = 0; i < 10; i++){
|
||||
signals.emplace(signals.end(), Signal(2560.f/2.f, 1440.f/2.f, 5.0f));
|
||||
signals[i].target_node_id = rand() % 9;
|
||||
for(int i = 0; i < 1; i++){
|
||||
signals.emplace(signals.end(), Signal(0, 0, 5.0f, 2.0f));
|
||||
signals[i].next = &nodes[0];
|
||||
}
|
||||
|
||||
midi_out.open_port(midi_out_ports[2]);
|
||||
|
||||
Vec2D<float> drag_origin;
|
||||
|
||||
sf::Clock deltaClock;
|
||||
|
||||
while(window.isOpen()){
|
||||
sf::Event event;
|
||||
while(window.pollEvent(event) ){
|
||||
Node* connecting_from;
|
||||
|
||||
if(event.type == sf::Event::Closed){
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
while(!WindowShouldClose()){
|
||||
|
||||
sf::Vector2i mp = sf::Mouse::getPosition(window);
|
||||
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
|
||||
Vec2D<float> mouse_pos = {(float)mp.x, (float)mp.y};
|
||||
|
||||
bool mouse_toggled = false;
|
||||
mouse_pressed = sf::Mouse::isButtonPressed(sf::Mouse::Button::Left);
|
||||
bool mouse_down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
||||
bool mouse_clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
||||
bool mouse_released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
|
||||
if(!mouse_pressed && mouse_clicked) mouse_clicked = false;
|
||||
if(mouse_pressed && !mouse_clicked){
|
||||
mouse_clicked = true;
|
||||
mouse_toggled = true;
|
||||
if(mouse_clicked){
|
||||
drag_start = mouse_pos;
|
||||
}
|
||||
|
||||
window.clear(sf::Color(46,46,46));
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground((Color){46,46,46});
|
||||
|
||||
BeginMode2D(camera);
|
||||
|
||||
bool hovering = false;
|
||||
|
||||
bool hovering = false;
|
||||
for( auto& n : nodes){
|
||||
Vec2D<float> connector_position = n.position - ((n.position - mouse_pos)).norm() * (n.radius + 10.0f);
|
||||
float dist_connector = (connector_position - mouse_pos).length();
|
||||
|
||||
float dist = (n.position - mouse_pos).length();
|
||||
|
||||
// connect nodes
|
||||
if( (dist <= n.radius + 25.0f && dist > n.radius) || n.connecting){
|
||||
n.hover_connect = true;
|
||||
} else {
|
||||
n.hover_connect = false;
|
||||
}
|
||||
|
||||
for( auto& n : nodes){
|
||||
if(dist_connector <= 6.0f && mouse_clicked) {
|
||||
connecting_from = &n;
|
||||
n.connecting = true;
|
||||
}
|
||||
|
||||
if((n.position - mouse_pos).length() <= n.radius && !hovering) {
|
||||
n.hover_move = true;
|
||||
hovering = true;
|
||||
} else {
|
||||
n.hover_move = false;
|
||||
}
|
||||
if(n.connecting && mouse_down){
|
||||
DrawLine(connector_position.x, connector_position.y, mouse_pos.x, mouse_pos.y, (Color){229, 181, 103, 255});
|
||||
}
|
||||
|
||||
if(mouse_released && n.connecting) {
|
||||
n.connecting = false;
|
||||
}
|
||||
|
||||
if(mouse_released && n.hover_connect) {
|
||||
n.connections.push_back(connecting_from);
|
||||
connecting_from->connections.push_back(&n);
|
||||
}
|
||||
|
||||
// move node
|
||||
if((n.position - mouse_pos).length() <= n.radius || n.picked_up){
|
||||
n.hover_move = true;
|
||||
} else {
|
||||
n.hover_move = false;
|
||||
}
|
||||
|
||||
if(mouse_clicked && n.hover_move){
|
||||
n.clicked = true;
|
||||
}
|
||||
if(mouse_toggled) drag_origin = n.position;
|
||||
if(mouse_pressed && n.clicked){
|
||||
n.position = mouse_pos; // - (drag_start - drag_origin);
|
||||
}
|
||||
if(!mouse_pressed) n.clicked = false;
|
||||
n.update();
|
||||
n.draw(&window);
|
||||
}
|
||||
if(mouse_clicked && n.hover_move){
|
||||
n.picked_up = true;
|
||||
drag_origin = mouse_pos;
|
||||
}
|
||||
if(mouse_down && n.picked_up){
|
||||
n.position = mouse_pos - (n.position - drag_origin);
|
||||
}
|
||||
if(mouse_down && n.hover_move) hovering = true;
|
||||
|
||||
for( auto& n : signals){
|
||||
n.speed = 2.0f;
|
||||
n.direction = nodes[n.target_node_id].position - n.position;
|
||||
if(n.position.dist(&nodes[n.target_node_id].position) < n.speed * 1.5) {
|
||||
n.target_node_id++;
|
||||
midi_out.send_message(libremidi::channel_events::control_change(2, n.target_node_id, 50));
|
||||
}
|
||||
if(n.target_node_id == 10) n.target_node_id = 0;
|
||||
n.update();
|
||||
n.draw(&window);
|
||||
}
|
||||
|
||||
if(!hovering && mouse_clicked) {
|
||||
Vec2D<float> ref = {1.f,0.f};
|
||||
Vec2D<float> lineVec = mouse_pos - drag_start;
|
||||
float width = lineVec.length();
|
||||
float angle = ref.angleDeg(lineVec);
|
||||
if(mouse_released) {
|
||||
n.picked_up = false;
|
||||
}
|
||||
n.draw(&mouse_pos);
|
||||
}
|
||||
|
||||
sf::RectangleShape line;
|
||||
line.setSize(sf::Vector2f(width, 2));
|
||||
line.setPosition(drag_start.x, drag_start.y);
|
||||
line.setRotation(angle);
|
||||
line.setFillColor(sf::Color(100,0,0));
|
||||
window.draw(line);
|
||||
}
|
||||
//window.draw();
|
||||
window.display();
|
||||
/*for( auto from : connections){*/
|
||||
/* for( auto to : from.second){*/
|
||||
/* Vec2D<float> from_position = from.first->position - ((from.first->position - to->position)).norm() * (from.first->radius + 10.0f);*/
|
||||
/* Vec2D<float> to_position = to->position - ((to->position - from.first->position)).norm() * (to->radius + 10.0f);*/
|
||||
/* DrawLine(from_position.x, from_position.y, to_position.x, to_position.y, (Color){229, 181, 103, 255});*/
|
||||
/* }*/
|
||||
/*}*/
|
||||
|
||||
for( auto& s : signals){
|
||||
s.direction = s.next->position - s.position;
|
||||
if(s.position.dist(&s.next->position) < s.speed * 1.5) {
|
||||
if(s.next->connections.size() > 0) {
|
||||
s.next = s.next->connections[0];
|
||||
}
|
||||
//midi_out.send_message(libremidi::channel_events::control_change(2, 10, 50));
|
||||
}
|
||||
s.draw(&mouse_pos);
|
||||
}
|
||||
|
||||
if(!hovering && mouse_clicked) {
|
||||
}
|
||||
|
||||
EndMode2D();
|
||||
GuiWindowBox((Rectangle){16,16,232,400}, "config");
|
||||
|
||||
GuiButton((Rectangle){32, 64, 96, 20}, "button");
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "SFML/Graphics/RenderWindow.hpp"
|
||||
#include "datatypes.h"
|
||||
|
||||
class Movable{
|
||||
@@ -16,6 +15,6 @@ class Movable{
|
||||
Vec2D<float> direction;
|
||||
|
||||
virtual void update() {};
|
||||
virtual void draw(sf::RenderWindow *window) {};
|
||||
virtual void draw(Vec2D<float> *mouse) {};
|
||||
|
||||
};
|
||||
|
||||
+25
-13
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <raylib.h>
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "moveable.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define R 10.0f
|
||||
|
||||
class Node : public Movable{
|
||||
|
||||
public:
|
||||
@@ -16,21 +17,32 @@ class Node : public Movable{
|
||||
|
||||
float radius;
|
||||
|
||||
bool clicked = false;
|
||||
int id;
|
||||
bool picked_up = false;
|
||||
bool hover_move = false;
|
||||
bool hover_connect = false;
|
||||
bool connecting = false;
|
||||
|
||||
std::vector<Node*> connections;
|
||||
|
||||
void update() {};
|
||||
|
||||
void draw(sf::RenderWindow* window) {
|
||||
|
||||
sf::CircleShape circle(radius);
|
||||
circle.setOrigin(radius/2.f, radius/2.f);
|
||||
if(!hover_move) circle.setFillColor(sf::Color(180, 210, 115));
|
||||
if(hover_move) circle.setFillColor(sf::Color(108, 153, 187));
|
||||
circle.setPosition(position.x, position.y);
|
||||
window->draw(circle);
|
||||
void draw(Vec2D<float> *mouse) {
|
||||
if(!hover_move) DrawCircle(position.x, position.y, radius, (Color){180, 210, 115, 255});
|
||||
if(hover_move) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
||||
|
||||
Vec2D<float> connector = position - ((position - *mouse)).norm() * (radius + R);
|
||||
|
||||
for(auto& to : connections){
|
||||
Vec2D<float> from_position = position - ((position - to->position)).norm() * (radius + 10.0f);
|
||||
Vec2D<float> to_position = to->position - ((to->position - position)).norm() * (to->radius + 10.0f);
|
||||
DrawLine(from_position.x, from_position.y, to_position.x, to_position.y, (Color){229, 181, 103, 255});
|
||||
}
|
||||
|
||||
if(hover_connect){
|
||||
DrawCircleLines(position.x, position.y, radius + R, (Color){108, 153, 187, 255});
|
||||
DrawCircle(connector.x, connector.y, 6.0f, (Color){108, 153, 187, 255});
|
||||
} else {
|
||||
DrawCircleLines(position.x, position.y, radius + R, (Color){108, 153, 187, 50});
|
||||
DrawCircle(connector.x, connector.y, 6.0f, (Color){108, 153, 187, 50});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
+14
-14
@@ -1,32 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "SFML/Graphics/CircleShape.hpp"
|
||||
#include "SFML/Graphics/Color.hpp"
|
||||
#include "SFML/Graphics/RenderWindow.hpp"
|
||||
#include <raylib.h>
|
||||
|
||||
#include "datatypes.h"
|
||||
#include "moveable.h"
|
||||
#include "node.h"
|
||||
|
||||
class Signal : public Movable{
|
||||
public:
|
||||
|
||||
Signal();
|
||||
Signal(float x, float y, float r) : Movable(Vec2D<float>(x, y), Vec2D<float>(0,0), 0.0), radius(r) {}
|
||||
Signal(float x, float y, float r, float s) : Movable(Vec2D<float>(x, y), Vec2D<float>(0,0), s), radius(r) {}
|
||||
|
||||
int id = 0;
|
||||
|
||||
|
||||
Node *next;
|
||||
|
||||
bool at_target = false;
|
||||
int target_node_id = 1;
|
||||
int source_node_id = 0;
|
||||
|
||||
float radius;
|
||||
|
||||
void update() { position += direction.norm() * speed;};
|
||||
void draw(Vec2D<float> *mouse) {
|
||||
|
||||
position += direction.norm() * speed;
|
||||
|
||||
void draw(sf::RenderWindow *window) {
|
||||
sf::CircleShape circle(radius);
|
||||
circle.setFillColor(sf::Color(232, 125, 62));
|
||||
circle.setPosition(position.x, position.y);
|
||||
// circle.getPoint();
|
||||
// circle.getPointCount()
|
||||
window->draw(circle);
|
||||
};
|
||||
DrawCircle(position.x, position.y, radius, (Color){232, 125, 62, 255});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user