heavy restructuring with smart pointers, not finished
This commit is contained in:
+25
-27
@@ -6,6 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
|
||||
#include "datatypes.h"
|
||||
@@ -67,17 +68,17 @@ int main(){
|
||||
camera.zoom = 1.0f;
|
||||
|
||||
for(int i = 0; i < 4; ++i){
|
||||
app.nm.addNode((float)i * app.settings.grid*4 + 10 * app.settings.grid, 5 * app.settings.grid*4);
|
||||
app.gm.addNode((float)i * app.settings.grid*4 + 10 * app.settings.grid, 5 * app.settings.grid*4);
|
||||
}
|
||||
for(int i = 3; i >= 0; --i){
|
||||
app.nm.addNode((float)i * app.settings.grid*4 + 10 * app.settings.grid, 6 * app.settings.grid*4);
|
||||
app.gm.addNode((float)i * app.settings.grid*4 + 10 * app.settings.grid, 6 * app.settings.grid*4);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 8; ++i){
|
||||
app.cm.addConnection(app.nm.nodes[i].id, app.nm.nodes[(i+1) % 8].id);
|
||||
app.gm.addConnection(app.gm.nodes[i].id, app.gm.nodes[(i+1) % 8].id);
|
||||
}
|
||||
|
||||
app.sm.addSignalAtNode((app.nm.nodes | std::views::values).front().id);
|
||||
app.sm.addSignalAtNode((app.gm.nodes | std::views::values).front().id);
|
||||
app.sm.startSignalThread();
|
||||
|
||||
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
|
||||
@@ -109,15 +110,16 @@ int main(){
|
||||
|
||||
Vec2D<float> mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
||||
Vec2D<float> delta = mouse_delta * (-1.0f/camera.zoom);
|
||||
|
||||
std::vector<std::shared_ptr<Node>> copied_nodes;
|
||||
|
||||
auto dragging_nodes = app.nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n) { return n.dragging;});
|
||||
auto copied_nodes = app.nm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n) { return n.copied;});
|
||||
auto connecting_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.connecting;});
|
||||
auto selected_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.selected && !n.dragging;});
|
||||
auto hovering_nodes = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
||||
auto hovering_connectors = app.nm.nodes | std::ranges::views::values| std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, (n.position - ((n.position - mouse_pos)).norm() * (n.radius + 14.0f)), 8.0f);});
|
||||
auto dragging_nodes = app.gm.nodes | std::ranges::views::values | std::ranges::views::filter([](Node n) { return n.dragging;});
|
||||
auto connecting_nodes = app.gm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.connecting;});
|
||||
auto selected_nodes = app.gm.nodes | std::ranges::views::values| std::ranges::views::filter([](Node n) { return n.selected && !n.dragging;});
|
||||
auto hovering_nodes = app.gm.nodes | std::ranges::views::values| std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, n.position, n.radius);});
|
||||
auto hovering_connectors = app.gm.nodes | std::ranges::views::values| std::ranges::views::filter([&mouse_pos](Node n) { return CheckCollisionPointCircle(mouse_pos, (n.position - ((n.position - mouse_pos)).norm() * (n.radius + 14.0f)), 8.0f);});
|
||||
|
||||
for(auto &n : app.nm.nodes | std::ranges::views::values){
|
||||
for(auto &n : app.gm.nodes | std::ranges::views::values){
|
||||
if(hovering_nodes.empty()) n.hovering = false;
|
||||
if(hovering_connectors.empty()) n.hover_connect = false;
|
||||
}
|
||||
@@ -137,13 +139,13 @@ int main(){
|
||||
|
||||
if(IsKeyPressed(KEY_TAB)) {
|
||||
app.settings.mode = (app.settings.mode + 1) % 3;
|
||||
app.nm.setNodeMode(app.settings.mode);
|
||||
app.gm.setNodeMode(app.settings.mode);
|
||||
}
|
||||
|
||||
switch(istate){
|
||||
case InteractionState::HOVER_CANVAS:
|
||||
{
|
||||
for(auto &n : app.nm.nodes | std::ranges::views::values){
|
||||
for(auto &n : app.gm.nodes | std::ranges::views::values){
|
||||
n.hover_connect = false;
|
||||
}
|
||||
if(mouse_right_down) {
|
||||
@@ -162,7 +164,7 @@ int main(){
|
||||
DrawRectangleLines(select1.x, select1.y, select2.x, select2.y, (Color){150,150,150,150});
|
||||
selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||
|
||||
for(auto& n : app.nm.nodes | std::views::values){
|
||||
for(auto& n : app.gm.nodes | std::views::values){
|
||||
if(CheckCollisionPointRec(n.position, selection)) {
|
||||
n.in_rect = true;
|
||||
} else {
|
||||
@@ -172,7 +174,7 @@ int main(){
|
||||
}
|
||||
|
||||
if(mouse_released){
|
||||
for(auto& n : app.nm.nodes | std::views::values){
|
||||
for(auto& n : app.gm.nodes | std::views::values){
|
||||
if(CheckCollisionPointRec(n.position, selection)) {
|
||||
n.selected = true;
|
||||
n.in_rect = false;
|
||||
@@ -259,12 +261,12 @@ int main(){
|
||||
if(mouse_released) {
|
||||
if(&hovering_nodes.front() != &connecting_nodes.front() && &connecting_nodes.front() != &hovering_connectors.front()){
|
||||
if(!hovering_nodes.empty()){
|
||||
app.cm.addConnection(connecting_nodes.front().id, hovering_nodes.front().id);
|
||||
app.gm.addConnection(connecting_nodes.front().id, hovering_nodes.front().id);
|
||||
} else if(!hovering_connectors.empty()){
|
||||
app.cm.addConnection(connecting_nodes.front().id, hovering_connectors.front().id);
|
||||
app.gm.addConnection(connecting_nodes.front().id, hovering_connectors.front().id);
|
||||
} else {
|
||||
int id = app.nm.addNode(mouse_pos.x, mouse_pos.y);
|
||||
app.cm.addConnection(connecting_nodes.front().id, id);
|
||||
int id = app.gm.addNode(mouse_pos.x, mouse_pos.y);
|
||||
app.gm.addConnection(connecting_nodes.front().id, id);
|
||||
}
|
||||
}
|
||||
connecting_nodes.front().connecting = false;
|
||||
@@ -282,13 +284,7 @@ int main(){
|
||||
}
|
||||
case InteractionState::COPY_SELECTED_NODES:
|
||||
{
|
||||
for(auto &n: copied_nodes){
|
||||
n.copied = false;
|
||||
}
|
||||
for(auto &n: selected_nodes){
|
||||
n.copied = true;
|
||||
n.selected = false;
|
||||
}
|
||||
std::copy(selected_nodes.begin(), selected_nodes.end(), copied_nodes.begin());
|
||||
break;
|
||||
}
|
||||
case InteractionState::PASTE_SELECTED_NODES:
|
||||
@@ -296,7 +292,9 @@ int main(){
|
||||
for(auto &n: copied_nodes){
|
||||
n.drag_offset = (n.position - copied_nodes.front().position);
|
||||
}
|
||||
// app.nm.copyNodes(mouse_pos);
|
||||
// app.gm.copyNodes(mouse_pos);
|
||||
//app.gm.copyNodes(selected_nodes, mouse_pos);
|
||||
|
||||
app.copyNodesAndConnections(mouse_pos);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user