Detect if there is touch device available

This commit is contained in:
Deve 2019-01-09 22:04:50 +01:00
parent 20310f9dbc
commit 15ffc98369
14 changed files with 73 additions and 46 deletions

View File

@ -259,6 +259,9 @@ namespace irr
*/ */
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0; virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0;
//! Returns true if system has touch device
virtual bool supportsTouchDevice() =0;
//! Set the current Gamma Value for the Display //! Set the current Gamma Value for the Display
virtual bool setGammaRamp(f32 red, f32 green, f32 blue, virtual bool setGammaRamp(f32 red, f32 green, f32 blue,
f32 relativebrightness, f32 relativecontrast) =0; f32 relativebrightness, f32 relativecontrast) =0;

View File

@ -53,6 +53,7 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
AccelerometerActive(false), AccelerometerActive(false),
GyroscopeActive(false), GyroscopeActive(false),
TextInputEnabled(false), TextInputEnabled(false),
HasTouchDevice(false),
IsMousePressed(false), IsMousePressed(false),
GamepadAxisX(0), GamepadAxisX(0),
GamepadAxisY(0), GamepadAxisY(0),
@ -118,6 +119,9 @@ CIrrDeviceAndroid::CIrrDeviceAndroid(const SIrrlichtCreationParameters& param)
ExposedVideoData.OGLESAndroid.Window = Android->window; ExposedVideoData.OGLESAndroid.Window = Android->window;
createVideoModeList(); createVideoModeList();
int32_t touch = AConfiguration_getTouchscreen(Android->config);
HasTouchDevice = touch != ACONFIGURATION_TOUCHSCREEN_NOTOUCH;
} }
createDriver(); createDriver();

View File

@ -75,6 +75,7 @@ namespace irr
virtual bool isGyroscopeAvailable(); virtual bool isGyroscopeAvailable();
virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;} virtual void setTextInputEnabled(bool enabled) {TextInputEnabled = enabled;}
virtual void showKeyboard(bool show); virtual void showKeyboard(bool show);
virtual bool supportsTouchDevice() { return HasTouchDevice; }
class CCursorControl : public gui::ICursorControl class CCursorControl : public gui::ICursorControl
{ {
@ -143,6 +144,7 @@ namespace irr
}; };
TouchEventData TouchEventsData[32]; TouchEventData TouchEventsData[32];
bool HasTouchDevice;
bool IsMousePressed; bool IsMousePressed;
float GamepadAxisX; float GamepadAxisX;
float GamepadAxisY; float GamepadAxisY;

View File

@ -119,6 +119,9 @@ namespace irr
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
//! Returns true if system has touch device
virtual bool supportsTouchDevice() { return false; }
//! Set the current Gamma Value for the Display //! Set the current Gamma Value for the Display
virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast ); virtual bool setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast );

View File

@ -545,6 +545,7 @@ public:
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !device->m_touch) if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !device->m_touch)
{ {
device->m_has_touch_device = true;
device->m_touch = wl_seat_get_touch(seat); device->m_touch = wl_seat_get_touch(seat);
wl_touch_add_listener(device->m_touch, &touch_listener, wl_touch_add_listener(device->m_touch, &touch_listener,
device); device);
@ -863,6 +864,7 @@ CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& params)
m_width = params.WindowSize.Width; m_width = params.WindowSize.Width;
m_height = params.WindowSize.Height; m_height = params.WindowSize.Height;
m_touches_count = 0; m_touches_count = 0;
m_has_touch_device = false;
m_window_has_focus = false; m_window_has_focus = false;
m_window_minimized = false; m_window_minimized = false;

View File

@ -116,6 +116,9 @@ namespace irr
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo);
//! Returns true if system has touch device
virtual bool supportsTouchDevice() { return m_has_touch_device; }
//! Set the current Gamma Value for the Display //! Set the current Gamma Value for the Display
virtual bool setGammaRamp(f32 red, f32 green, f32 blue, virtual bool setGammaRamp(f32 red, f32 green, f32 blue,
f32 brightness, f32 contrast); f32 brightness, f32 contrast);
@ -216,6 +219,7 @@ namespace irr
unsigned int m_width; unsigned int m_width;
unsigned int m_height; unsigned int m_height;
unsigned int m_touches_count; unsigned int m_touches_count;
bool m_has_touch_device;
bool m_window_has_focus; bool m_window_has_focus;
bool m_window_minimized; bool m_window_minimized;
mutable core::stringc m_clipboard; mutable core::stringc m_clipboard;

View File

@ -478,10 +478,10 @@ namespace UserConfigParams
PARAM_DEFAULT( GroupUserConfigParam("Multitouch", PARAM_DEFAULT( GroupUserConfigParam("Multitouch",
"Settings for the multitouch device") ); "Settings for the multitouch device") );
PARAM_PREFIX BoolUserConfigParam m_multitouch_enabled PARAM_PREFIX IntUserConfigParam m_multitouch_active
PARAM_DEFAULT( BoolUserConfigParam(true, "multitouch_enabled", PARAM_DEFAULT( IntUserConfigParam(1, "multitouch_active",
&m_multitouch_group, &m_multitouch_group,
"Enable multitouch support.") ); "Enable multitouch support: 0 = disabled, 1 = if available, 2 = enabled") );
PARAM_PREFIX IntUserConfigParam m_multitouch_mode PARAM_PREFIX IntUserConfigParam m_multitouch_mode
PARAM_DEFAULT( IntUserConfigParam(1, "multitouch_mode", PARAM_DEFAULT( IntUserConfigParam(1, "multitouch_mode",

View File

@ -168,7 +168,9 @@ bool DeviceManager::initialize()
addGamepad(gamepadDevice); addGamepad(gamepadDevice);
} // end for } // 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(); m_multitouch_device = new MultitouchDevice();
} }

View File

@ -1233,30 +1233,32 @@ EventPropagation InputManager::input(const SEvent& event)
} }
} }
// Simulate touch event on non-android devices // Simulate touch events if there is no real device
//~ #if !defined(ANDROID) if (UserConfigParams::m_multitouch_active > 1 &&
//~ MultitouchDevice* device = m_device_manager->getMultitouchDevice(); !irr_driver->getDevice()->supportsTouchDevice())
{
MultitouchDevice* device = m_device_manager->getMultitouchDevice();
//~ if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN || if (device != NULL && (type == EMIE_LMOUSE_PRESSED_DOWN ||
//~ type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED)) type == EMIE_LMOUSE_LEFT_UP || type == EMIE_MOUSE_MOVED))
//~ { {
//~ device->m_events[0].id = 0; device->m_events[0].id = 0;
//~ device->m_events[0].x = event.MouseInput.X; device->m_events[0].x = event.MouseInput.X;
//~ device->m_events[0].y = event.MouseInput.Y; device->m_events[0].y = event.MouseInput.Y;
//~ if (type == EMIE_LMOUSE_PRESSED_DOWN) if (type == EMIE_LMOUSE_PRESSED_DOWN)
//~ { {
//~ device->m_events[0].touched = true; device->m_events[0].touched = true;
//~ } }
//~ else if (type == EMIE_LMOUSE_LEFT_UP) else if (type == EMIE_LMOUSE_LEFT_UP)
//~ { {
//~ device->m_events[0].touched = false; device->m_events[0].touched = false;
//~ } }
//~ m_device_manager->updateMultitouchDevice(); m_device_manager->updateMultitouchDevice();
//~ device->updateDeviceState(0); device->updateDeviceState(0);
//~ } }
//~ #endif }
/* /*
EMIE_LMOUSE_PRESSED_DOWN Left mouse button was pressed down. EMIE_LMOUSE_PRESSED_DOWN Left mouse button was pressed down.

View File

@ -1886,8 +1886,6 @@ int main(int argc, char *argv[] )
// not have) other managers initialised: // not have) other managers initialised:
initUserConfig(); initUserConfig();
UserConfigParams::m_multitouch_enabled = true;
CommandLine::addArgsFromUserConfig(); CommandLine::addArgsFromUserConfig();
handleCmdLinePreliminary(); handleCmdLinePreliminary();

View File

@ -40,14 +40,6 @@ void override_default_params()
// Disable advanced lighting by default to make the game playable // Disable advanced lighting by default to make the game playable
UserConfigParams::m_dynamic_lights = false; 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 // Set multitouch device scale depending on actual screen size
int32_t screen_size = AConfiguration_getScreenSize(global_android_app->config); int32_t screen_size = AConfiguration_getScreenSize(global_android_app->config);

View File

@ -122,9 +122,15 @@ void OptionsScreenUI::loadedFromFile()
//I18N: In the UI options, minimap position in the race UI //I18N: In the UI options, minimap position in the race UI
minimap_options->addLabel( core::stringw(_("Hidden"))); minimap_options->addLabel( core::stringw(_("Hidden")));
minimap_options->m_properties[GUIEngine::PROP_MIN_VALUE] = "0"; 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_MIN_VALUE] = "1";
}
minimap_options->m_properties[GUIEngine::PROP_MAX_VALUE] = "2"; minimap_options->m_properties[GUIEngine::PROP_MAX_VALUE] = "2";
} // loadedFromFile } // loadedFromFile
@ -144,8 +150,11 @@ void OptionsScreenUI::init()
GUIEngine::SpinnerWidget* minimap_options = getWidget<GUIEngine::SpinnerWidget>("minimap"); GUIEngine::SpinnerWidget* minimap_options = getWidget<GUIEngine::SpinnerWidget>("minimap");
assert( minimap_options != NULL ); assert( minimap_options != NULL );
if (UserConfigParams::m_multitouch_enabled && bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 &&
UserConfigParams::m_multitouch_mode != 0 && 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 == 0)
{ {
UserConfigParams::m_minimap_display = 1; UserConfigParams::m_minimap_display = 1;

View File

@ -116,8 +116,11 @@ RaceGUI::RaceGUI()
const float map_size = stk_config->m_minimap_size * map_size_splitscreen; const float map_size = stk_config->m_minimap_size * map_size_splitscreen;
const float top_margin = 3.5f * m_font_height; const float top_margin = 3.5f * m_font_height;
if (UserConfigParams::m_multitouch_enabled && bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 &&
UserConfigParams::m_multitouch_mode != 0 && irr_driver->getDevice()->supportsTouchDevice()) ||
UserConfigParams::m_multitouch_active > 1;
if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0 &&
race_manager->getNumLocalPlayers() == 1) race_manager->getNumLocalPlayers() == 1)
{ {
m_multitouch_gui = new RaceGUIMultitouch(this); m_multitouch_gui = new RaceGUIMultitouch(this);

View File

@ -89,8 +89,11 @@ RaceGUIOverworld::RaceGUIOverworld()
float scaling = irr_driver->getFrameSize().Height / 420.0f; float scaling = irr_driver->getFrameSize().Height / 420.0f;
const float map_size = 250.0f; const float map_size = 250.0f;
if (UserConfigParams::m_multitouch_enabled && bool multitouch_enabled = (UserConfigParams::m_multitouch_active == 1 &&
UserConfigParams::m_multitouch_mode != 0 && irr_driver->getDevice()->supportsTouchDevice()) ||
UserConfigParams::m_multitouch_active > 1;
if (multitouch_enabled && UserConfigParams::m_multitouch_mode != 0 &&
race_manager->getNumLocalPlayers() == 1) race_manager->getNumLocalPlayers() == 1)
{ {
m_multitouch_gui = new RaceGUIMultitouch(this); m_multitouch_gui = new RaceGUIMultitouch(this);