From 15ffc983695bcd46d0de75deeef9047caff57133 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 9 Jan 2019 22:04:50 +0100 Subject: [PATCH] Detect if there is touch device available --- lib/irrlicht/include/IrrlichtDevice.h | 3 ++ .../source/Irrlicht/CIrrDeviceAndroid.cpp | 4 ++ .../source/Irrlicht/CIrrDeviceAndroid.h | 2 + lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h | 3 ++ .../source/Irrlicht/CIrrDeviceWayland.cpp | 2 + .../source/Irrlicht/CIrrDeviceWayland.h | 4 ++ src/config/user_config.hpp | 6 +-- src/input/device_manager.cpp | 4 +- src/input/input_manager.cpp | 50 ++++++++++--------- src/main.cpp | 2 - src/main_android.cpp | 8 --- .../options/options_screen_ui.cpp | 17 +++++-- src/states_screens/race_gui.cpp | 7 ++- src/states_screens/race_gui_overworld.cpp | 7 ++- 14 files changed, 73 insertions(+), 46 deletions(-) diff --git a/lib/irrlicht/include/IrrlichtDevice.h b/lib/irrlicht/include/IrrlichtDevice.h index 4dba5c877..4741baf4c 100644 --- a/lib/irrlicht/include/IrrlichtDevice.h +++ b/lib/irrlicht/include/IrrlichtDevice.h @@ -259,6 +259,9 @@ namespace irr */ virtual bool activateJoysticks(core::array& joystickInfo) =0; + //! Returns true if system has touch device + virtual bool supportsTouchDevice() =0; + //! Set the current Gamma Value for the Display virtual bool setGammaRamp(f32 red, f32 green, f32 blue, f32 relativebrightness, f32 relativecontrast) =0; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp index cf7e8f36a..084c022cc 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.cpp @@ -53,6 +53,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) AccelerometerActive(false), GyroscopeActive(false), TextInputEnabled(false), + HasTouchDevice(false), IsMousePressed(false), GamepadAxisX(0), GamepadAxisY(0), @@ -118,6 +119,9 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param) ExposedVideoData.OGLESAndroid.Window = Android->window; createVideoModeList(); + + int32_t touch = AConfiguration_getTouchscreen(Android->config); + HasTouchDevice = touch != ACONFIGURATION_TOUCHSCREEN_NOTOUCH; } createDriver(); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h index 51f4a43ea..1b90eae23 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h @@ -75,6 +75,7 @@ namespace irr virtual bool isGyroscopeAvailable(); virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;} virtual void showKeyboard(bool show); + virtual bool supportsTouchDevice() { return HasTouchDevice; } class CCursorControl : public gui::ICursorControl { @@ -143,6 +144,7 @@ namespace irr }; TouchEventData TouchEventsData[32]; + bool HasTouchDevice; bool IsMousePressed; float GamepadAxisX; float GamepadAxisY; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h index ce4229b1b..422a2f0b0 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceStub.h @@ -118,6 +118,9 @@ namespace irr //! Activate any joysticks, and generate events for them. virtual bool activateJoysticks(core::array & joystickInfo); + + //! Returns true if system has touch device + virtual bool supportsTouchDevice() { return false; } //! Set the current Gamma Value for the Display virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ); diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp index 86b53fbe4..715c86349 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp @@ -545,6 +545,7 @@ public: if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !device->m_touch) { + device->m_has_touch_device = true; device->m_touch = wl_seat_get_touch(seat); wl_touch_add_listener(device->m_touch, &touch_listener, device); @@ -863,6 +864,7 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& params) m_width = params.WindowSize.Width; m_height = params.WindowSize.Height; m_touches_count = 0; + m_has_touch_device = false; m_window_has_focus = false; m_window_minimized = false; diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h index 7c0cb92f4..eec929123 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h @@ -115,6 +115,9 @@ namespace irr //! Activate any joysticks, and generate events for them. virtual bool activateJoysticks(core::array& joystickInfo); + + //! Returns true if system has touch device + virtual bool supportsTouchDevice() { return m_has_touch_device; } //! Set the current Gamma Value for the Display virtual bool setGammaRamp(f32 red, f32 green, f32 blue, @@ -216,6 +219,7 @@ namespace irr unsigned int m_width; unsigned int m_height; unsigned int m_touches_count; + bool m_has_touch_device; bool m_window_has_focus; bool m_window_minimized; mutable core::stringc m_clipboard; diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index c4b02faea..80676afa0 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -478,10 +478,10 @@ namespace UserConfigParams PARAM_DEFAULT( GroupUserConfigParam("Multitouch", "Settings for the multitouch device") ); - PARAM_PREFIX BoolUserConfigParam m_multitouch_enabled - PARAM_DEFAULT( BoolUserConfigParam(true, "multitouch_enabled", + PARAM_PREFIX IntUserConfigParam m_multitouch_active + PARAM_DEFAULT( IntUserConfigParam(1, "multitouch_active", &m_multitouch_group, - "Enable multitouch support.") ); + "Enable multitouch support: 0 = disabled, 1 = if available, 2 = enabled") ); PARAM_PREFIX IntUserConfigParam m_multitouch_mode PARAM_DEFAULT( IntUserConfigParam(1, "multitouch_mode", diff --git a/src/input/device_manager.cpp b/src/input/device_manager.cpp index 18d382119..2d4963a8b 100644 --- a/src/input/device_manager.cpp +++ b/src/input/device_manager.cpp @@ -168,7 +168,9 @@ bool DeviceManager::initialize() addGamepad(gamepadDevice); } // end for - if (UserConfigParams::m_multitouch_enabled) + if ((UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1) { m_multitouch_device = new MultitouchDevice(); } diff --git a/src/input/input_manager.cpp b/src/input/input_manager.cpp index b3c518339..15ccf6acf 100644 --- a/src/input/input_manager.cpp +++ b/src/input/input_manager.cpp @@ -1233,30 +1233,32 @@ EventPropagation InputManager::input(const SEvent& event) } } - // Simulate touch event on non-android devices - //~ #if !defined(ANDROID) - //~ MultitouchDevice* device = m_device_manager->getMultitouchDevice(); - - //~ if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN || - //~ type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED)) - //~ { - //~ device->m_events[0].id = 0; - //~ device->m_events[0].x = event.MouseInput.X; - //~ device->m_events[0].y = event.MouseInput.Y; - - //~ if (type == EMIE_LMOUSE_PRESSED_DOWN) - //~ { - //~ device->m_events[0].touched = true; - //~ } - //~ else if (type == EMIE_LMOUSE_LEFT_UP) - //~ { - //~ device->m_events[0].touched = false; - //~ } - - //~ m_device_manager->updateMultitouchDevice(); - //~ device->updateDeviceState(0); - //~ } - //~ #endif + // Simulate touch events if there is no real device + if (UserConfigParams::m_multitouch_active > 1 && + !irr_driver->getDevice()->supportsTouchDevice()) + { + MultitouchDevice* device = m_device_manager->getMultitouchDevice(); + + if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN || + type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED)) + { + device->m_events[0].id = 0; + device->m_events[0].x = event.MouseInput.X; + device->m_events[0].y = event.MouseInput.Y; + + if (type == EMIE_LMOUSE_PRESSED_DOWN) + { + device->m_events[0].touched = true; + } + else if (type == EMIE_LMOUSE_LEFT_UP) + { + device->m_events[0].touched = false; + } + + m_device_manager->updateMultitouchDevice(); + device->updateDeviceState(0); + } + } /* EMIE_LMOUSE_PRESSED_DOWN Left mouse button was pressed down. diff --git a/src/main.cpp b/src/main.cpp index 33452174f..b23a494a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1885,8 +1885,6 @@ int main(int argc, char *argv[] ) // handle all command line options that do not need (or must // not have) other managers initialised: initUserConfig(); - - UserConfigParams::m_multitouch_enabled = true; CommandLine::addArgsFromUserConfig(); diff --git a/src/main_android.cpp b/src/main_android.cpp index 3f2189ef1..6ff0677ff 100644 --- a/src/main_android.cpp +++ b/src/main_android.cpp @@ -39,14 +39,6 @@ void override_default_params() // Disable advanced lighting by default to make the game playable UserConfigParams::m_dynamic_lights = false; - - // Enable multitouch device when touchscreen is available - int32_t touch = AConfiguration_getTouchscreen(global_android_app->config); - - if (touch != ACONFIGURATION_TOUCHSCREEN_NOTOUCH) - { - UserConfigParams::m_multitouch_enabled = true; - } // Set multitouch device scale depending on actual screen size int32_t screen_size = AConfiguration_getScreenSize(global_android_app->config); diff --git a/src/states_screens/options/options_screen_ui.cpp b/src/states_screens/options/options_screen_ui.cpp index d448becd7..00a0eea50 100644 --- a/src/states_screens/options/options_screen_ui.cpp +++ b/src/states_screens/options/options_screen_ui.cpp @@ -122,9 +122,15 @@ void OptionsScreenUI::loadedFromFile() //I18N: In the UI options, minimap position in the race UI minimap_options->addLabel( core::stringw(_("Hidden"))); minimap_options->m_properties[GUIEngine::PROP_MIN_VALUE] = "0"; - if (UserConfigParams::m_multitouch_enabled && - UserConfigParams::m_multitouch_mode != 0) + + bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1; + + if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0) + { minimap_options->m_properties[GUIEngine::PROP_MIN_VALUE] = "1"; + } minimap_options->m_properties[GUIEngine::PROP_MAX_VALUE] = "2"; } // loadedFromFile @@ -144,8 +150,11 @@ void OptionsScreenUI::init() GUIEngine::SpinnerWidget* minimap_options = getWidget("minimap"); assert( minimap_options != NULL ); - if (UserConfigParams::m_multitouch_enabled && - UserConfigParams::m_multitouch_mode != 0 && + bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1; + + if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0 && UserConfigParams::m_minimap_display == 0) { UserConfigParams::m_minimap_display = 1; diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 5087096dc..5891ae01f 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -115,9 +115,12 @@ RaceGUI::RaceGUI() float scaling = irr_driver->getFrameSize().Height / 480.0f; const float map_size = stk_config->m_minimap_size * map_size_splitscreen; const float top_margin = 3.5f * m_font_height; + + bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1; - if (UserConfigParams::m_multitouch_enabled && - UserConfigParams::m_multitouch_mode != 0 && + if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0 && race_manager->getNumLocalPlayers() == 1) { m_multitouch_gui = new RaceGUIMultitouch(this); diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 31b08bf52..867b45925 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -88,9 +88,12 @@ RaceGUIOverworld::RaceGUIOverworld() float scaling = irr_driver->getFrameSize().Height / 420.0f; const float map_size = 250.0f; + + bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 && + irr_driver->getDevice()->supportsTouchDevice()) || + UserConfigParams::m_multitouch_active > 1; - if (UserConfigParams::m_multitouch_enabled && - UserConfigParams::m_multitouch_mode != 0 && + if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0 && race_manager->getNumLocalPlayers() == 1) { m_multitouch_gui = new RaceGUIMultitouch(this);