3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "util/numeric.h"
22 #include "inputhandler.h"
23 #include "mainmenumanager.h"
25 bool MyEventReceiver::OnEvent(const SEvent &event)
28 React to nothing here if a menu is active
31 #ifdef HAVE_TOUCHSCREENGUI
32 if (m_touchscreengui) {
33 m_touchscreengui->Toggle(false);
36 return g_menumgr.preprocessEvent(event);
39 // Remember whether each key is down or up
40 if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
41 const KeyPress &keyCode = event.KeyInput;
42 if (keysListenedFor[keyCode]) {
43 if (event.KeyInput.PressedDown) {
44 keyIsDown.set(keyCode);
45 keyWasDown.set(keyCode);
47 keyIsDown.unset(keyCode);
53 #ifdef HAVE_TOUCHSCREENGUI
54 // case of touchscreengui we have to handle different events
55 if (m_touchscreengui && event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
56 m_touchscreengui->translateEvent(event);
61 if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
62 /* TODO add a check like:
63 if (event.JoystickEvent != joystick_we_listen_for)
66 return joystick->handleEvent(event.JoystickEvent);
68 // handle mouse events
69 if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
72 middle_active = false;
75 left_active = event.MouseInput.isLeftPressed();
76 middle_active = event.MouseInput.isMiddlePressed();
77 right_active = event.MouseInput.isRightPressed();
79 if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
82 if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN) {
85 if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
88 if (event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) {
91 if (event.MouseInput.Event == EMIE_MOUSE_WHEEL) {
92 mouse_wheel += event.MouseInput.Wheel;
95 } else if (event.EventType == irr::EET_LOG_TEXT_EVENT) {
96 static const LogLevel irr_loglev_conv[] = {
97 LL_VERBOSE, // ELL_DEBUG
98 LL_INFO, // ELL_INFORMATION
99 LL_WARNING, // ELL_WARNING
100 LL_ERROR, // ELL_ERROR
103 assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
104 g_logger.log(irr_loglev_conv[event.LogEvent.Level],
105 std::string("Irrlicht: ") + event.LogEvent.Text);
108 /* always return false in order to continue processing events */
115 s32 RandomInputHandler::Rand(s32 min, s32 max)
117 return (myrand() % (max - min + 1)) + min;