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;
//! 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;

View File

@ -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();

View File

@ -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;

View File

@ -118,6 +118,9 @@ namespace irr
//! Activate any joysticks, and generate events for them.
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
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)
{
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;

View File

@ -115,6 +115,9 @@ namespace irr
//! Activate any joysticks, and generate events for them.
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
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;

View File

@ -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",

View File

@ -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();
}

View File

@ -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.

View File

@ -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();

View File

@ -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);

View File

@ -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<GUIEngine::SpinnerWidget>("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;

View File

@ -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);

View File

@ -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);