2024-11-14 00:55:09 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-11-24 03:08:06 +01:00
|
|
|
#include "interaction-event.h"
|
2024-11-25 00:53:10 +01:00
|
|
|
#include "nlohmann/json.hpp"
|
2024-11-15 01:49:10 +01:00
|
|
|
#include "raylib.h"
|
2024-11-14 00:55:09 +01:00
|
|
|
#include "vmath.h"
|
|
|
|
|
#include <memory>
|
2024-11-24 03:08:06 +01:00
|
|
|
#include <queue>
|
2024-11-14 00:55:09 +01:00
|
|
|
|
2024-11-19 01:04:06 +01:00
|
|
|
#define STATE state->istate
|
|
|
|
|
#define SETTINGS state->settings
|
|
|
|
|
#define SCREEN_MOUSE state->screen_mouse
|
|
|
|
|
#define RAW_MOUSE state->raw_mouse
|
|
|
|
|
#define MOD_MOUSE state->mod_mouse
|
|
|
|
|
#define MOUSE_LEFT state->mouse_left
|
|
|
|
|
#define MOUSE_RIGHT state->mouse_right
|
|
|
|
|
#define MOUSE_MIDDLE state->mouse_middle
|
|
|
|
|
#define KEYS_DOWN state->keys_down
|
|
|
|
|
#define KEYS_PRESSED state->keys_pressed
|
|
|
|
|
#define KEYS_RELEASED state->keys_released
|
|
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
namespace VISEQ::APP{
|
|
|
|
|
|
|
|
|
|
struct AppSettings{
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
float grid;
|
|
|
|
|
float bpm;
|
|
|
|
|
float fps;
|
|
|
|
|
float speed = 16.0f;
|
|
|
|
|
int gui_selected_midi_out;
|
2024-12-15 03:17:10 +01:00
|
|
|
Color mode_colors[7] = {VS_COLOR_GREEN, VS_COLOR_SUN, VS_COLOR_PINK, VS_COLOR_ORANGE, VS_COLOR_PURPLE, VS_COLOR_LIGHTGREY, (Color){0,0,0,0}};
|
2024-11-14 00:55:09 +01:00
|
|
|
};
|
2024-11-14 01:37:16 +01:00
|
|
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(AppSettings, width, height, grid, bpm, fps, speed, gui_selected_midi_out)
|
2024-11-14 00:55:09 +01:00
|
|
|
|
2024-11-14 23:21:04 +01:00
|
|
|
enum InteractionState {HOVER_CANVAS, HOVER_NODE, HOVER_CONNECTOR, ADD_NODES_MENU, DRAG_NODE, CONNECT_NODE, DRAW_SELECTION, SCALE_SELECTION, DELETE_SELECTED_NODES, COPY_SELECTED_NODES, PASTE_SELECTED_NODES};
|
2024-11-24 03:08:06 +01:00
|
|
|
|
2024-11-17 02:40:31 +01:00
|
|
|
inline std::vector<std::string> state_string = {"HOVER_CANVAS"," HOVER_NODE"," HOVER_CONNECTOR"," ADD_NODES_MENU"," DRAG_NODE"," CONNECT_NODE"," DRAW_SELECTION"," SCALE_SELECTION"," DELETE_SELECTED_NODES"," COPY_SELECTED_NODES"," PASTE_SELECTED_NODES"};
|
|
|
|
|
|
2024-11-15 01:49:10 +01:00
|
|
|
struct MouseState{
|
|
|
|
|
bool down = false;
|
|
|
|
|
bool clicked = false;
|
|
|
|
|
bool released = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ModifierKeys{
|
|
|
|
|
bool ctrl = false;
|
|
|
|
|
bool shift = false;
|
|
|
|
|
bool alt = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
class State{
|
|
|
|
|
public:
|
|
|
|
|
State(){}
|
|
|
|
|
State(State &state) = delete;
|
|
|
|
|
void operator=(const State &) = delete;
|
|
|
|
|
|
|
|
|
|
AppSettings settings;
|
2024-11-14 01:37:16 +01:00
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
Vec2Df raw_mouse;
|
2024-11-14 01:37:16 +01:00
|
|
|
Vec2Df screen_mouse;
|
2024-11-14 00:55:09 +01:00
|
|
|
Vec2Df mod_mouse;
|
|
|
|
|
|
2024-11-14 23:21:04 +01:00
|
|
|
InteractionState istate = HOVER_CANVAS;
|
2024-11-17 02:40:31 +01:00
|
|
|
InteractionState old_istate = HOVER_CANVAS;
|
2024-11-24 03:08:06 +01:00
|
|
|
|
2024-11-14 01:37:16 +01:00
|
|
|
int node_mode = 0;
|
2024-12-05 23:39:01 +01:00
|
|
|
bool context_menu = false;
|
|
|
|
|
|
2024-11-16 00:29:01 +01:00
|
|
|
bool hovering = false;
|
2024-11-15 01:49:10 +01:00
|
|
|
|
2024-11-28 01:08:04 +01:00
|
|
|
int mouse_z = 0;
|
|
|
|
|
|
2024-11-15 01:49:10 +01:00
|
|
|
MouseState mouse_left;
|
|
|
|
|
MouseState mouse_right;
|
|
|
|
|
MouseState mouse_middle;
|
|
|
|
|
|
|
|
|
|
ModifierKeys keys_down;
|
|
|
|
|
ModifierKeys keys_pressed;
|
|
|
|
|
ModifierKeys keys_released;
|
|
|
|
|
|
2024-11-16 00:29:01 +01:00
|
|
|
Rectangle selection;
|
2024-11-30 02:54:40 +01:00
|
|
|
Rectangle bounding_box;
|
2024-11-15 01:49:10 +01:00
|
|
|
|
|
|
|
|
Vec2Df mouse_delta;
|
2024-11-19 01:04:06 +01:00
|
|
|
|
2024-11-25 00:53:10 +01:00
|
|
|
Vec2Df selection_origin;
|
2024-12-15 03:17:10 +01:00
|
|
|
|
|
|
|
|
Color mode_color = settings.mode_colors[0];
|
2024-11-24 03:08:06 +01:00
|
|
|
|
|
|
|
|
void pushEvent(InteractionEvent e){
|
2024-11-25 00:53:10 +01:00
|
|
|
event_queue.push_back(e);
|
2024-11-24 03:08:06 +01:00
|
|
|
}
|
2024-11-19 01:04:06 +01:00
|
|
|
|
2024-11-25 00:53:10 +01:00
|
|
|
InteractionEvent pullEvent(){
|
|
|
|
|
if(!event_queue.empty()){
|
|
|
|
|
InteractionEvent e = event_queue.front();
|
|
|
|
|
event_queue.pop_front();
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
return {nullptr, Interaction::NONE};
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 01:49:10 +01:00
|
|
|
void update(Camera2D camera){
|
2024-11-24 03:08:06 +01:00
|
|
|
|
2024-11-17 02:40:31 +01:00
|
|
|
if(istate != old_istate) std::cout << state_string[istate] << std::endl;
|
|
|
|
|
|
2024-11-15 01:49:10 +01:00
|
|
|
mouse_delta = {GetMouseDelta().x, GetMouseDelta().y};
|
|
|
|
|
|
|
|
|
|
settings.speed = (settings.grid * 16.0f) * (settings.bpm / 120.f);
|
|
|
|
|
|
|
|
|
|
Vector2 mp = GetScreenToWorld2D(GetMousePosition(), camera);
|
|
|
|
|
Vec2Df mouse_pos = {(float)mp.x, (float)mp.y};
|
|
|
|
|
|
|
|
|
|
mouse_left.down = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
|
|
|
|
mouse_left.clicked = IsMouseButtonPressed(MOUSE_BUTTON_LEFT);
|
|
|
|
|
mouse_left.released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
|
|
|
|
|
|
|
|
|
mouse_right.down = IsMouseButtonDown(MOUSE_BUTTON_RIGHT);
|
|
|
|
|
mouse_right.clicked = IsMouseButtonPressed(MOUSE_BUTTON_RIGHT);
|
|
|
|
|
mouse_right.released = IsMouseButtonReleased(MOUSE_BUTTON_RIGHT);
|
|
|
|
|
|
|
|
|
|
keys_down.ctrl = IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL);
|
|
|
|
|
keys_down.shift = IsKeyDown(KEY_LEFT_SHIFT) || IsKeyDown(KEY_RIGHT_SHIFT);
|
|
|
|
|
keys_down.alt = IsKeyDown(KEY_LEFT_ALT) || IsKeyDown(KEY_RIGHT_ALT);
|
|
|
|
|
|
|
|
|
|
keys_pressed.ctrl = IsKeyPressed(KEY_LEFT_CONTROL) || IsKeyPressed(KEY_RIGHT_CONTROL);
|
|
|
|
|
keys_pressed.shift = IsKeyPressed(KEY_LEFT_SHIFT) || IsKeyPressed(KEY_RIGHT_SHIFT);
|
|
|
|
|
keys_pressed.alt = IsKeyPressed(KEY_LEFT_ALT) || IsKeyPressed(KEY_RIGHT_ALT);
|
|
|
|
|
|
|
|
|
|
keys_released.ctrl = IsKeyReleased(KEY_LEFT_CONTROL) || IsKeyReleased(KEY_RIGHT_CONTROL);
|
|
|
|
|
keys_released.shift = IsKeyReleased(KEY_LEFT_SHIFT) || IsKeyReleased(KEY_RIGHT_SHIFT);
|
|
|
|
|
keys_released.alt = IsKeyReleased(KEY_LEFT_ALT) || IsKeyReleased(KEY_RIGHT_ALT);
|
|
|
|
|
|
2024-12-11 01:16:06 +01:00
|
|
|
screen_mouse = {round(mouse_pos.x), round(mouse_pos.y)};
|
2024-11-15 01:49:10 +01:00
|
|
|
raw_mouse = {GetMousePosition().x, GetMousePosition().y};
|
2024-12-11 01:16:06 +01:00
|
|
|
mod_mouse = {round(mouse_pos.x), round(mouse_pos.y)};
|
2024-12-15 03:17:10 +01:00
|
|
|
|
|
|
|
|
mode_color = settings.mode_colors[node_mode];
|
2024-11-15 01:49:10 +01:00
|
|
|
|
|
|
|
|
if(keys_down.ctrl) {
|
|
|
|
|
mod_mouse.x = round(mouse_pos.x / settings.grid) * settings.grid;
|
|
|
|
|
mod_mouse.y = round(mouse_pos.y / settings.grid) * settings.grid;
|
|
|
|
|
}
|
2024-11-17 02:40:31 +01:00
|
|
|
old_istate = istate;
|
2024-11-15 01:49:10 +01:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 00:55:09 +01:00
|
|
|
inline static std::shared_ptr<State> instance;
|
|
|
|
|
static std::shared_ptr<State> get() {
|
|
|
|
|
if(!instance){
|
|
|
|
|
instance.reset(new State());
|
|
|
|
|
}
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-11-19 01:04:06 +01:00
|
|
|
|
|
|
|
|
namespace VISEQ{
|
|
|
|
|
using IState = VISEQ::APP::InteractionState;
|
|
|
|
|
}
|