Selection working partially. Needs global z-index hovering to work reliably.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "draggable.h"
|
#include "draggable.h"
|
||||||
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
namespace VISEQ::APP::CANVAS {
|
namespace VISEQ::APP::CANVAS {
|
||||||
@@ -10,6 +11,7 @@ namespace VISEQ::APP::CANVAS {
|
|||||||
|
|
||||||
Camera2D camera;
|
Camera2D camera;
|
||||||
Vec2Df camera_delta;
|
Vec2Df camera_delta;
|
||||||
|
Vec2Df select_start;
|
||||||
|
|
||||||
virtual bool hovering() override {
|
virtual bool hovering() override {
|
||||||
return true;
|
return true;
|
||||||
@@ -23,15 +25,33 @@ namespace VISEQ::APP::CANVAS {
|
|||||||
|
|
||||||
virtual void drawStart(){
|
virtual void drawStart(){
|
||||||
BeginMode2D(camera);
|
BeginMode2D(camera);
|
||||||
|
state->hovering = false;
|
||||||
|
if(hovering()) state->istate = InteractionState::HOVER_CANVAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void drawEnd(){
|
virtual void drawEnd(){
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void select(){
|
||||||
|
|
||||||
|
if(state->mouse_left.clicked){
|
||||||
|
select_start = state->screen_mouse;
|
||||||
|
state->istate = InteractionState::DRAW_SELECTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(state->mouse_left.down){
|
||||||
|
Vec2Df select1 = {state->screen_mouse.x > select_start.x ? select_start.x : state->screen_mouse.x, state->screen_mouse.y > select_start.y ? select_start.y : state->screen_mouse.y};
|
||||||
|
Vec2Df select2 = {state->screen_mouse.x > select_start.x ? state->screen_mouse.x - select_start.x : select_start.x - state->screen_mouse.x, state->screen_mouse.y > select_start.y ? state->screen_mouse.y - select_start.y : select_start.y - state->screen_mouse.y};
|
||||||
|
DrawRectangleLines(select1.x, select1.y, select2.x, select2.y, (Color){150,150,150,150});
|
||||||
|
state->selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void draw(){
|
virtual void draw(){
|
||||||
camera_delta = state->mouse_delta * (-1.0f/camera.zoom);
|
camera_delta = state->mouse_delta * (-1.0f/camera.zoom);
|
||||||
if(hovering()) drag();
|
if(hovering()) drag();
|
||||||
|
if(state->istate == InteractionState::HOVER_CANVAS || state->istate == InteractionState::DRAW_SELECTION) select();
|
||||||
|
|
||||||
float wheel = GetMouseWheelMove();
|
float wheel = GetMouseWheelMove();
|
||||||
if(wheel != 0){
|
if(wheel != 0){
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace VISEQ::GRAPH {
|
|||||||
|
|
||||||
std::shared_ptr<GraphItem> parent;
|
std::shared_ptr<GraphItem> parent;
|
||||||
|
|
||||||
|
bool hover_connect = false;
|
||||||
|
|
||||||
float radius = 5.0f;
|
float radius = 5.0f;
|
||||||
float orbit = 14.0f;
|
float orbit = 14.0f;
|
||||||
Vec2Df center_position;
|
Vec2Df center_position;
|
||||||
|
|||||||
+5
-1
@@ -6,7 +6,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace VISEQ::GRAPH {
|
namespace VISEQ::GRAPH {
|
||||||
class GraphItem{
|
class GraphItem : public std::enable_shared_from_this<GraphItem>{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GraphItem() {newId(-1);}
|
GraphItem() {newId(-1);}
|
||||||
@@ -20,6 +20,10 @@ namespace VISEQ::GRAPH {
|
|||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
|
std::shared_ptr<GraphItem> getptr(){
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
|
||||||
void newId(int start){
|
void newId(int start){
|
||||||
static int _id;
|
static int _id;
|
||||||
if(start > -1) _id = start;
|
if(start > -1) _id = start;
|
||||||
|
|||||||
+19
-1
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
|
#include "state.h"
|
||||||
#include "vmath.h"
|
#include "vmath.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
@@ -44,8 +45,12 @@ namespace VISEQ::GRAPH {
|
|||||||
EDGES::VEC_SPTR_Edge remove_edges;
|
EDGES::VEC_SPTR_Edge remove_edges;
|
||||||
EDGES::VEC_SPTR_Edge split_edges;
|
EDGES::VEC_SPTR_Edge split_edges;
|
||||||
|
|
||||||
|
VEC_SPTR_Node selected_nodes;
|
||||||
|
|
||||||
std::map<NODES::SPTR_Node, int> counter;
|
std::map<NODES::SPTR_Node, int> counter;
|
||||||
|
|
||||||
|
std::shared_ptr<APP::State> state = APP::State::get();
|
||||||
|
|
||||||
NODES::SPTR_Node getRandomNode(){
|
NODES::SPTR_Node getRandomNode(){
|
||||||
VEC_SPTR_GraphItem o;
|
VEC_SPTR_GraphItem o;
|
||||||
std::ranges::sample(nodes, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
|
std::ranges::sample(nodes, std::back_inserter(o), 1, std::mt19937{std::random_device{}()});
|
||||||
@@ -294,13 +299,26 @@ namespace VISEQ::GRAPH {
|
|||||||
Vec2Df nb_position = nb->position - ((nb->position - node->position)).norm() * 20.0f;
|
Vec2Df nb_position = nb->position - ((nb->position - node->position)).norm() * 20.0f;
|
||||||
DrawLineV(n_position, nb_position, VS_COLOR_PINK);
|
DrawLineV(n_position, nb_position, VS_COLOR_PINK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNodes(Vec2Df mouse_pos, Camera2D camera){
|
void drawNodes(Vec2Df mouse_pos, Camera2D camera){
|
||||||
for(auto n : nodes){
|
for(auto n : nodes){
|
||||||
|
if(CheckCollisionPointRec(n->position, state->selection)) {
|
||||||
|
n->in_selection_rect = true;
|
||||||
|
} else {
|
||||||
|
n->in_selection_rect = false;
|
||||||
|
}
|
||||||
|
if(state->istate == APP::InteractionState::DRAW_SELECTION && state->mouse_left.released){
|
||||||
|
if(CheckCollisionPointRec(n->position, state->selection)) {
|
||||||
|
n->selected = true;
|
||||||
|
n->in_selection_rect = false;
|
||||||
|
} else {
|
||||||
|
if(!state->keys_down.shift) n->selected = false;
|
||||||
|
}
|
||||||
|
state->selection = (Rectangle){0,0,0,0};
|
||||||
|
}
|
||||||
n->update();
|
n->update();
|
||||||
if(n->picked_up) drawNeighborLines(n, mouse_pos, camera);
|
if(n->picked_up) drawNeighborLines(n, mouse_pos, camera);
|
||||||
n->draw(mouse_pos, camera);
|
n->draw(mouse_pos, camera);
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ namespace VISEQ::BASE {
|
|||||||
Interactable() {}
|
Interactable() {}
|
||||||
virtual ~Interactable() {}
|
virtual ~Interactable() {}
|
||||||
|
|
||||||
|
bool in_selection_rect = false;
|
||||||
|
bool selected = false;
|
||||||
|
|
||||||
|
bool copied = false;
|
||||||
|
bool highlighted = false;
|
||||||
|
bool erase = false;
|
||||||
|
|
||||||
virtual bool hovering() = 0;
|
virtual bool hovering() = 0;
|
||||||
|
|
||||||
virtual bool clicked() {
|
virtual bool clicked() {
|
||||||
|
|||||||
+2
-2
@@ -166,8 +166,8 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
gate_color = ColorAlphaBlend(VS_COLOR_RED, (Color){232, 125, 62, (unsigned char)Clamp(255 - midi_gate_map, 0, 255)}, WHITE);
|
||||||
break;}
|
break;}
|
||||||
}
|
}
|
||||||
if(!picked_up && !selected && !in_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color);
|
if(!picked_up && !selected && !in_selection_rect && !hovering()) DrawCircle(position.x, position.y, radius, gate_color);
|
||||||
if(selected || picked_up || in_rect || hovering()) DrawCircle(position.x, position.y, radius, (Color){108, 153, 187, 255});
|
if(selected || picked_up || in_selection_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::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(distributionMode == Distribution::ROUNDROBIN) DrawCircle(position.x, position.y, radius/2.0f, VS_COLOR_YELLOW);
|
||||||
|
|||||||
@@ -21,16 +21,6 @@ namespace VISEQ::BASE {
|
|||||||
Vec2Df position;
|
Vec2Df position;
|
||||||
Vec2Df direction;
|
Vec2Df direction;
|
||||||
|
|
||||||
bool in_rect = false;
|
|
||||||
|
|
||||||
bool hover_connect = false;
|
|
||||||
bool connecting = false;
|
|
||||||
bool selected = false;
|
|
||||||
bool highlighted = false;
|
|
||||||
bool copied = false;
|
|
||||||
|
|
||||||
bool erase = false;
|
|
||||||
|
|
||||||
virtual void setPosition(Vec2Df _position) {position = _position;}
|
virtual void setPosition(Vec2Df _position) {position = _position;}
|
||||||
virtual Vec2Df getPosition() {return position;};
|
virtual Vec2Df getPosition() {return position;};
|
||||||
virtual void update(double frametime) {};
|
virtual void update(double frametime) {};
|
||||||
|
|||||||
+3
-3
@@ -25,7 +25,7 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
Node(Vec2Df p) : Draggable(p) {}
|
Node(Vec2Df p) : Draggable(p) {}
|
||||||
|
|
||||||
void addConnector() {
|
void addConnector() {
|
||||||
connectors.emplace_back(std::make_shared<Connector>(std::make_shared<GraphItem>(this), position, radius + 5.0f));
|
connectors.emplace_back(std::make_shared<Connector>(GraphItem::getptr(), position, radius + 5.0f));
|
||||||
connectors.back()->init();
|
connectors.back()->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ namespace VISEQ::GRAPH::NODES {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update() override{
|
void update() override{
|
||||||
|
if(hovering()) state->hovering = true;
|
||||||
if(pickedUp()) drag();
|
if(pickedUp() || selected) drag();
|
||||||
if(released()) putDown();
|
if(released()) putDown();
|
||||||
int free_connectors = 0;
|
int free_connectors = 0;
|
||||||
for(auto c : connectors){
|
for(auto c : connectors){
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ namespace VISEQ::APP{
|
|||||||
|
|
||||||
int node_mode = 0;
|
int node_mode = 0;
|
||||||
|
|
||||||
|
bool hovering = false;
|
||||||
|
|
||||||
MouseState mouse_left;
|
MouseState mouse_left;
|
||||||
MouseState mouse_right;
|
MouseState mouse_right;
|
||||||
MouseState mouse_middle;
|
MouseState mouse_middle;
|
||||||
@@ -55,6 +57,7 @@ namespace VISEQ::APP{
|
|||||||
ModifierKeys keys_pressed;
|
ModifierKeys keys_pressed;
|
||||||
ModifierKeys keys_released;
|
ModifierKeys keys_released;
|
||||||
|
|
||||||
|
Rectangle selection;
|
||||||
|
|
||||||
Vec2Df mouse_delta;
|
Vec2Df mouse_delta;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user