29 #include <SDL_timer.h> 52 const EventsManager::RequestHandler EventsManager::_requestHandler[
kITCEventMAX] = {
54 &EventsManager::requestCallInMainThread,
55 &EventsManager::requestRebuildGLContainer,
56 &EventsManager::requestDestroyGLContainer
60 EventsManager::EventsManager() : _ready(false), _quitRequested(false), _doQuit(false),
61 _fatalError(false), _queueSize(0), _fullQueue(false), _repeat(false), _repeatCounter(0),
62 _textInputCounter(0) {
81 SDL_RegisterEvents(1);
110 while (SDL_PollEvent(0));
137 return SDL_GetTicks();
143 (event.key.keysym.mod & (KMOD_CTRL | KMOD_GUI)) &&
144 (event.key.keysym.sym == SDLK_q))) {
151 if ((event.type ==
kEventKeyDown) && (event.key.keysym.mod & KMOD_ALT) &&
152 (event.key.keysym.sym == SDLK_F4)) {
163 if ((event.key.keysym.mod & KMOD_ALT) && event.key.keysym.sym == SDLK_RETURN) {
166 }
else if ((event.key.keysym.mod & KMOD_ALT) && event.key.keysym.sym == SDLK_m) {
169 }
else if ((event.key.keysym.mod & KMOD_ALT) && event.key.keysym.sym == SDLK_s) {
193 Request &request = *static_cast<Request *>(event.user.data1);
195 if (request._type != itcEvent)
203 (this->*handler)(request);
206 request.signalReply();
216 while (SDL_PollEvent(&event)) {
267 int result = SDL_PushEvent(&event);
291 SDL_StartTextInput();
303 return event.text.text;
306 uint32 sym =
event.key.keysym.sym;
356 const int joyCount = SDL_NumJoysticks();
361 for (
int i = 0; i < joyCount; i++)
364 SDL_JoystickEventState(SDL_ENABLE);
368 SDL_JoystickEventState(SDL_DISABLE);
386 if ((*j)->getName() == name)
bool pushEvent(Event &event)
Push an event onto the events queue.
Inter-thread request events.
bool parseITC(const Event &event)
Look for inter-thread communication.
bool ready() const
Was the events subsystem successfully initialized?
The global graphics manager.
void runMainLoop()
Run the main loop.
#define START_IGNORE_IMPLICIT_FALLTHROUGH
A class holding an UTF-8 string.
void requestRebuildGLContainer(Request &request)
The global config manager.
Joystick/Gamepad handling.
void init()
Initialize the events subsystem.
bool isMainThread()
Returns true if called from the main thread, false otherwise.
RequestDataGLContainer _glContainer
Inter-thread communication.
#define NotificationMan
Shortcut for accessing the notification manager.
Graphics::GLContainer * glContainer
The global window manager.
void enableTextInput(bool textInput=true)
Enable/Disable the text input.
#define TimerMan
Shortcut for accessing the timer manager.
bool quitRequested() const
Was an engine quit requested?
void requestDestroyGLContainer(Request &request)
bool isQueueFull() const
Is the event queue full?
Common::Mutex _eventQueueMutex
Exception that provides a stack of explanations.
bool _ready
Was the events subsystem successfully initialized?
Common::UString getTextInput(const Event &event)
Return the text that was input with keyboard, in UTF-8 encoding.
A container of OpenGL elements.
bool wait(uint32 timeout=0)
Keyboard key was pressed.
The notification manager, handling all notifications.
uint32 getTimestamp() const
Return the number of milliseconds the application is running.
const MainThreadCallerFunctor * caller
Basic exceptions to throw.
Threading system helpers.
void raiseFatalError()
Raise a fatal engine error.
Utility templates and functions.
Common::Condition _queueProcessed
#define DECLARE_SINGLETON(T)
Note that you need to use this macro from the global namespace.
The global events manager.
void(EventsManager::* RequestHandler)(Request &)
ITCEvent
Specific type of the inter-thread communication.
Joystick * getJoystickByIndex(size_t index) const
Return the joystick with that index.
void requestQuit()
Request an engine quit.
void requestCallInMainThread(Request &request)
void reset()
Completely reset the events manager.
static const RequestHandler _requestHandler[kITCEventMAX]
Pointer to the request handler.
void deinitJoysticks()
Deinitialize the available joysticks/gamepads.
Application quit was requested.
void doQuit()
Initiate the actual quitting process.
Convenience class that locks a mutex on creation and unlocks it on destruction.
#define STOP_IGNORE_IMPLICIT_FALLTHROUGH
#define WindowMan
Shortcut for accessing the window manager.
bool pollEvent(Event &event)
Get an event from the events queue.
void delay(uint32 ms)
Sleep that number of milliseconds.
void initJoysticks()
Initialize the available joysticks/gamepads.
void enforceMainThread()
Throws an Exception if called from a non-main thread.
void deinit()
Deinitialize the events subsystem.
Joystick * getJoystickByName(const Common::UString &name) const
Return the first joystick with that name.
bool parseEventGraphics(const Event &event)
Look for graphics events.
The global timer manager.
#define RequestMan
Shortcut for accessing the request manager.
bool parseEventQuit(const Event &event)
Look for quit events.
size_t getJoystickCount() const
Return the number of available joysticks.
Compiler-specific defines to mark an implicit switch-case fallthrough.
A request, carrying inter-thread communication.
bool _quitRequested
Was an engine quit requested?
bool fatalErrorRaised() const
Was a fatal engine error raised?
bool _doQuit
Are we currently in the process of quitting?
void enableKeyRepeat(bool repeat=true)
Enable/Disable repeated key events.
void flushEvents()
Clear the event queue, ignore all unhandled events.
RequestCallInMainThread _callInMainThread
static bool isCntrl(uint32 c)
Is the character an ASCII control character?
Keyboard key was released.
#define GfxMan
Shortcut for accessing the graphics manager.