I've done something like this because I don't want to have an if structure and I want to use an anonymous union for event's parameters :
SystemEvent SFMLWindow::popEvent() {
sf::Event event;
if (m_window->pollEvent(event)) {
SystemEvent sys_event;
sys_event.eventID = event.type;
sys_event.origin = SystemEvent::Origin::Unspecified;
sys_event.type = SystemEvent::Type::NoType;
sys_event.paramType = SystemEvent::Type::NoType;
sys_event.size.width = event.size.width;
sys_event.size.height = event.size.height;
sys_event.key.code = event.key.code;
sys_event.key.alt = event.key.alt;
sys_event.key.control = event.key.control;
sys_event.key.system = event.key.system;
sys_event.key.shift = event.key.shift;
sys_event.text.unicode = event.text.unicode;
sys_event.mouseMove.x = event.mouseMove.x;
sys_event.mouseMove.y = event.mouseMove.y;
sys_event.mouseButton.x = event.mouseButton.x;
sys_event.mouseButton.y = event.mouseButton.y;
sys_event.mouseButton.button = event.mouseButton.button;
sys_event.mouseWheel.x = event.mouseWheel.x;
sys_event.mouseWheel.y = event.mouseWheel.y;
sys_event.mouseWheel.delta = event.mouseWheel.delta;
sys_event.joystickConnect.joystickId = event.joystickConnect.joystickId;
sys_event.joystickMove.joystickId = event.joystickMove.joystickId;
sys_event.joystickMove.axis = event.joystickMove.axis;
sys_event.joystickMove.position = event.joystickMove.position;
sys_event.joystickButton.joystickId = event.joystickButton.joystickId;
sys_event.joystickButton.button = event.joystickButton.button;
return sys_event;
} else {
SystemEvent sys_event;
sys_event.eventID = -1;
sys_event.origin = SystemEvent::Origin::NoEvent;
sys_event.type = SystemEvent::Type::NoType;
sys_event.paramType = SystemEvent::Type::NoType;
return sys_event;
}
And something like this to make custom events for widgets :
class Button {
Button (IRenderWindow *rw) : rw(rw)
bool isMouseInButton() {
Vec2f mousePos (sf::Mouse::getPosition(*rw).x, sf::Mouse::getPosition(*rw).y);
//On test si la position de la souris est dans le rectangle du bouton.
}
void setActionListener(ActionListener &al) {
Action a (odfaeg::Action::EVENT_TYPE::MOUSE_BUTTON_PRESSED_ONCE, sf::Mouse::Left);
Command cmd(a, FastDelegate<bool>(&Button::isMouseInbutton, this, sf::Vector2f(-1, -1)), FastDelegate<void> (&ActionListener::actionPerformed, &al, buttonID);
inputContextHandler.connect(buttonID, command);
}
InputContextHandler inputContextHandler;
IRenderWindow *rw;
}
I don't know if it's the best way to do that but that's the way used by the java language.
If the user pressed the button. (if he clicked on the button area)
But I need to pass the a pointer (or a reference) of the window, maybe you can pass the window id into the sf::Event structure, rather than set up a focus, this is how SDL does, and, how do you plan to manage multiple screen ?
You need to collect events from both screens, so, from multiple windows, you need to pass the screen id and the window id to the event structure.