Dragging and selecting works. Dragging the selection not yet.
This commit is contained in:
+9
-3
@@ -3,8 +3,10 @@
|
||||
#include "clipboard.h"
|
||||
#include "datatypes.h"
|
||||
#include "graph-manager.h"
|
||||
#include "interaction-event.h"
|
||||
#include "midi-node.h"
|
||||
#include "mouse.h"
|
||||
#include "moveable.h"
|
||||
#include "node.h"
|
||||
#include "raylib.h"
|
||||
#include "signal-manager.h"
|
||||
@@ -61,16 +63,18 @@ namespace VISEQ::APP {
|
||||
auto e = event_queue.front();
|
||||
std::cout << e.action << " " << e.item->z_index << std::endl;
|
||||
|
||||
if(e.item->getType() == GraphItemType::NODE || e.item->getType() == GraphItemType::CONNECTOR) {
|
||||
if(e.item->getType() == GraphItemType::NODE || e.item->getType() == GraphItemType::CONNECTOR || e.item->getType() == GraphItemType::CANVAS) {
|
||||
switch(e.action){
|
||||
case VISEQ::APP::Interaction::PICKUP:
|
||||
{
|
||||
e.item->pickUp();
|
||||
goto exit_loop;
|
||||
break;
|
||||
}
|
||||
case VISEQ::APP::Interaction::DRAG:
|
||||
{
|
||||
e.item->drag();
|
||||
goto exit_loop;
|
||||
break;
|
||||
}
|
||||
case VISEQ::APP::Interaction::PUTDOWN:
|
||||
@@ -78,11 +82,13 @@ namespace VISEQ::APP {
|
||||
e.item->putDown();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
event_queue.pop();
|
||||
event_queue.pop_front();
|
||||
}
|
||||
exit_loop:
|
||||
event_queue.clear();
|
||||
}
|
||||
|
||||
void update(){
|
||||
|
||||
+28
-25
@@ -6,9 +6,10 @@
|
||||
#include "draggable.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include <memory>
|
||||
|
||||
namespace VISEQ::APP::CANVAS {
|
||||
class Canvas : public BASE::Draggable {
|
||||
class Canvas : public BASE::Draggable, public std::enable_shared_from_this<Canvas> {
|
||||
public:
|
||||
Canvas() {}
|
||||
|
||||
@@ -21,9 +22,21 @@ namespace VISEQ::APP::CANVAS {
|
||||
}
|
||||
|
||||
virtual void drag() override {
|
||||
if(state->mouse_right.down) {
|
||||
camera.target = Vector2Add(camera.target, camera_delta);
|
||||
}
|
||||
Vec2Df select1 = {SCREEN_MOUSE.x > select_start.x ? select_start.x : SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? select_start.y : SCREEN_MOUSE.y};
|
||||
Vec2Df select2 = {SCREEN_MOUSE.x > select_start.x ? SCREEN_MOUSE.x - select_start.x : select_start.x - SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? SCREEN_MOUSE.y - select_start.y : select_start.y - SCREEN_MOUSE.y};
|
||||
state->selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||
DrawRectangleLines(state->selection.x, state->selection.y, state->selection.width, state->selection.height, (Color){150,150,150,150});
|
||||
}
|
||||
|
||||
virtual void pickUp() override {
|
||||
BASE::Draggable::pickUp();
|
||||
state->selection = (Rectangle){0,0,0,0};
|
||||
select_start = SCREEN_MOUSE;
|
||||
}
|
||||
|
||||
virtual void putDown() override {
|
||||
BASE::Draggable::putDown();
|
||||
state->selection = (Rectangle){0,0,0,0};
|
||||
}
|
||||
|
||||
virtual void drawStart(){
|
||||
@@ -38,29 +51,20 @@ namespace VISEQ::APP::CANVAS {
|
||||
return GRAPH::GraphItemType::CANVAS;
|
||||
}
|
||||
|
||||
void makeSelection(){
|
||||
if(MOUSE_LEFT.clicked){
|
||||
state->selection = (Rectangle){0,0,0,0};
|
||||
select_start = SCREEN_MOUSE;
|
||||
STATE = IState::DRAW_SELECTION;
|
||||
}
|
||||
|
||||
if(MOUSE_LEFT.down){
|
||||
Vec2Df select1 = {SCREEN_MOUSE.x > select_start.x ? select_start.x : SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? select_start.y : SCREEN_MOUSE.y};
|
||||
Vec2Df select2 = {SCREEN_MOUSE.x > select_start.x ? SCREEN_MOUSE.x - select_start.x : select_start.x - SCREEN_MOUSE.x, SCREEN_MOUSE.y > select_start.y ? SCREEN_MOUSE.y - select_start.y : select_start.y - SCREEN_MOUSE.y};
|
||||
state->selection = (Rectangle){select1.x, select1.y, select2.x, select2.y};
|
||||
}
|
||||
|
||||
if(MOUSE_LEFT.released){
|
||||
STATE = IState::HOVER_CANVAS;
|
||||
state->selection = (Rectangle){0,0,0,0};
|
||||
}
|
||||
std::shared_ptr<Canvas> getPtr(){
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
virtual void update() override {
|
||||
camera_delta = state->mouse_delta * (-1.0f/camera.zoom);
|
||||
if(hovering()) drag();
|
||||
if(STATE == IState::HOVER_CANVAS || STATE == IState::DRAW_SELECTION) makeSelection();
|
||||
|
||||
if(state->mouse_right.down) {
|
||||
camera.target = Vector2Add(camera.target, camera_delta);
|
||||
}
|
||||
|
||||
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
|
||||
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
|
||||
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
|
||||
|
||||
float wheel = GetMouseWheelMove();
|
||||
if(wheel != 0){
|
||||
@@ -74,8 +78,7 @@ namespace VISEQ::APP::CANVAS {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void draw(){
|
||||
if(STATE == IState::DRAW_SELECTION) DrawRectangleLines(state->selection.x, state->selection.y, state->selection.width, state->selection.height, (Color){150,150,150,150});
|
||||
virtual void draw() {
|
||||
for(int x = -SETTINGS.grid*100; x < SETTINGS.grid*100; x+=SETTINGS.grid){
|
||||
for(int y = -SETTINGS.grid*100; y < SETTINGS.grid*100; y+=SETTINGS.grid){
|
||||
DrawPixel(x, y, (Color){130,130,130,200});
|
||||
|
||||
+3
-2
@@ -38,8 +38,9 @@ namespace VISEQ::BASE {
|
||||
}
|
||||
|
||||
virtual void drag() override {
|
||||
state->selection_origin = position;
|
||||
if(KEYS_PRESSED.ctrl){
|
||||
selection_offset = position - state->hover_position;
|
||||
selection_offset = position - state->selection_origin;
|
||||
}
|
||||
if(KEYS_DOWN.ctrl){
|
||||
position = MOD_MOUSE + selection_offset;
|
||||
@@ -53,7 +54,7 @@ namespace VISEQ::BASE {
|
||||
}
|
||||
|
||||
virtual void select() override {
|
||||
if(STATE == IState::DRAW_SELECTION) in_selection_rect = CheckCollisionPointRec(position, state->selection);
|
||||
in_selection_rect = CheckCollisionPointRec(position, state->selection);
|
||||
if(MOUSE_LEFT.released) selected = (KEYS_DOWN.shift && selected) || in_selection_rect;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -376,7 +376,7 @@ namespace VISEQ::GRAPH {
|
||||
|
||||
void drawNodes(Vec2Df mouse_pos, Camera2D camera){
|
||||
for(auto n : nodes){
|
||||
if(KEYS_PRESSED.ctrl && n->hovering()) state->hover_position = n->position;
|
||||
if(KEYS_PRESSED.ctrl && n->hovering()) state->selection_origin = n->position;
|
||||
}
|
||||
BASE::Interactable::z_hovering = -1;
|
||||
for(auto n : nodes){
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "interactable.h"
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
|
||||
namespace VISEQ::APP{
|
||||
|
||||
enum Interaction {HOVER, CLICK, HOLD, RELEASE, PICKUP, DRAG, PUTDOWN};
|
||||
enum Interaction {NONE, HOVER, CLICK, HOLD, RELEASE, PICKUP, DRAG, PUTDOWN, SELECTED};
|
||||
|
||||
struct InteractionEvent{
|
||||
std::shared_ptr<BASE::Interactable> item;
|
||||
Interaction action;
|
||||
};
|
||||
|
||||
inline static std::queue<VISEQ::APP::InteractionEvent> event_queue;
|
||||
inline static std::deque<VISEQ::APP::InteractionEvent> event_queue;
|
||||
}
|
||||
|
||||
+13
-13
@@ -31,7 +31,7 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
VISEQ::APP::CANVAS::Canvas canvas;
|
||||
std::shared_ptr<VISEQ::APP::CANVAS::Canvas> canvas = std::make_shared<VISEQ::APP::CANVAS::Canvas>();
|
||||
VISEQ::APP::AppManager app;
|
||||
|
||||
std::shared_ptr<VISEQ::APP::State> state = VISEQ::APP::State::get();
|
||||
@@ -74,10 +74,10 @@ int main(){
|
||||
|
||||
SetTargetFPS(state->settings.fps);
|
||||
|
||||
canvas.camera.target = (Vector2){ state->settings.width/2.0f, state->settings.height/2.0f };
|
||||
canvas.camera.offset = (Vector2){ state->settings.width/2.0f, state->settings.height/2.0f };
|
||||
canvas.camera.rotation = 0.0f;
|
||||
canvas.camera.zoom = 1.0f;
|
||||
canvas->camera.target = (Vector2){ state->settings.width/2.0f, state->settings.height/2.0f };
|
||||
canvas->camera.offset = (Vector2){ state->settings.width/2.0f, state->settings.height/2.0f };
|
||||
canvas->camera.rotation = 0.0f;
|
||||
canvas->camera.zoom = 1.0f;
|
||||
|
||||
if(std::filesystem::exists("state.json")){
|
||||
std::ifstream f("state.json");
|
||||
@@ -176,9 +176,9 @@ int main(){
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground((Color){46,46,46});
|
||||
canvas.drawStart();
|
||||
canvas->drawStart();
|
||||
|
||||
state->update(canvas.camera);
|
||||
state->update(canvas->camera);
|
||||
|
||||
/*else if(IsKeyDown(KEY_LEFT_SHIFT)){*/
|
||||
/* float steps = round((dragNode->neighbors.front()->position.dist(mouse_pos)) / state->settings.grid) * state->settings.grid;*/
|
||||
@@ -290,7 +290,7 @@ int main(){
|
||||
/* drag_distance = 0;*/
|
||||
/* }*/
|
||||
/* if(mouse_right_down) {*/
|
||||
/* canvas.camera.target = Vector2Add(canvas.camera.target, delta);*/
|
||||
/* canvas->camera.target = Vector2Add(canvas->camera.target, delta);*/
|
||||
/* drag_distance += delta.length();*/
|
||||
/* }*/
|
||||
/* if(mouse_right_released && drag_distance < 5) {*/
|
||||
@@ -490,14 +490,14 @@ int main(){
|
||||
/* }*/
|
||||
/*};*/
|
||||
|
||||
canvas.update();
|
||||
canvas->update();
|
||||
app.update();
|
||||
|
||||
canvas.draw();
|
||||
app.draw(SCREEN_MOUSE, canvas.camera);
|
||||
canvas.drawEnd();
|
||||
canvas->draw();
|
||||
app.draw(SCREEN_MOUSE, canvas->camera);
|
||||
canvas->drawEnd();
|
||||
|
||||
app.drawUI(SCREEN_MOUSE, canvas.camera);
|
||||
app.drawUI(SCREEN_MOUSE, canvas->camera);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ namespace VISEQ::GRAPH::NODES {
|
||||
break;}
|
||||
};
|
||||
if(midi_note < 0 ) midi_note = VISEQ::MIDI::Notes.size()-1;
|
||||
if(midi_note >= VISEQ::MIDI::Notes.size()) midi_note = 0;
|
||||
if(midi_note >= (int)VISEQ::MIDI::Notes.size()) midi_note = 0;
|
||||
|
||||
if(midi_cc < 0 ) midi_cc = 127;
|
||||
if(midi_cc > 127 ) midi_cc = 0;
|
||||
|
||||
+3
-1
@@ -68,10 +68,12 @@ namespace VISEQ::GRAPH::NODES {
|
||||
}
|
||||
|
||||
void update() override{
|
||||
|
||||
if(hovering() && clicked()) state->pushEvent({getPtr(), APP::Interaction::PICKUP});
|
||||
if(pickedUp()) state->pushEvent({getPtr(), APP::Interaction::DRAG});
|
||||
if(picked_up && released()) state->pushEvent({getPtr(), APP::Interaction::PUTDOWN});
|
||||
if(selected) state->pushEvent({getPtr(), APP::Interaction::SELECTED});
|
||||
|
||||
if(state->selection.width > 0) select();
|
||||
|
||||
int free_connectors = 0;
|
||||
for(auto c : connectors){
|
||||
|
||||
+12
-2
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "interaction-event.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "raylib.h"
|
||||
#include "vmath.h"
|
||||
#include <memory>
|
||||
@@ -78,10 +79,19 @@ namespace VISEQ::APP{
|
||||
|
||||
Vec2Df mouse_delta;
|
||||
|
||||
Vec2Df hover_position;
|
||||
Vec2Df selection_origin;
|
||||
|
||||
void pushEvent(InteractionEvent e){
|
||||
event_queue.push(e);
|
||||
event_queue.push_back(e);
|
||||
}
|
||||
|
||||
InteractionEvent pullEvent(){
|
||||
if(!event_queue.empty()){
|
||||
InteractionEvent e = event_queue.front();
|
||||
event_queue.pop_front();
|
||||
return e;
|
||||
}
|
||||
return {nullptr, Interaction::NONE};
|
||||
}
|
||||
|
||||
void update(Camera2D camera){
|
||||
|
||||
Reference in New Issue
Block a user