IOS7: Refactor touchpadModeEnabled to a TouchMode

Change the boolean parameter indicating if "touch mode" is enabled
or not to an enum which could contain several different touch modes.
This commit is contained in:
Lars Sundström 2023-10-01 20:35:04 +02:00
parent 2971029301
commit 8e9f54ad32
5 changed files with 30 additions and 22 deletions

View File

@ -66,6 +66,11 @@ enum DirectionalInput {
kDirectionalInputDpad,
};
enum TouchMode {
kTouchModeDirect,
kTouchModeTouchpad,
};
enum UIViewSwipeDirection {
kUIViewSwipeUp = 1,
kUIViewSwipeDown = 2,
@ -98,6 +103,6 @@ void iOS7_buildSharedOSystemInstance();
void iOS7_main(int argc, char **argv);
Common::String iOS7_getDocumentsDir();
Common::String iOS7_getAppBundleDir();
bool iOS7_touchpadModeEnabled();
TouchMode iOS7_getCurrentTouchMode();
#endif

View File

@ -427,7 +427,7 @@ void OSystem_iOS7::registerDefaultSettings(const Common::String &target) const {
void OSystem_iOS7::applyBackendSettings() {
virtualController(ConfMan.getBool("gamepad_controller"));
_touchpadModeEnabled = ConfMan.getBool("touchpad_mode");
_currentTouchMode = ConfMan.getBool("touchpad_mode") ? kTouchModeTouchpad : kTouchModeDirect;
_mouseClickAndDragEnabled = ConfMan.getBool("clickanddrag_mode");
#if TARGET_OS_IOS

View File

@ -180,13 +180,13 @@ bool OSystem_iOS7::handleEvent_touchFirstDown(Common::Event &event, int x, int y
_lastPadX = x;
_lastPadY = y;
if (!_touchpadModeEnabled) {
if (_currentTouchMode == kTouchModeDirect) {
Common::Point mouse(x, y);
dynamic_cast<iOSCommonGraphics *>(_graphicsManager)->notifyMousePosition(mouse);
}
if (_mouseClickAndDragEnabled) {
if (_touchpadModeEnabled) {
if (_currentTouchMode == kTouchModeTouchpad) {
_queuedInputEvent.type = Common::EVENT_LBUTTONDOWN;
_queuedEventTime = getMillis() + 250;
handleEvent_mouseEvent(_queuedInputEvent, 0, 0);
@ -209,7 +209,7 @@ bool OSystem_iOS7::handleEvent_touchFirstUp(Common::Event &event, int x, int y)
if (!handleEvent_touchSecondUp(event, x, y))
return false;
} else if (_mouseClickAndDragEnabled) {
if (_touchpadModeEnabled && _queuedInputEvent.type == Common::EVENT_LBUTTONDOWN) {
if (_currentTouchMode == kTouchModeTouchpad && _queuedInputEvent.type == Common::EVENT_LBUTTONDOWN) {
// This has not been sent yet, send it right away
event = _queuedInputEvent;
_queuedInputEvent.type = Common::EVENT_LBUTTONUP;
@ -280,7 +280,7 @@ bool OSystem_iOS7::handleEvent_touchFirstDragged(Common::Event &event, int x, in
_lastPadX = x;
_lastPadY = y;
if (_touchpadModeEnabled) {
if (_currentTouchMode == kTouchModeTouchpad) {
if (_mouseClickAndDragEnabled && _queuedInputEvent.type == Common::EVENT_LBUTTONDOWN) {
// Cancel the button down event since this was a pure mouse move
_queuedInputEvent.type = Common::EVENT_INVALID;
@ -439,11 +439,14 @@ bool OSystem_iOS7::handleEvent_swipe(Common::Event &event, int direction, int to
case kUIViewSwipeRight: {
// Swipe right
_touchpadModeEnabled = !_touchpadModeEnabled;
ConfMan.setBool("touchpad_mode", _touchpadModeEnabled);
ConfMan.flushToDisk();
if (_currentTouchMode == kTouchModeDirect) {
_currentTouchMode = kTouchModeTouchpad;
} else {
_currentTouchMode = kTouchModeDirect;
}
Common::U32String dialogMsg;
if (_touchpadModeEnabled)
if (_currentTouchMode == kTouchModeTouchpad)
dialogMsg = _("Touchpad mode enabled.");
else
dialogMsg = _("Touchpad mode disabled.");

View File

@ -93,7 +93,7 @@ OSystem_iOS7::OSystem_iOS7() :
_screenOrientation(kScreenOrientationAuto),
_timeSuspended(0), _runningTasks(0) {
_queuedInputEvent.type = Common::EVENT_INVALID;
_touchpadModeEnabled = ConfMan.getBool("touchpad_mode");
_currentTouchMode = kTouchModeTouchpad;
_mouseClickAndDragEnabled = ConfMan.getBool("clickanddrag_mode");
_chrootBasePath = iOS7_getDocumentsDir();
@ -112,10 +112,6 @@ OSystem_iOS7::~OSystem_iOS7() {
delete _graphicsManager;
}
bool OSystem_iOS7::touchpadModeEnabled() const {
return _touchpadModeEnabled;
}
#if defined(USE_OPENGL) && defined(USE_GLAD)
void *OSystem_iOS7::getOpenGLProcAddress(const char *name) const {
return dlsym(RTLD_SELF, name);
@ -429,15 +425,18 @@ void OSystem_iOS7::addSysArchivesToSearchSet(Common::SearchSet &s, int priority)
}
}
bool iOS7_touchpadModeEnabled() {
OSystem_iOS7 *sys = dynamic_cast<OSystem_iOS7 *>(g_system);
return sys && sys->touchpadModeEnabled();
}
void iOS7_buildSharedOSystemInstance() {
OSystem_iOS7::sharedInstance();
}
TouchMode iOS7_getCurrentTouchMode() {
OSystem_iOS7 *sys = dynamic_cast<OSystem_iOS7 *>(g_system);
if (!sys) {
abort();
}
return sys->getCurrentTouchMode();
}
void iOS7_main(int argc, char **argv) {
//OSystem_iOS7::migrateApp();

View File

@ -68,7 +68,7 @@ protected:
Common::Event _queuedInputEvent;
bool _secondaryTapped;
bool _mouseClickAndDragEnabled;
bool _touchpadModeEnabled;
TouchMode _currentTouchMode;
int _lastPadX;
int _lastPadY;
@ -101,7 +101,8 @@ public:
bool setGraphicsMode(int mode, uint flags) override;
bool touchpadModeEnabled() const;
TouchMode getCurrentTouchMode() const { return _currentTouchMode; };
void setCurrentTouchMode(TouchMode mode) { _currentTouchMode = mode; };
#if TARGET_OS_IOS
void applyOrientationSettings();