SuperTuxKart
Loading...
Searching...
No Matches
event_handler.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2010-2015 Marianne Gagnon
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef HEADER_EVENT_HANDLER_HPP
19#define HEADER_EVENT_HANDLER_HPP
20
21#include <vector2d.h>
22#include <IEventReceiver.h>
23#include "input/input.hpp"
24#include "utils/leak_check.hpp"
25
29namespace GUIEngine
30{
31
35 enum EventPropagation
36 {
37 EVENT_BLOCK,
38 EVENT_BLOCK_BUT_HANDLED,
39 EVENT_LET
40 };
41
42 enum NavigationDirection
43 {
44 NAV_LEFT,
45 NAV_RIGHT,
46 NAV_UP,
47 NAV_DOWN
48 };
49
50 class Widget;
51
65 class EventHandler : public irr::IEventReceiver
66 {
71
72 EventPropagation onGUIEvent(const irr::SEvent& event);
73 EventPropagation onWidgetActivated(Widget* w, const int playerID, Input::InputType type);
74 void sendNavigationEvent(const NavigationDirection nav, const int playerID);
75 void navigate(const NavigationDirection nav, const int playerID);
76
82 void sendEventToUser(Widget* widget, std::string& name, const int playerID);
83
85 irr::core::vector2di m_mouse_pos;
86
87 public:
88
89 LEAK_CHECK()
90
92 ~EventHandler();
93
98 bool OnEvent (const irr::SEvent &event);
99
105 void processGUIAction(const PlayerAction action, int deviceID, const unsigned int value,
106 Input::InputType type, const int playerID);
107
109 const irr::core::vector2di& getMousePos() const { return m_mouse_pos; }
110
112 static EventHandler* get();
113 static void deallocate();
114
115 void setAcceptEvents(bool value) { m_accept_events = value; }
116 int findIDClosestWidget(const NavigationDirection nav, const int playerID,
117 Widget* w, bool ignore_disabled, int recursion_counter=1);
118 };
119
120}
121
122#endif
Class to handle irrLicht events (GUI and input as well)
Definition: event_handler.hpp:66
int findIDClosestWidget(const NavigationDirection nav, const int playerID, Widget *w, bool ignore_disabled, int recursion_counter=1)
This function use simple heuristic to find the closest widget in the requested direction,...
Definition: event_handler.cpp:516
void processGUIAction(const PlayerAction action, int deviceID, const unsigned int value, Input::InputType type, const int playerID)
When the input module is done processing an input and mapped it to an action, and this action needs t...
Definition: event_handler.cpp:263
static EventHandler * get()
singleton access
Definition: event_handler.cpp:343
void sendEventToUser(Widget *widget, std::string &name, const int playerID)
send an event to the GUI module user's event callback
Definition: event_handler.cpp:707
irr::core::vector2di m_mouse_pos
Last position of the mouse cursor.
Definition: event_handler.hpp:85
const irr::core::vector2di & getMousePos() const
Get the mouse position.
Definition: event_handler.hpp:109
void navigate(const NavigationDirection nav, const int playerID)
Focus the next widget downards, upwards, leftwards or rightwards.
Definition: event_handler.cpp:459
bool OnEvent(const irr::SEvent &event)
All irrLicht events will go through this (input as well GUI; input events are immediately delegated t...
Definition: event_handler.cpp:70
bool m_accept_events
This variable is used to ignore events during the initial load screen, so that a player cannot trigge...
Definition: event_handler.hpp:70
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:117
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
Definition: input.hpp:35