Implemented an initial cut at the event router. Its job is to take the random events from SFML and translate them into nice clean orderly events to the Gui::FSM.

This commit is contained in:
Zed A. Shaw 2025-06-04 12:19:24 -04:00
parent 5c47a0151c
commit 0674908e49
8 changed files with 184 additions and 6 deletions

86
event_router.cpp Normal file
View file

@ -0,0 +1,86 @@
#define FSM_DEBUG 1
#include "event_router.hpp"
#include "dbc.hpp"
namespace routing {
using enum Event;
using enum State;
void Router::process_window(sf::RenderWindow& window) {
(void)window;
}
void Router::event(Event ev) {
switch($state) {
FSM_STATE(State, START, ev);
FSM_STATE(State, IDLE, ev);
FSM_STATE(State, MOUSE_ACTIVE, ev);
FSM_STATE(State, MOUSE_MOVING, ev);
}
}
void Router::START(Event ) {
state(State::IDLE);
}
void Router::IDLE(Event ev) {
switch(ev) {
case MOUSE_DOWN:
state(State::MOUSE_ACTIVE);
break;
case MOUSE_UP:
dbc::log("mouse up in IDLE");
break;
case MOUSE_MOVE:
dbc::log("mouse move, send moved event");
break;
case KEY_PRESS:
dbc::log("key pressed");
break;
default:
dbc::sentinel("invalid event");
}
}
void Router::MOUSE_ACTIVE(Event ev) {
switch(ev) {
case MOUSE_DOWN:
dbc::log("mouse down in MOUSE_ACTIVE");
break;
case MOUSE_UP:
dbc::log("mouse up, send click event");
state(State::IDLE);
break;
case MOUSE_MOVE:
state(State::MOUSE_MOVING);
break;
case KEY_PRESS:
dbc::log("send the key but cancel");
state(State::IDLE);
break;
default:
dbc::sentinel("invalid event");
}
}
void Router::MOUSE_MOVING(Event ev) {
switch(ev) {
case MOUSE_DOWN:
dbc::log("mouse down in MOUSE_MOVING state");
break;
case MOUSE_UP:
dbc::log("mouse up, send drop event");
state(State::IDLE);
break;
case MOUSE_MOVE:
dbc::log("mouse move, send drag event");
break;
case KEY_PRESS:
dbc::log("send the key but cancel");
state(State::IDLE);
break;
default:
dbc::sentinel("invalid event");
}
}
}