FifeGUI 0.2.0
A C++ GUI library designed for games.
backends/sdl2/input.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_BACKENDS_SDL_SDLINPUT_HPP_
6#define INCLUDE_FIFECHAN_BACKENDS_SDL_SDLINPUT_HPP_
7
8#include <SDL2/SDL.h>
9
10#include <queue>
11
12#include "fifechan/input.hpp"
13#include "fifechan/keyinput.hpp"
14#include "fifechan/mouseinput.hpp"
15#include "fifechan/platform.hpp"
16
17namespace fcn
18{
19 class Key;
20}
21
22namespace fcn::sdl2
23{
24
30 class FIFEGUI_EXT_API Input : public fcn::Input
31 {
32 public:
36 Input();
37
44 virtual void pushInput(SDL_Event event);
45
51 void _pollInput() override { }
52
53 // Inherited from Input
54
55 bool isKeyQueueEmpty() override;
56
57 KeyInput dequeueKeyInput() override;
58
59 bool isMouseQueueEmpty() override;
60
61 MouseInput dequeueMouseInput() override;
62
63 protected:
70 MouseInput::Button convertMouseButton(int button);
71
79 int convertSDLEventToFifechanKeyValue(SDL_Event event);
80
82 std::queue<KeyInput> mKeyInputQueue;
83
85 std::queue<MouseInput> mMouseInputQueue;
86
88 bool mMouseDown{false};
89
91 bool mMouseInWindow{false};
92 };
93} // namespace fcn::sdl2
94
95#endif // INCLUDE_FIFECHAN_BACKENDS_SDL_SDLINPUT_HPP_
Abstract interface for polling user input devices.
Definition input.hpp:28
Internal class representing raw keyboard input data.
Definition keyinput.hpp:28
Represents a keyboard key or character code.
Definition key.hpp:20
Internal class representing raw mouse input data.
Input()
Constructor.
Definition input.cpp:15
void _pollInput() override
Polls all input.
std::queue< KeyInput > mKeyInputQueue
Queue of key inputs waiting to be processed.
virtual void pushInput(SDL_Event event)
Pushes an SDL event.
Definition input.cpp:55
std::queue< MouseInput > mMouseInputQueue
Queue of mouse inputs waiting to be processed.
bool mMouseDown
True if a mouse button is currently held down.
bool mMouseInWindow
True if the mouse cursor is currently within the application window.
Unified header for the SDL backend.