Files
viseq/src/state.h
T
2026-06-24 11:04:28 +02:00

105 lines
2.6 KiB
C++

#pragma once
#include "interaction-event.h"
#include "nlohmann/json.hpp"
#include "raylib.h"
#include "vmath.h"
#include <deque>
#include <memory>
#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
namespace VISEQ::APP{
struct AppSettings{
int width;
int height;
float grid;
float bpm;
float fps;
float speed = 16.0f;
int gui_selected_midi_out;
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}};
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(AppSettings, width, height, grid, bpm, fps, speed, gui_selected_midi_out)
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};
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"};
struct MouseState{
bool down = false;
bool clicked = false;
bool released = false;
};
struct ModifierKeys{
bool ctrl = false;
bool shift = false;
bool alt = false;
};
class State{
public:
State(){}
State(State &state) = delete;
void operator=(const State &) = delete;
AppSettings settings;
Vec2Df raw_mouse;
Vec2Df screen_mouse;
Vec2Df mod_mouse;
InteractionState istate = HOVER_CANVAS;
InteractionState old_istate = HOVER_CANVAS;
int node_mode = 0;
bool context_menu = false;
bool hovering = false;
int mouse_z = 0;
MouseState mouse_left;
MouseState mouse_right;
MouseState mouse_middle;
ModifierKeys keys_down;
ModifierKeys keys_pressed;
ModifierKeys keys_released;
Rectangle selection;
Rectangle bounding_box;
Vec2Df mouse_delta;
Vec2Df selection_origin;
Color mode_color = settings.mode_colors[0];
void pushEvent(InteractionEvent e);
InteractionEvent pullEvent();
void update(Camera2D camera);
inline static std::shared_ptr<State> instance;
static std::shared_ptr<State> get();
std::deque<InteractionEvent> event_queue;
};
}
namespace VISEQ{
using IState = VISEQ::APP::InteractionState;
}