Files
viseq/src/state.h
T

105 lines
2.6 KiB
C++
Raw Normal View History

2024-11-14 00:55:09 +01:00
#pragma once
#include "interaction-event.h"
#include "nlohmann/json.hpp"
#include "raylib.h"
2024-11-14 00:55:09 +01:00
#include "vmath.h"
2026-06-24 11:04:28 +02:00
#include <deque>
2024-11-14 00:55:09 +01:00
#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
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;
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
};
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};
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;
};
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 00:55:09 +01:00
Vec2Df raw_mouse;
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;
InteractionState old_istate = HOVER_CANVAS;
int node_mode = 0;
2024-12-05 23:39:01 +01:00
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];
2026-06-24 11:04:28 +02:00
2026-01-06 02:44:18 +01:00
void pushEvent(InteractionEvent e);
InteractionEvent pullEvent();
void update(Camera2D camera);
2024-11-14 00:55:09 +01:00
inline static std::shared_ptr<State> instance;
2026-01-12 00:16:36 +01:00
static std::shared_ptr<State> get();
2026-05-04 18:40:00 +02:00
std::deque<InteractionEvent> event_queue;
2024-11-14 00:55:09 +01:00
};
}
namespace VISEQ{
using IState = VISEQ::APP::InteractionState;
}