ANDROIDSDL: implemented checkbox for change mouse mode in Options menu

This commit is contained in:
lubomyr 2017-01-30 22:35:40 +02:00
parent ca55163ea1
commit 15acee29f1
11 changed files with 134 additions and 0 deletions

View file

@ -27,6 +27,7 @@
#include "backends/platform/androidsdl/androidsdl-sdl.h" #include "backends/platform/androidsdl/androidsdl-sdl.h"
#include "backends/events/androidsdl/androidsdl-events.h" #include "backends/events/androidsdl/androidsdl-events.h"
#include "backends/graphics/androidsdl/androidsdl-graphics.h" #include "backends/graphics/androidsdl/androidsdl-graphics.h"
#include <SDL_android.h>
void OSystem_ANDROIDSDL::initBackend() { void OSystem_ANDROIDSDL::initBackend() {
// Create the backend custom managers // Create the backend custom managers
@ -43,6 +44,38 @@ void OSystem_ANDROIDSDL::initBackend() {
if (!ConfMan.hasKey("gfx_mode")) if (!ConfMan.hasKey("gfx_mode"))
ConfMan.set("gfx_mode", "2x"); ConfMan.set("gfx_mode", "2x");
if (!ConfMan.hasKey("touchpad_mouse_mode")) {
const bool enable = (SDL_ANDROID_GetMouseEmulationMode() == 0) ? false : true;
ConfMan.setBool("touchpad_mouse_mode", enable);
} else {
touchpadMode(ConfMan.getBool("touchpad_mouse_mode"));
}
// Call parent implementation of this method // Call parent implementation of this method
OSystem_POSIX::initBackend(); OSystem_POSIX::initBackend();
} }
void OSystem_ANDROIDSDL::touchpadMode(bool enable) {
if (enable)
switchToRelativeMouseMode();
else
switchToDirectMouseMode();
}
void OSystem_ANDROIDSDL::switchToDirectMouseMode() {
SDL_ANDROID_SetMouseEmulationMode(0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
}
void OSystem_ANDROIDSDL::switchToRelativeMouseMode() {
SDL_ANDROID_SetMouseEmulationMode(1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
}
void OSystem_ANDROIDSDL::setFeatureState(Feature f, bool enable) {
switch (f) {
case kFeatureTouchpadMode:
touchpadMode(enable);
break;
}
OSystem_POSIX::setFeatureState(f, enable);
}

View file

@ -28,6 +28,10 @@
class OSystem_ANDROIDSDL : public OSystem_POSIX { class OSystem_ANDROIDSDL : public OSystem_POSIX {
public: public:
virtual void initBackend(); virtual void initBackend();
virtual void setFeatureState(Feature f, bool enable);
void touchpadMode(bool enable);
void switchToDirectMouseMode();
void switchToRelativeMouseMode();
#ifdef ENABLE_KEYMAPPER #ifdef ENABLE_KEYMAPPER
// FIXME: This just calls parent methods, is it needed? // FIXME: This just calls parent methods, is it needed?

View file

@ -337,6 +337,14 @@ public:
* This feature has no associated state. * This feature has no associated state.
*/ */
kFeatureOpenUrl kFeatureOpenUrl
#ifdef ANDROIDSDL
/**
* mouse emulation mode
*/
,
kFeatureTouchpadMode
#endif
}; };
/** /**

View file

@ -136,6 +136,10 @@ OptionsDialog::~OptionsDialog() {
} }
void OptionsDialog::init() { void OptionsDialog::init() {
#ifdef ANDROIDSDL
_enableAndroidSdlSettings = false;
_touchpadCheckbox = 0;
#endif
_enableGraphicSettings = false; _enableGraphicSettings = false;
_gfxPopUp = 0; _gfxPopUp = 0;
_gfxPopUpDesc = 0; _gfxPopUpDesc = 0;
@ -203,6 +207,14 @@ void OptionsDialog::build() {
_guioptions = parseGameGUIOptions(_guioptionsString); _guioptions = parseGameGUIOptions(_guioptionsString);
} }
#ifdef ANDROIDSDL
// AndroidSDL options
if (ConfMan.hasKey("touchpad_mouse_mode", _domain)) {
bool touchpadState = ConfMan.getBool("touchpad_mouse_mode", _domain);
_touchpadCheckbox->setState(touchpadState);
}
#endif
// Graphic options // Graphic options
if (_fullscreenCheckbox) { if (_fullscreenCheckbox) {
_gfxPopUp->setSelected(0); _gfxPopUp->setSelected(0);
@ -380,6 +392,14 @@ void OptionsDialog::open() {
} }
void OptionsDialog::apply() { void OptionsDialog::apply() {
#ifdef ANDROIDSDL
if (_enableAndroidSdlSettings) {
if (ConfMan.getBool("touchpad_mouse_mode", _domain) != _touchpadCheckbox->getState()) {
ConfMan.setBool("touchpad_mouse_mode", _touchpadCheckbox->getState(), _domain);
g_system->setFeatureState(OSystem::kFeatureTouchpadMode, _touchpadCheckbox->getState());
}
}
#endif
// Graphic options // Graphic options
bool graphicsModeChanged = false; bool graphicsModeChanged = false;
if (_fullscreenCheckbox) { if (_fullscreenCheckbox) {
@ -673,6 +693,10 @@ void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
} }
} }
void OptionsDialog::setAndroidSdlSettingsState(bool enabled) {
_enableAndroidSdlSettings = enabled;
}
void OptionsDialog::setGraphicSettingsState(bool enabled) { void OptionsDialog::setGraphicSettingsState(bool enabled) {
_enableGraphicSettings = enabled; _enableGraphicSettings = enabled;
@ -799,6 +823,15 @@ void OptionsDialog::setSubtitleSettingsState(bool enabled) {
_subSpeedLabel->setEnabled(ena); _subSpeedLabel->setEnabled(ena);
} }
#ifdef ANDROIDSDL
void OptionsDialog::addAndroidSdlControls(GuiObject *boss, const Common::String &prefix) {
// Touchpad Mouse mode
_touchpadCheckbox = new CheckboxWidget(boss, prefix + "grTouchpadCheckbox", _("Touchpad mouse mode"));
_enableAndroidSdlSettings = true;
}
#endif
void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &prefix) { void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &prefix) {
const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes(); const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
Common::String context; Common::String context;
@ -1226,6 +1259,14 @@ void GlobalOptionsDialog::build() {
// The tab widget // The tab widget
TabWidget *tab = new TabWidget(this, "GlobalOptions.TabWidget"); TabWidget *tab = new TabWidget(this, "GlobalOptions.TabWidget");
#ifdef ANDROIDSDL
//
// The control tab only for Android SDL platform
//
tab->addTab(_("Control"));
addAndroidSdlControls(tab, "GlobalOptions_AndroidSdl.");
#endif
// //
// 1) The graphics tab // 1) The graphics tab
// //

View file

@ -86,6 +86,9 @@ protected:
virtual void clean(); virtual void clean();
void rebuild(); void rebuild();
#ifdef ANDROIDSDL
void addAndroidSdlControls(GuiObject *boss, const Common::String &prefix);
#endif
void addGraphicControls(GuiObject *boss, const Common::String &prefix); void addGraphicControls(GuiObject *boss, const Common::String &prefix);
void addAudioControls(GuiObject *boss, const Common::String &prefix); void addAudioControls(GuiObject *boss, const Common::String &prefix);
void addMIDIControls(GuiObject *boss, const Common::String &prefix); void addMIDIControls(GuiObject *boss, const Common::String &prefix);
@ -96,6 +99,9 @@ protected:
void addSubtitleControls(GuiObject *boss, const Common::String &prefix, int maxSliderVal = 255); void addSubtitleControls(GuiObject *boss, const Common::String &prefix, int maxSliderVal = 255);
void addEngineControls(GuiObject *boss, const Common::String &prefix, const ExtraGuiOptions &engineOptions); void addEngineControls(GuiObject *boss, const Common::String &prefix, const ExtraGuiOptions &engineOptions);
#ifdef ANDROIDSDL
void setAndroidSdlSettingsState(bool enabled);
#endif
void setGraphicSettingsState(bool enabled); void setGraphicSettingsState(bool enabled);
void setAudioSettingsState(bool enabled); void setAudioSettingsState(bool enabled);
void setMIDISettingsState(bool enabled); void setMIDISettingsState(bool enabled);
@ -112,6 +118,16 @@ protected:
int _pathsTabId; int _pathsTabId;
private: private:
#ifdef ANDROIDSDL
//
// AndroidSDL controls
//
bool _enableAndroidSdlSettings;
CheckboxWidget *_touchpadCheckbox;
#endif
// //
// Graphics controls // Graphics controls
// //

Binary file not shown.

View file

@ -238,6 +238,14 @@
</layout> </layout>
</dialog> </dialog>
<dialog name = 'GlobalOptions_AndroidSdl' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<widget name = 'grTouchpadCheckbox'
type = 'Checkbox'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'> <dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'> <layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>

View file

@ -235,6 +235,14 @@
</layout> </layout>
</dialog> </dialog>
<dialog name = 'GlobalOptions_AndroidSdl' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<widget name = 'grTouchpadCheckbox'
type = 'Checkbox'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'> <dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'> <layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>

Binary file not shown.

View file

@ -252,6 +252,14 @@
</layout> </layout>
</dialog> </dialog>
<dialog name = 'GlobalOptions_AndroidSdl' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<widget name = 'grTouchpadCheckbox'
type = 'Checkbox'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'> <dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'> <layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>

View file

@ -233,6 +233,14 @@
</layout> </layout>
</dialog> </dialog>
<dialog name = 'GlobalOptions_AndroidSdl' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<widget name = 'grTouchpadCheckbox'
type = 'Checkbox'
/>
</layout>
</dialog>
<dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'> <dialog name = 'GlobalOptions_Graphics' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'> <layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>