Initial commit
This commit is contained in:
27
backends/platform/ios7/README.md
Normal file
27
backends/platform/ios7/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# ScummVM for iOS 7.1+ #
|
||||
|
||||
This is a quick fix of the latest ScummVM (1.8.0) for iOS 7.1. It has been tested on real iPhone 6S+, and iPad Pro, and also on all the available Xcode simulators.
|
||||
|
||||
I tried to use all the latest iOS features to replace the old code. For instance, it uses gesture recognizers most of the time, it supports the new iPhones 6 / 6+ / 6s / 6s+ resolution, and you can copy your game files using iTunes.
|
||||
|
||||
## Compilation ##
|
||||
|
||||
See https://wiki.scummvm.org/index.php/Compiling_ScummVM/iPhone
|
||||
|
||||
## Usage ##
|
||||
|
||||
The game data files can be copied on the iOS device using iTunes. Once done, add your games in ScummVM as usual.
|
||||
|
||||
Here is a list of the in-game gestures:
|
||||
|
||||
|Gesture|Description|
|
||||
|-------|-----------|
|
||||
|Two fingers swipe down|Display the ScummVM menu for loading, saving, etc.|
|
||||
|Two fingers swipe right|Enable / disable the touchpad mode|
|
||||
|Two fingers swipe up|Enable / disable the mouse-click-and-drag mode|
|
||||
|Two fingers tap|Simulate a right click. You should tap with one finger, and then tap with another while keeping your first finger on the screen.|
|
||||
|Two fingers double-tap|Skip the cinematic / video|
|
||||
|
||||
The iOS keyboard is visible when the device is in portrait mode, and hidden in landscape mode.
|
||||
|
||||
External devices such as mouse, trackpad and gamepad controllers, are supported from iOS 14 and later.
|
||||
42
backends/platform/ios7/ios7_app_delegate.h
Normal file
42
backends/platform/ios7/ios7_app_delegate.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_APP_DELEGATE_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_APP_DELEGATE_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
@class iPhoneView;
|
||||
|
||||
|
||||
@interface iOS7AppDelegate : NSObject<UIApplicationDelegate>
|
||||
|
||||
+ (iOS7AppDelegate *)iOS7AppDelegate;
|
||||
+ (iPhoneView *)iPhoneView;
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
+ (UIInterfaceOrientation)currentOrientation;
|
||||
+ (void)setKeyWindow:(UIWindow *)window;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
178
backends/platform/ios7/ios7_app_delegate.mm
Normal file
178
backends/platform/ios7/ios7_app_delegate.mm
Normal file
@@ -0,0 +1,178 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
#include "backends/platform/ios7/ios7_scummvm_view_controller.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
@implementation iOS7AppDelegate {
|
||||
UIWindow *_window;
|
||||
iOS7ScummVMViewController *_controller;
|
||||
iPhoneView *_view;
|
||||
BOOL _restoreState;
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if (self = [super init]) {
|
||||
_window = nil;
|
||||
_view = nil;
|
||||
_restoreState = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(UIApplication *)application {
|
||||
CGRect rect = [[UIScreen mainScreen] bounds];
|
||||
|
||||
// Create the directory for savegames
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *documentPath = [NSString stringWithUTF8String:iOS7_getDocumentsDir().c_str()];
|
||||
NSString *savePath = [documentPath stringByAppendingPathComponent:@"Savegames"];
|
||||
if (![fm fileExistsAtPath:savePath]) {
|
||||
[fm createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
|
||||
_controller = [[iOS7ScummVMViewController alloc] init];
|
||||
|
||||
_view = [[iPhoneView alloc] initWithFrame:rect];
|
||||
#if TARGET_OS_IOS
|
||||
// This property does not affect the gesture recognizers attached to the view.
|
||||
// Gesture recognizers receive all touches that occur in the view.
|
||||
_view.multipleTouchEnabled = NO;
|
||||
#endif
|
||||
_controller.view = _view;
|
||||
|
||||
if (@available(iOS 13.0, *)) {
|
||||
// iOS13 and later uses of UIScene.
|
||||
// The keyWindow is setup by iOS7SceneDelegate
|
||||
} else {
|
||||
[iOS7AppDelegate setKeyWindow:[[UIWindow alloc] initWithFrame:rect]];
|
||||
}
|
||||
|
||||
// Force creation of the shared instance on the main thread
|
||||
iOS7_buildSharedOSystemInstance();
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||||
iOS7_main(iOS7_argc, iOS7_argv);
|
||||
});
|
||||
|
||||
if (_restoreState)
|
||||
[_view restoreApplicationState];
|
||||
else
|
||||
[_view clearApplicationState];
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
[_view applicationSuspend];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
[_view applicationResume];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
// Make sure we have the correct orientation in case the orientation was changed while
|
||||
// the app was inactive.
|
||||
[_controller updateCurrentOrientation];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// Start the background task before sending the application entered background event.
|
||||
// This is because this event will be handled in a separate thread and it will likely
|
||||
// no be started before we return from this function.
|
||||
[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
|
||||
|
||||
[_view saveApplicationState];
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_13_2
|
||||
- (BOOL)application:(UIApplication *)application shouldSaveSecureApplicationState:(NSCoder *)coder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application shouldRestoreSecureApplicationState:(NSCoder *)coder {
|
||||
return YES;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __IPHONE_13_0
|
||||
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)) {
|
||||
// Called when a new scene session is being created.
|
||||
UISceneConfiguration *config = [[UISceneConfiguration alloc] initWithName:@"ScummVM Scene Configuration" sessionRole:connectingSceneSession.role];
|
||||
[config setDelegateClass:NSClassFromString(@"iOS7SceneDelegate")];
|
||||
return config;
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions API_AVAILABLE(ios(13.0)) {
|
||||
// Called when the user discards a scene session.
|
||||
// Use this method to release any resources that were
|
||||
// specific to the discarded scenes, as they will not return.
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)application:(UIApplication *)application didDecodeRestorableStateWithCoder:(NSCoder *)coder {
|
||||
_restoreState = YES;
|
||||
}
|
||||
|
||||
+ (iOS7AppDelegate *)iOS7AppDelegate {
|
||||
UIApplication *app = [UIApplication sharedApplication];
|
||||
// [UIApplication delegate] must be used from the main thread only
|
||||
if ([NSThread currentThread] == [NSThread mainThread]) {
|
||||
return (iOS7AppDelegate *) app.delegate;
|
||||
} else {
|
||||
__block iOS7AppDelegate *delegate = nil;
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
delegate = (iOS7AppDelegate *) app.delegate;
|
||||
});
|
||||
return delegate;
|
||||
}
|
||||
}
|
||||
|
||||
+ (iPhoneView *)iPhoneView {
|
||||
iOS7AppDelegate *appDelegate = [self iOS7AppDelegate];
|
||||
return appDelegate->_view;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
+ (UIInterfaceOrientation)currentOrientation {
|
||||
iOS7AppDelegate *appDelegate = [self iOS7AppDelegate];
|
||||
return [appDelegate->_controller currentOrientation];
|
||||
}
|
||||
|
||||
+ (void)setKeyWindow:(UIWindow *)window {
|
||||
iOS7AppDelegate *appDelegate = [self iOS7AppDelegate];
|
||||
appDelegate->_window = window;
|
||||
[appDelegate->_window retain];
|
||||
[appDelegate->_window setRootViewController:appDelegate->_controller];
|
||||
[appDelegate->_window makeKeyAndVisible];
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
112
backends/platform/ios7/ios7_common.h
Normal file
112
backends/platform/ios7/ios7_common.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_COMMON_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_COMMON_H
|
||||
|
||||
#include "graphics/surface.h"
|
||||
|
||||
|
||||
enum InputEvent {
|
||||
kInputTouchBegan,
|
||||
kInputTouchMoved,
|
||||
kInputMouseLeftButtonDown,
|
||||
kInputMouseLeftButtonUp,
|
||||
kInputMouseRightButtonDown,
|
||||
kInputMouseRightButtonUp,
|
||||
kInputMouseDelta,
|
||||
kInputOrientationChanged,
|
||||
kInputKeyPressed,
|
||||
kInputApplicationSuspended,
|
||||
kInputApplicationResumed,
|
||||
kInputApplicationSaveState,
|
||||
kInputApplicationClearState,
|
||||
kInputApplicationRestoreState,
|
||||
kInputSwipe,
|
||||
kInputTap,
|
||||
kInputLongPress,
|
||||
kInputMainMenu,
|
||||
kInputJoystickAxisMotion,
|
||||
kInputJoystickButtonDown,
|
||||
kInputJoystickButtonUp,
|
||||
kInputScreenChanged,
|
||||
kInputTouchModeChanged
|
||||
};
|
||||
|
||||
enum ScreenOrientation {
|
||||
kScreenOrientationAuto,
|
||||
kScreenOrientationPortrait,
|
||||
kScreenOrientationFlippedPortrait,
|
||||
kScreenOrientationLandscape,
|
||||
kScreenOrientationFlippedLandscape
|
||||
};
|
||||
|
||||
enum DirectionalInput {
|
||||
kDirectionalInputThumbstick,
|
||||
kDirectionalInputDpad,
|
||||
};
|
||||
|
||||
enum TouchMode {
|
||||
kTouchModeDirect,
|
||||
kTouchModeTouchpad,
|
||||
};
|
||||
|
||||
enum UIViewSwipeDirection {
|
||||
kUIViewSwipeUp = 1,
|
||||
kUIViewSwipeDown = 2,
|
||||
kUIViewSwipeLeft = 4,
|
||||
kUIViewSwipeRight = 8
|
||||
};
|
||||
|
||||
enum UIViewTapDescription {
|
||||
kUIViewTapSingle = 1,
|
||||
kUIViewTapDouble = 2
|
||||
};
|
||||
|
||||
enum UIViewLongPressDescription {
|
||||
UIViewLongPressStarted = 1,
|
||||
UIViewLongPressEnded = 2
|
||||
};
|
||||
|
||||
struct InternalEvent {
|
||||
InternalEvent() : type(), value1(), value2() {}
|
||||
InternalEvent(InputEvent t, int v1, int v2) : type(t), value1(v1), value2(v2) {}
|
||||
|
||||
InputEvent type;
|
||||
int value1, value2;
|
||||
};
|
||||
|
||||
// On the ObjC side
|
||||
|
||||
extern int iOS7_argc;
|
||||
extern char **iOS7_argv;
|
||||
|
||||
bool iOS7_fetchEvent(InternalEvent *event);
|
||||
bool iOS7_isBigDevice();
|
||||
|
||||
void iOS7_buildSharedOSystemInstance();
|
||||
void iOS7_main(int argc, char **argv);
|
||||
Common::String iOS7_getDocumentsDir();
|
||||
Common::String iOS7_getAppBundleDir();
|
||||
TouchMode iOS7_getCurrentTouchMode();
|
||||
void iOS7_setSafeAreaInsets(int l, int r, int t, int b);
|
||||
|
||||
#endif
|
||||
49
backends/platform/ios7/ios7_game_controller.h
Normal file
49
backends/platform/ios7/ios7_game_controller.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_GAME_CONTROLLER_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_GAME_CONTROLLER_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
@class iPhoneView;
|
||||
|
||||
@interface GameController : NSObject
|
||||
|
||||
typedef enum {
|
||||
kGameControllerJoystickLeft = 0,
|
||||
kGameControllerJoystickRight
|
||||
} GameControllerJoystick;
|
||||
|
||||
|
||||
@property (nonatomic, readwrite, retain) iPhoneView *view;
|
||||
@property (nonatomic, assign) BOOL isConnected;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)v;
|
||||
|
||||
- (CGPoint)getLocationInView:(UITouch *)touch;
|
||||
- (void)handleJoystickAxisMotionX:(int)x andY:(int)y forJoystick:(GameControllerJoystick)joystick;
|
||||
- (void)handleJoystickButtonAction:(int)button isPressed:(bool)pressed;
|
||||
|
||||
- (void)handleMainMenu:(BOOL)pressed;
|
||||
@end
|
||||
|
||||
#endif /* BACKENDS_PLATFORM_IOS7_IOS7_GAME_CONTROLLER_H */
|
||||
96
backends/platform/ios7/ios7_game_controller.mm
Normal file
96
backends/platform/ios7/ios7_game_controller.mm
Normal file
@@ -0,0 +1,96 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "common/events.h"
|
||||
#include "backends/platform/ios7/ios7_game_controller.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
@interface GameController()
|
||||
@property (nonatomic, assign) BOOL firstButtonPressed;
|
||||
@property (nonatomic, assign) BOOL secondButtonPressed;
|
||||
@end
|
||||
|
||||
@implementation GameController
|
||||
|
||||
@synthesize view;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)v {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self setView:v];
|
||||
}
|
||||
_firstButtonPressed = _secondButtonPressed = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGPoint)getLocationInView:(UITouch *)touch {
|
||||
CGPoint p = [touch locationInView:[self view]];
|
||||
p.x *= [[self view] contentScaleFactor];
|
||||
p.y *= [[self view] contentScaleFactor];
|
||||
return p;
|
||||
}
|
||||
|
||||
- (void)handleJoystickAxisMotionX:(int)x andY:(int)y forJoystick:(GameControllerJoystick)joystick {
|
||||
if (joystick == kGameControllerJoystickLeft) {
|
||||
[view addEvent:InternalEvent(kInputJoystickAxisMotion, Common::JOYSTICK_AXIS_LEFT_STICK_X, x)];
|
||||
[view addEvent:InternalEvent(kInputJoystickAxisMotion, Common::JOYSTICK_AXIS_LEFT_STICK_Y, y)];
|
||||
} else {
|
||||
[view addEvent:InternalEvent(kInputJoystickAxisMotion, Common::JOYSTICK_AXIS_RIGHT_STICK_X, x)];
|
||||
[view addEvent:InternalEvent(kInputJoystickAxisMotion, Common::JOYSTICK_AXIS_RIGHT_STICK_Y, y)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleJoystickButtonAction:(int)button isPressed:(bool)pressed {
|
||||
bool addEvent = true;
|
||||
if (button == Common::JOYSTICK_BUTTON_A) {
|
||||
if (_firstButtonPressed) {
|
||||
if (pressed) {
|
||||
addEvent = false;
|
||||
}
|
||||
}
|
||||
_firstButtonPressed = pressed;
|
||||
} else if (button == Common::JOYSTICK_BUTTON_B) {
|
||||
if (_secondButtonPressed) {
|
||||
if (pressed) {
|
||||
addEvent = false;
|
||||
}
|
||||
}
|
||||
_secondButtonPressed = pressed;
|
||||
}
|
||||
// Do not send button presses if keyboard is shown because if e.g.
|
||||
// the "Do you want to quit?" dialog is shown the wait for user
|
||||
// input will end (treating the button push as a mouse click) while
|
||||
// the user tried to select the "y" or "n" character on the tvOS
|
||||
// keyboard.
|
||||
if (addEvent && ![view isKeyboardShown]) {
|
||||
[view addEvent:InternalEvent(pressed ? kInputJoystickButtonDown : kInputJoystickButtonUp, button, 0)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleMainMenu:(BOOL)pressed {
|
||||
if (!pressed) { // released
|
||||
[view handleMainMenuKey];
|
||||
}
|
||||
}
|
||||
@end
|
||||
35
backends/platform/ios7/ios7_gamepad_controller.h
Normal file
35
backends/platform/ios7/ios7_gamepad_controller.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_GAMEPAD_CONTROLLER_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_GAMEPAD_CONTROLLER_H
|
||||
|
||||
#include "backends/platform/ios7/ios7_game_controller.h"
|
||||
|
||||
API_AVAILABLE(ios(7.0))
|
||||
@interface GamepadController : GameController
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view;
|
||||
- (void)virtualController:(bool)connect;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* BACKENDS_PLATFORM_IOS7_IOS7_GAMEPAD_CONTROLLER_H */
|
||||
317
backends/platform/ios7/ios7_gamepad_controller.mm
Normal file
317
backends/platform/ios7/ios7_gamepad_controller.mm
Normal file
@@ -0,0 +1,317 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "common/events.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "backends/platform/ios7/ios7_gamepad_controller.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
#include <GameController/GameController.h>
|
||||
|
||||
@implementation GamepadController {
|
||||
GCController *_controller;
|
||||
#if TARGET_OS_IOS
|
||||
#ifdef __IPHONE_15_0
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualController *_virtualControllerThumbstick;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualController *_virtualControllerMiniThumbstick;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualController *_virtualControllerDpad;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualController *_virtualControllerMiniDpad;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualController *_currentController;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualControllerConfiguration *_configDpad;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualControllerConfiguration *_configMiniDpad;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualControllerConfiguration *_configThumbstick;
|
||||
API_AVAILABLE(ios(15.0))
|
||||
GCVirtualControllerConfiguration *_configMiniThumbstick;
|
||||
#endif
|
||||
#endif
|
||||
int _currentDpadXValue;
|
||||
int _currentDpadYValue;
|
||||
}
|
||||
|
||||
@dynamic view;
|
||||
@dynamic isConnected;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view {
|
||||
self = [super initWithView:view];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(controllerDidConnect:)
|
||||
name:@"GCControllerDidConnectNotification"
|
||||
object:nil];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
#ifdef __IPHONE_15_0
|
||||
if (@available(iOS 15.0, *)) {
|
||||
// Configure a simple game controller with dPad and A and B buttons
|
||||
_configDpad = [[GCVirtualControllerConfiguration alloc] init];
|
||||
_configMiniDpad = [[GCVirtualControllerConfiguration alloc] init];
|
||||
_configThumbstick = [[GCVirtualControllerConfiguration alloc] init];
|
||||
_configMiniThumbstick = [[GCVirtualControllerConfiguration alloc] init];
|
||||
|
||||
NSArray<NSString *> *_commonElements = [[NSArray alloc] initWithObjects: GCInputButtonA, GCInputButtonB, GCInputButtonX, GCInputButtonY, nil];
|
||||
NSArray<NSString *> *_additionalElements = [[NSArray alloc] initWithObjects: GCInputRightThumbstick, GCInputLeftShoulder, GCInputRightShoulder, nil];
|
||||
|
||||
NSMutableSet<NSString *> *_fullSetElementsThumbstick = [[NSMutableSet alloc] initWithObjects: GCInputLeftThumbstick, nil];
|
||||
[_fullSetElementsThumbstick addObjectsFromArray:_commonElements];
|
||||
[_fullSetElementsThumbstick addObjectsFromArray:_additionalElements];
|
||||
|
||||
NSMutableSet<NSString *> *_miniSetElementsThumbstick = [[NSMutableSet alloc] initWithObjects:GCInputLeftThumbstick, nil];
|
||||
[_miniSetElementsThumbstick addObjectsFromArray:_commonElements];
|
||||
|
||||
NSMutableSet<NSString *> *_fullSetElementsDpad = [[NSMutableSet alloc] initWithObjects: GCInputDirectionalDpad, nil];
|
||||
[_fullSetElementsDpad addObjectsFromArray:_commonElements];
|
||||
[_fullSetElementsDpad addObjectsFromArray:_additionalElements];
|
||||
|
||||
NSMutableSet<NSString *> *_miniSetElementsDpad = [[NSMutableSet alloc] initWithObjects:GCInputDirectionalDpad, nil];
|
||||
[_miniSetElementsDpad addObjectsFromArray:_commonElements];
|
||||
|
||||
_configThumbstick.elements = _fullSetElementsThumbstick;
|
||||
_configMiniThumbstick.elements = _miniSetElementsThumbstick;
|
||||
_configDpad.elements = _fullSetElementsDpad;
|
||||
_configMiniDpad.elements = _miniSetElementsDpad;
|
||||
|
||||
[_miniSetElementsDpad release];
|
||||
[_fullSetElementsDpad release];
|
||||
[_miniSetElementsThumbstick release];
|
||||
[_fullSetElementsThumbstick release];
|
||||
[_commonElements release];
|
||||
[_additionalElements release];
|
||||
|
||||
_virtualControllerThumbstick = [[GCVirtualController alloc] initWithConfiguration:_configThumbstick];
|
||||
_virtualControllerMiniThumbstick = [[GCVirtualController alloc] initWithConfiguration:_configMiniThumbstick];
|
||||
_virtualControllerDpad = [[GCVirtualController alloc] initWithConfiguration:_configDpad];
|
||||
_virtualControllerMiniDpad = [[GCVirtualController alloc] initWithConfiguration:_configMiniDpad];
|
||||
_currentController = _virtualControllerThumbstick;
|
||||
|
||||
[_configDpad release];
|
||||
[_configMiniDpad release];
|
||||
[_configThumbstick release];
|
||||
[_configMiniThumbstick release];
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
_currentDpadXValue = 0;
|
||||
_currentDpadYValue = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
// Undocumented way to retrieve the GCControllerView.
|
||||
// Drill down the layer structure to get the GCControllerView.
|
||||
// The view layers for iPhones are:
|
||||
// - TransitionView
|
||||
// - DropShadowView
|
||||
// - LayoutContainerView
|
||||
// - ContainerView
|
||||
// iPads have an additional layer under the ContainerView
|
||||
#if TARGET_OS_IOS
|
||||
- (BOOL)setGCControllerViewProperties:(NSArray<UIView*>*)subviews {
|
||||
BOOL stop = NO;
|
||||
for (UIView *view in subviews) {
|
||||
if ([[view classForCoder] isEqual:NSClassFromString(@"GCControllerView")]) {
|
||||
// Set the frame alpha to the user specified value
|
||||
// to make the virtual controller more transparent
|
||||
view.alpha = ((float)ConfMan.getInt("gamepad_controller_opacity") / 10.0);
|
||||
stop = YES;
|
||||
} else {
|
||||
// Keep drilling
|
||||
stop = [self setGCControllerViewProperties:view.subviews];
|
||||
}
|
||||
if (stop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stop;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)virtualController:(bool)connect {
|
||||
#if TARGET_OS_IOS
|
||||
#ifdef __IPHONE_15_0
|
||||
if (@available(iOS 15.0, *)) {
|
||||
GCVirtualController *controller;
|
||||
switch (ConfMan.getInt("gamepad_controller_directional_input")) {
|
||||
case kDirectionalInputThumbstick:
|
||||
controller = ConfMan.getBool("gamepad_controller_minimal_layout") ? _virtualControllerMiniThumbstick : _virtualControllerThumbstick;
|
||||
break;
|
||||
case kDirectionalInputDpad:
|
||||
default:
|
||||
controller = ConfMan.getBool("gamepad_controller_minimal_layout") ? _virtualControllerMiniDpad : _virtualControllerDpad;
|
||||
break;
|
||||
}
|
||||
|
||||
if (_currentController != controller) {
|
||||
[_currentController disconnect];
|
||||
}
|
||||
|
||||
if (connect) {
|
||||
[controller connectWithReplyHandler:^(NSError * _Nullable error) {
|
||||
[self setGCControllerViewProperties:[[[UIApplication sharedApplication] keyWindow] subviews]];
|
||||
}];
|
||||
_currentController = controller;
|
||||
}
|
||||
else {
|
||||
[_currentController disconnect];
|
||||
[self setIsConnected:NO];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)controllerDidConnect:(NSNotification *)notification {
|
||||
_controller = (GCController*)notification.object;
|
||||
|
||||
#if TARGET_OS_TV
|
||||
if (_controller.microGamepad != nil) {
|
||||
[self setIsConnected:YES];
|
||||
|
||||
_controller.microGamepad.buttonA.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_A isPressed:pressed];
|
||||
};
|
||||
|
||||
_controller.microGamepad.buttonX.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
// Map button X to button B because B is mapped to left button
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_B isPressed:pressed];
|
||||
};
|
||||
|
||||
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
||||
_controller.microGamepad.buttonMenu.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleMainMenu:pressed];
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (_controller.extendedGamepad != nil) {
|
||||
[self setIsConnected:YES];
|
||||
|
||||
_controller.extendedGamepad.leftThumbstick.valueChangedHandler = ^(GCControllerDirectionPad * _Nonnull dpad, float xValue, float yValue) {
|
||||
// Convert the given axis values in float (-1 to 1) to ScummVM Joystick
|
||||
// Axis value as integers (0 to int16_max)
|
||||
int x = xValue * (float)Common::JOYAXIS_MAX;
|
||||
int y = yValue * (float)Common::JOYAXIS_MAX;
|
||||
|
||||
// Apple's Y values are reversed from ScummVM's
|
||||
[self handleJoystickAxisMotionX:x andY:0-y forJoystick:kGameControllerJoystickLeft];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.rightThumbstick.valueChangedHandler = ^(GCControllerDirectionPad * _Nonnull dpad, float xValue, float yValue) {
|
||||
// Convert the given axis values in float (-1 to 1) to ScummVM Joystick
|
||||
// Axis value as integers (0 to int16_max)
|
||||
int x = xValue * (float)Common::JOYAXIS_MAX;
|
||||
int y = yValue * (float)Common::JOYAXIS_MAX;
|
||||
|
||||
// Apple's Y values are reversed from ScummVM's
|
||||
[self handleJoystickAxisMotionX:x andY:0-y forJoystick:kGameControllerJoystickRight];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.dpad.valueChangedHandler = ^(GCControllerDirectionPad * _Nonnull dpad, float xValue, float yValue) {
|
||||
// Negative values are left/down, positive are right/up, 0 is no press
|
||||
// Change xValue to only be -1, 0, or 1
|
||||
xValue = xValue < 0.f ? -1.f : xValue > 0.f ? 1.f : 0.f;
|
||||
if (xValue != _currentDpadXValue) {
|
||||
if (_currentDpadXValue < 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_LEFT isPressed:false];
|
||||
} else if (_currentDpadXValue > 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_RIGHT isPressed:false];
|
||||
}
|
||||
if (xValue < 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_LEFT isPressed:true];
|
||||
} else if (xValue > 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_RIGHT isPressed:true];
|
||||
}
|
||||
_currentDpadXValue = xValue;
|
||||
}
|
||||
|
||||
// Change yValue to only be -1, 0, or 1
|
||||
yValue = yValue < 0.f ? -1.f : yValue > 0.f ? 1.f : 0.f;
|
||||
if (yValue != _currentDpadYValue) {
|
||||
if (_currentDpadYValue < 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_DOWN isPressed:false];
|
||||
} else if (_currentDpadYValue > 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_UP isPressed:false];
|
||||
}
|
||||
if (yValue < 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_DOWN isPressed:true];
|
||||
} else if (yValue > 0) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_UP isPressed:true];
|
||||
}
|
||||
_currentDpadYValue = yValue;
|
||||
}
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.buttonA.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_A isPressed:pressed];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.buttonB.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_B isPressed:pressed];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.buttonX.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_X isPressed:pressed];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.buttonY.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_Y isPressed:pressed];
|
||||
};
|
||||
#ifdef __IPHONE_12_1
|
||||
if (@available(iOS 12.1, tvOS 12.1, *)) {
|
||||
_controller.extendedGamepad.leftThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_LEFT_STICK isPressed:pressed];
|
||||
};
|
||||
}
|
||||
|
||||
if (@available(iOS 12.1, tvOS 12.1, *)) {
|
||||
_controller.extendedGamepad.rightThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_RIGHT_STICK isPressed:pressed];
|
||||
};
|
||||
}
|
||||
#endif
|
||||
_controller.extendedGamepad.leftShoulder.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_LEFT_SHOULDER isPressed:pressed];
|
||||
};
|
||||
|
||||
_controller.extendedGamepad.rightShoulder.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_RIGHT_SHOULDER isPressed:pressed];
|
||||
};
|
||||
|
||||
#ifdef __IPHONE_13_0
|
||||
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
||||
_controller.extendedGamepad.buttonMenu.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[self handleMainMenu:pressed];
|
||||
};
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
48
backends/platform/ios7/ios7_keyboard.h
Normal file
48
backends/platform/ios7/ios7_keyboard.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_KEYBOARD_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_KEYBOARD_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
#include <UIKit/UITextView.h>
|
||||
|
||||
@class TextInputHandler;
|
||||
|
||||
@interface SoftKeyboard : UIView<UITextFieldDelegate> {
|
||||
id inputDelegate;
|
||||
TextInputHandler *inputView;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame;
|
||||
- (void)dealloc;
|
||||
- (UITextField *)inputView;
|
||||
- (void)setInputDelegate:(id)delegate;
|
||||
- (void)handleKeyPress:(unichar)c withModifierFlags:(int)f;
|
||||
- (void)handleMainMenuKey;
|
||||
|
||||
- (void)showKeyboard;
|
||||
- (void)hideKeyboard;
|
||||
- (BOOL)isKeyboardShown;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
829
backends/platform/ios7/ios7_keyboard.mm
Normal file
829
backends/platform/ios7/ios7_keyboard.mm
Normal file
@@ -0,0 +1,829 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "backends/platform/ios7/ios7_keyboard.h"
|
||||
#include "common/keyboard.h"
|
||||
#include "common/config-manager.h"
|
||||
#ifdef __IPHONE_14_0
|
||||
#include <GameController/GameController.h>
|
||||
#endif
|
||||
|
||||
@interface UITextInputTraits
|
||||
- (void)setAutocorrectionType:(int)type;
|
||||
- (void)setAutocapitalizationType:(int)type;
|
||||
- (void)setEnablesReturnKeyAutomatically:(BOOL)val;
|
||||
@end
|
||||
|
||||
@interface TextInputHandler : UITextField<UITabBarDelegate, UITextInput> {
|
||||
SoftKeyboard *softKeyboard;
|
||||
UITabBar *toolbar;
|
||||
UIScrollView *scrollView;
|
||||
}
|
||||
|
||||
- (id)initWithKeyboard:(SoftKeyboard *)keyboard;
|
||||
- (void)dealloc;
|
||||
- (void)attachAccessoryView;
|
||||
- (void)detachAccessoryView;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TextInputHandler
|
||||
|
||||
- (id)initWithKeyboard:(SoftKeyboard *)keyboard {
|
||||
self = [super initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
|
||||
softKeyboard = keyboard;
|
||||
|
||||
[self setAutocorrectionType:UITextAutocorrectionTypeNo];
|
||||
[self setSpellCheckingType:UITextSpellCheckingTypeNo];
|
||||
[self setAutocapitalizationType:UITextAutocapitalizationTypeNone];
|
||||
[self setEnablesReturnKeyAutomatically:NO];
|
||||
#if TARGET_OS_IOS
|
||||
// Hide the input assistent bar. The API is only available since IOS 9.0.
|
||||
// The code only compils with the iOS 9.0+ SDK, and only works on iOS 9.0
|
||||
// or above.
|
||||
#ifdef __IPHONE_9_0
|
||||
if ( @available(iOS 9,*) ) {
|
||||
UITextInputAssistantItem* item = [self inputAssistantItem];
|
||||
if (item) {
|
||||
item.leadingBarButtonGroups = @[];
|
||||
item.trailingBarButtonGroups = @[];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
toolbar = [[UITabBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
|
||||
toolbar.barTintColor = keyboard.backgroundColor;
|
||||
toolbar.tintColor = [UIColor grayColor];
|
||||
toolbar.translucent = NO;
|
||||
toolbar.delegate = self;
|
||||
|
||||
toolbar.items = @[
|
||||
// Keyboard layout button
|
||||
[[[UITabBarItem alloc] initWithTitle:@"123" image:nil tag:0] autorelease],
|
||||
// GMM button
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u2630" image:nil tag:1] autorelease],
|
||||
// Escape key
|
||||
[[[UITabBarItem alloc] initWithTitle:@"Esc" image:nil tag:2] autorelease],
|
||||
// Tab key
|
||||
[[[UITabBarItem alloc] initWithTitle:@"Tab" image:nil tag:3] autorelease],
|
||||
// Return key
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u23ce" image:nil tag:4] autorelease],
|
||||
// Function keys
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F1" image:nil tag:5] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F2" image:nil tag:6] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F3" image:nil tag:7] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F4" image:nil tag:8] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F5" image:nil tag:9] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F6" image:nil tag:10] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F7" image:nil tag:11] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F8" image:nil tag:12] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F9" image:nil tag:13] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F10" image:nil tag:14] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F11" image:nil tag:15] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"F12" image:nil tag:16] autorelease],
|
||||
// Arrow keys
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u2190" image:nil tag:17] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u2191" image:nil tag:18] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u2192" image:nil tag:19] autorelease],
|
||||
[[[UITabBarItem alloc] initWithTitle:@"\u2193" image:nil tag:20] autorelease]
|
||||
];
|
||||
|
||||
// Increase the font size on the UITabBarItems to make them readable on small displays
|
||||
for (UITabBarItem *item in toolbar.items) {
|
||||
[item setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:20.0], NSFontAttributeName, nil] forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
#if TARGET_OS_TV
|
||||
// In tvOS a UITabBarItem is selected when moving to the selected item, in other words
|
||||
// no click is required. This is not a great user experience since the user needs to
|
||||
// scroll to the wanted UITabBarItem causing the delegate function
|
||||
// tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item to be called multiple
|
||||
// times. Instead add a tap gesture on the UITabBar and let the delegate function set
|
||||
// the selected item. Then trigger the action when the user press the button.
|
||||
UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectUITabBarItem:)] autorelease];
|
||||
[toolbar addGestureRecognizer:tapGesture];
|
||||
#endif
|
||||
|
||||
self.inputAccessoryView = toolbar;
|
||||
[toolbar sizeToFit];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
// In tvOS the UITabBar is scrollable but not in iOS. In iOS the UITabBar must be
|
||||
// put in a UIScrollView to be scrollable.
|
||||
scrollView = [[UIScrollView alloc] init];
|
||||
scrollView.frame = toolbar.frame;
|
||||
scrollView.bounds = toolbar.bounds;
|
||||
scrollView.autoresizingMask = toolbar.autoresizingMask;
|
||||
scrollView.showsVerticalScrollIndicator = false;
|
||||
scrollView.showsHorizontalScrollIndicator = false;
|
||||
scrollView.bounces = false;
|
||||
toolbar.autoresizingMask = UIViewAutoresizingNone;
|
||||
[scrollView addSubview:toolbar];
|
||||
self.inputAccessoryView = nil;
|
||||
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)dealloc {
|
||||
[toolbar release];
|
||||
[scrollView release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/* There's a difference between UITextFields and UITextViews that the
|
||||
* delegate function textView:shouldChangeTextInRange:replacementText:
|
||||
* is called when pressing the backward button on a keyboard also when
|
||||
* the textView is empty. This is not the case for UITextFields, the
|
||||
* function textField:shouldChangeTextInRange:replacementText: is not
|
||||
* called if the textField is empty which is problematic in the cases
|
||||
* where there's already text in the open dialog (e.g. the save dialog
|
||||
* when the user wants to overwrite an existing slot). There's currently
|
||||
* no possibility to propagate existing text elements from dialog into
|
||||
* the textField. To be able to handle the cases where the user wants to
|
||||
* delete existing texts when the textField is empty the inputView has
|
||||
* to implement the UITextInput protocol function deleteBackward that is
|
||||
* called every time the backward key is pressed.
|
||||
* Propagate all delete callbacks to the backend.
|
||||
*/
|
||||
-(void)deleteBackward {
|
||||
[softKeyboard handleKeyPress:'\b' withModifierFlags:0];
|
||||
[super deleteBackward];
|
||||
}
|
||||
|
||||
-(void)selectUITabBarItem:(UITapGestureRecognizer *)recognizer {
|
||||
switch ([[toolbar selectedItem] tag]) {
|
||||
case 0:
|
||||
[self switchKeyboardLayout];
|
||||
break;
|
||||
case 1:
|
||||
[self mainMenuKey];
|
||||
break;
|
||||
case 2:
|
||||
[self escapeKey];
|
||||
break;
|
||||
case 3:
|
||||
[self tabKey];
|
||||
break;
|
||||
case 4:
|
||||
[self returnKey];
|
||||
break;
|
||||
case 5:
|
||||
[self fn1Key];
|
||||
break;
|
||||
case 6:
|
||||
[self fn2Key];
|
||||
break;
|
||||
case 7:
|
||||
[self fn3Key];
|
||||
break;
|
||||
case 8:
|
||||
[self fn4Key];
|
||||
break;
|
||||
case 9:
|
||||
[self fn5Key];
|
||||
break;
|
||||
case 10:
|
||||
[self fn6Key];
|
||||
break;
|
||||
case 11:
|
||||
[self fn7Key];
|
||||
break;
|
||||
case 12:
|
||||
[self fn8Key];
|
||||
break;
|
||||
case 13:
|
||||
[self fn9Key];
|
||||
break;
|
||||
case 14:
|
||||
[self fn10Key];
|
||||
break;
|
||||
case 15:
|
||||
[self fn11Key];
|
||||
break;
|
||||
case 16:
|
||||
[self fn12Key];
|
||||
break;
|
||||
case 17:
|
||||
[self leftArrowKey];
|
||||
break;
|
||||
case 18:
|
||||
[self upArrowKey];
|
||||
break;
|
||||
case 19:
|
||||
[self rightArrowKey];
|
||||
break;
|
||||
case 20:
|
||||
[self downArrowKey];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
|
||||
#if TARGET_OS_IOS
|
||||
// In iOS the UITabBarItem is selected on touch. Trigger the action
|
||||
// on the selected item.
|
||||
[self selectUITabBarItem:nil];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)attachAccessoryView {
|
||||
// We need at least a width of 1024 pt for the toolbar. If we add more buttons this may need to be increased.
|
||||
toolbar.frame = CGRectMake(0, 0, MAX(CGFloat(1024), [[UIScreen mainScreen] bounds].size.width), toolbar.frame.size.height);
|
||||
toolbar.bounds = toolbar.frame;
|
||||
toolbar.selectedItem = nil;
|
||||
self.inputAccessoryView = toolbar;
|
||||
#if TARGET_OS_IOS
|
||||
scrollView.contentSize = toolbar.frame.size;
|
||||
self.inputAccessoryView = scrollView;
|
||||
#endif
|
||||
[self reloadInputViews];
|
||||
}
|
||||
|
||||
- (void)detachAccessoryView {
|
||||
self.inputAccessoryView = nil;
|
||||
[self reloadInputViews];
|
||||
}
|
||||
|
||||
- (void) setWantsPriority: (UIKeyCommand*) keyCommand {
|
||||
// In iOS 15 the UIKeyCommand has a new property wantsPriorityOverSystemBehavior that is needed to
|
||||
// receive some keys (such as the arrow keys).
|
||||
if ([keyCommand respondsToSelector:@selector(setWantsPriorityOverSystemBehavior:)]) {
|
||||
[keyCommand setValue:[NSNumber numberWithBool:YES] forKey:@"wantsPriorityOverSystemBehavior"];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIKeyCommand *)createKeyCommandForKey:(NSString *)key withModifierFlags:(UIKeyModifierFlags)flags andSelector:(SEL)selector {
|
||||
UIKeyCommand *k = [UIKeyCommand keyCommandWithInput:key modifierFlags:flags action:selector];
|
||||
[self setWantsPriority:k];
|
||||
return k;
|
||||
}
|
||||
|
||||
- (NSArray *)overloadKeys:(NSArray<NSString *> *)keys withSelector:(SEL)selector {
|
||||
NSMutableArray<UIKeyCommand *> *overloadedKeys = [[[NSMutableArray alloc] init] autorelease];
|
||||
for (NSString *key in keys) {
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:0 andSelector:selector]];
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierShift andSelector:selector]];
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierControl andSelector:selector]];
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierAlternate andSelector:selector]];
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierCommand andSelector:selector]];
|
||||
// UIKeyModifierAlphaShift seems broken since iOS 13
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierAlphaShift andSelector:selector]];
|
||||
[overloadedKeys addObject:[self createKeyCommandForKey:key withModifierFlags:UIKeyModifierNumericPad andSelector:selector]];
|
||||
}
|
||||
return overloadedKeys;
|
||||
}
|
||||
|
||||
- (NSArray *)overloadArrowKeys {
|
||||
NSArray<NSString *> *arrowKeys = [[[NSArray alloc] initWithObjects:UIKeyInputUpArrow, UIKeyInputDownArrow, UIKeyInputLeftArrow, UIKeyInputRightArrow, nil] autorelease];
|
||||
return [self overloadKeys:arrowKeys withSelector:@selector(handleArrowKey:)];
|
||||
}
|
||||
|
||||
- (NSArray *)overloadRomanLetters {
|
||||
NSString *romanLetters = @"abcdefghijklmnopqrstuvwxyz";
|
||||
NSMutableArray<NSString *> *letters = [[[NSMutableArray alloc] init] autorelease];
|
||||
for (NSUInteger x = 0; x < romanLetters.length; x++) {
|
||||
unichar c = [romanLetters characterAtIndex:x];
|
||||
[letters addObject:[NSString stringWithCharacters:&c length:1]];
|
||||
}
|
||||
return [self overloadKeys:letters withSelector:@selector(handleLetterKey:)];;
|
||||
}
|
||||
|
||||
- (NSArray *)overloadNumbers {
|
||||
NSString *numbers = @"0123456789";
|
||||
NSMutableArray<NSString *> *numArray = [[[NSMutableArray alloc] init] autorelease];
|
||||
for (NSUInteger x = 0; x < numbers.length; x++) {
|
||||
unichar c = [numbers characterAtIndex:x];
|
||||
[numArray addObject:[NSString stringWithCharacters:&c length:1]];
|
||||
}
|
||||
return [self overloadKeys:numArray withSelector:@selector(handleNumberKey:)];
|
||||
}
|
||||
|
||||
- (NSArray *)overloadFnKeys {
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
NSArray<NSString *> *fnKeys = [[[NSArray alloc] initWithObjects:UIKeyInputF1, UIKeyInputF2, UIKeyInputF3, UIKeyInputF4, UIKeyInputF5, UIKeyInputF6, UIKeyInputF7, UIKeyInputF8, UIKeyInputF9, UIKeyInputF10, UIKeyInputF11, UIKeyInputF12, nil] autorelease];
|
||||
return [self overloadKeys:fnKeys withSelector:@selector(handleFnKey:)];
|
||||
}
|
||||
#endif
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSArray *)overloadSpecialKeys {
|
||||
#ifdef __IPHONE_13_4
|
||||
NSMutableArray<NSString *> *specialKeys = [[[NSMutableArray alloc] initWithObjects:UIKeyInputEscape, UIKeyInputPageUp, UIKeyInputPageDown, nil] autorelease];
|
||||
|
||||
if (@available(iOS 13.4, *)) {
|
||||
[specialKeys addObject: UIKeyInputHome];
|
||||
[specialKeys addObject: UIKeyInputEnd];
|
||||
}
|
||||
return [self overloadKeys:specialKeys withSelector:@selector(handleSpecialKey:)];
|
||||
#else
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (int)convertModifierFlags:(UIKeyModifierFlags)flags {
|
||||
return (((flags & UIKeyModifierShift) ? Common::KBD_SHIFT : 0) |
|
||||
((flags & UIKeyModifierControl) ? Common::KBD_CTRL : 0) |
|
||||
((flags & UIKeyModifierAlternate) ? Common::KBD_ALT : 0) |
|
||||
((flags & UIKeyModifierCommand) ? Common::KBD_META : 0) |
|
||||
((flags & UIKeyModifierAlphaShift) ? Common::KBD_CAPS : 0) |
|
||||
((flags & UIKeyModifierNumericPad) ? Common::KBD_NUM : 0));
|
||||
}
|
||||
|
||||
- (void)handleArrowKey:(UIKeyCommand *)keyCommand {
|
||||
if (keyCommand.input == UIKeyInputUpArrow) {
|
||||
[self upArrow:keyCommand];
|
||||
} else if (keyCommand.input == UIKeyInputDownArrow) {
|
||||
[self downArrow:keyCommand];
|
||||
} else if (keyCommand.input == UIKeyInputLeftArrow) {
|
||||
[self leftArrow:keyCommand];
|
||||
} else {
|
||||
[self rightArrow:keyCommand];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleLetterKey:(UIKeyCommand *)keyCommand {
|
||||
UniChar c = [[keyCommand input] characterAtIndex:0];
|
||||
if ((keyCommand.modifierFlags & UIKeyModifierShift) ||
|
||||
(keyCommand.modifierFlags & UIKeyModifierAlphaShift)) {
|
||||
// Convert to capital letter
|
||||
c -= 32;
|
||||
}
|
||||
[softKeyboard handleKeyPress: c withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
|
||||
- (void)handleNumberKey:(UIKeyCommand *)keyCommand {
|
||||
if (keyCommand.modifierFlags == UIKeyModifierCommand) {
|
||||
switch ([[keyCommand input] characterAtIndex:0]) {
|
||||
case '1':
|
||||
[self fn1Key];
|
||||
break;
|
||||
case '2':
|
||||
[self fn2Key];
|
||||
break;
|
||||
case '3':
|
||||
[self fn3Key];
|
||||
break;
|
||||
case '4':
|
||||
[self fn4Key];
|
||||
break;
|
||||
case '5':
|
||||
[self fn5Key];
|
||||
break;
|
||||
case '6':
|
||||
[self fn6Key];
|
||||
break;
|
||||
case '7':
|
||||
[self fn7Key];
|
||||
break;
|
||||
case '8':
|
||||
[self fn8Key];
|
||||
break;
|
||||
case '9':
|
||||
[self fn9Key];
|
||||
break;
|
||||
case '0':
|
||||
[self fn10Key];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (keyCommand.modifierFlags == (UIKeyModifierCommand | UIKeyModifierShift)) {
|
||||
switch ([[keyCommand input] characterAtIndex:0]) {
|
||||
case '1':
|
||||
[self fn11Key];
|
||||
break;
|
||||
case '2':
|
||||
[self fn12Key];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
[softKeyboard handleKeyPress: [[keyCommand input] characterAtIndex:0] withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleFnKey:(UIKeyCommand *)keyCommand {
|
||||
#ifdef __IPHONE_13_4
|
||||
if (@available(iOS 13.4, *)) {
|
||||
if (keyCommand.input == UIKeyInputF1) {
|
||||
[self fn1Key];
|
||||
} else if (keyCommand.input == UIKeyInputF2) {
|
||||
[self fn2Key];
|
||||
} else if (keyCommand.input == UIKeyInputF3) {
|
||||
[self fn3Key];
|
||||
} else if (keyCommand.input == UIKeyInputF4) {
|
||||
[self fn4Key];
|
||||
} else if (keyCommand.input == UIKeyInputF5) {
|
||||
[self fn5Key];
|
||||
} else if (keyCommand.input == UIKeyInputF6) {
|
||||
[self fn6Key];
|
||||
} else if (keyCommand.input == UIKeyInputF7) {
|
||||
[self fn7Key];
|
||||
} else if (keyCommand.input == UIKeyInputF8) {
|
||||
[self fn8Key];
|
||||
} else if (keyCommand.input == UIKeyInputF9) {
|
||||
[self fn9Key];
|
||||
} else if (keyCommand.input == UIKeyInputF10) {
|
||||
[self fn10Key];
|
||||
} else if (keyCommand.input == UIKeyInputF11) {
|
||||
[self fn11Key];
|
||||
} else if (keyCommand.input == UIKeyInputF12) {
|
||||
[self fn12Key];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)handleSpecialKey:(UIKeyCommand *)keyCommand {
|
||||
#ifdef __IPHONE_13_4
|
||||
if (keyCommand.input == UIKeyInputEscape) {
|
||||
[self escapeKey:keyCommand];
|
||||
} else if (keyCommand.input == UIKeyInputPageUp) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_PAGEUP withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
} else if (keyCommand.input == UIKeyInputPageDown) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_PAGEDOWN withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
if (@available(iOS 13.4, *)) {
|
||||
if (keyCommand.input == UIKeyInputHome) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_HOME withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
} else if (keyCommand.input == UIKeyInputEnd) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_END withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (NSArray *)keyCommands {
|
||||
NSMutableArray<UIKeyCommand *> *overloadedKeys = [[[NSMutableArray alloc] init] autorelease];
|
||||
// Arrows
|
||||
[overloadedKeys addObjectsFromArray:[self overloadArrowKeys]];
|
||||
// Roman letters
|
||||
[overloadedKeys addObjectsFromArray:[self overloadRomanLetters]];
|
||||
// Numbers
|
||||
[overloadedKeys addObjectsFromArray:[self overloadNumbers]];
|
||||
// FN keys
|
||||
[overloadedKeys addObjectsFromArray:[self overloadFnKeys]];
|
||||
// ESC, PAGE_UP, PAGE_DOWN, HOME, END
|
||||
[overloadedKeys addObjectsFromArray:[self overloadSpecialKeys]];
|
||||
|
||||
return overloadedKeys;
|
||||
}
|
||||
|
||||
- (void) upArrow: (UIKeyCommand *) keyCommand {
|
||||
if (keyCommand.modifierFlags == UIKeyModifierCommand) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_PAGEUP withModifierFlags:0];
|
||||
} else {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_UP withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) downArrow: (UIKeyCommand *) keyCommand {
|
||||
if (keyCommand.modifierFlags == UIKeyModifierCommand) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_PAGEDOWN withModifierFlags:0];
|
||||
} else {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_DOWN withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) leftArrow: (UIKeyCommand *) keyCommand {
|
||||
if (keyCommand.modifierFlags == UIKeyModifierCommand) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_HOME withModifierFlags:0];
|
||||
} else {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_LEFT withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) rightArrow: (UIKeyCommand *) keyCommand {
|
||||
if (keyCommand.modifierFlags == UIKeyModifierCommand) {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_END withModifierFlags:0];
|
||||
} else {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_RIGHT withModifierFlags:[self convertModifierFlags:keyCommand.modifierFlags]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) escapeKey: (UIKeyCommand *) keyCommand {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_ESCAPE withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) mainMenuKey {
|
||||
[softKeyboard handleMainMenuKey];
|
||||
}
|
||||
|
||||
- (void) escapeKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_ESCAPE withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) tabKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_TAB withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn1Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F1 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn2Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F2 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn3Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F3 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn4Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F4 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn5Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F5 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn6Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F6 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn7Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F7 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn8Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F8 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn9Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F9 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn10Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F10 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn11Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F11 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) fn12Key {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_F12 withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) leftArrowKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_LEFT withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) upArrowKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_UP withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) rightArrowKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_RIGHT withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) downArrowKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_DOWN withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) returnKey {
|
||||
[softKeyboard handleKeyPress:Common::KEYCODE_RETURN withModifierFlags:0];
|
||||
}
|
||||
|
||||
- (void) switchKeyboardLayout {
|
||||
if ([self keyboardType] == UIKeyboardTypeDefault) {
|
||||
[self setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
[[toolbar selectedItem] setTitle:@"abc"];
|
||||
} else {
|
||||
[self setKeyboardType:UIKeyboardTypeDefault];
|
||||
[[toolbar selectedItem] setTitle:@"123"];
|
||||
}
|
||||
|
||||
[self reloadInputViews];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation SoftKeyboard {
|
||||
BOOL _keyboardVisible;
|
||||
CGFloat _inputAccessoryHeight;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)resizeParentFrame:(NSNotification*)notification keyboardDidShow:(BOOL)didShow
|
||||
{
|
||||
NSDictionary* userInfo = [notification userInfo];
|
||||
CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
keyboardFrame = [self.superview convertRect:keyboardFrame fromView:nil];
|
||||
|
||||
// Base the new frame size on the current parent frame size
|
||||
CGRect newFrame = self.superview.frame;
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
if (GCKeyboard.coalescedKeyboard != nil) {
|
||||
if (didShow) {
|
||||
// The inputAccessoryView is hidden by setting it to nil. Then when
|
||||
// receiving the UIKeyboardDidHideNotification the height will be 0.
|
||||
// Remember the height of the inputAccessoryView when it's presented
|
||||
// so the main frame can be resized back to the proper size.
|
||||
_inputAccessoryHeight = inputView.inputAccessoryView.frame.size.height;
|
||||
}
|
||||
newFrame.size.height += (_inputAccessoryHeight) * (didShow ? -1 : 1);
|
||||
} else {
|
||||
newFrame.size.height += (keyboardFrame.size.height) * (didShow ? -1 : 1);
|
||||
}
|
||||
} else {
|
||||
newFrame.size.height += (keyboardFrame.size.height) * (didShow ? -1 : 1);
|
||||
}
|
||||
#endif
|
||||
// Resize with a fancy animation
|
||||
NSNumber *rate = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
|
||||
[UIView animateWithDuration:rate.floatValue animations:^{
|
||||
self.superview.frame = newFrame;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)keyboardDidShow:(NSNotification*)notification
|
||||
{
|
||||
// NotificationCenter might notify multiple times
|
||||
// when keyboard did show because the accessoryView
|
||||
// affect the keyboard height. However since we use
|
||||
// UIKeyboardFrameEndUserInfoKey to get the keyboard
|
||||
// it will always have the same value. Make sure to
|
||||
// only handle one notification.
|
||||
if (!_keyboardVisible) {
|
||||
[self resizeParentFrame:notification keyboardDidShow:YES];
|
||||
_keyboardVisible = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyboardDidHide:(NSNotification*)notification
|
||||
{
|
||||
// NotificationCenter will only call this once
|
||||
// when keyboard did hide.
|
||||
[self resizeParentFrame:notification keyboardDidShow:NO];
|
||||
_keyboardVisible = NO;
|
||||
}
|
||||
|
||||
- (void)keyboardDidConnect:(NSNotification*)notification
|
||||
{
|
||||
[inputView becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)keyboardDidDisconnect:(NSNotification*)notification
|
||||
{
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
if (GCKeyboard.coalescedKeyboard == nil) {
|
||||
[inputView endEditing:YES];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardDidShow:)
|
||||
name:UIKeyboardDidShowNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardDidHide:)
|
||||
name:UIKeyboardDidHideNotification
|
||||
object:nil];
|
||||
#endif
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardDidConnect:)
|
||||
name:GCKeyboardDidConnectNotification
|
||||
object:nil];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(keyboardDidDisconnect:)
|
||||
name:GCKeyboardDidDisconnectNotification
|
||||
object:nil];
|
||||
}
|
||||
#endif
|
||||
|
||||
inputDelegate = nil;
|
||||
inputView = [[TextInputHandler alloc] initWithKeyboard:self];
|
||||
inputView.delegate = self;
|
||||
inputView.clearsOnBeginEditing = YES;
|
||||
inputView.keyboardType = UIKeyboardTypeDefault;
|
||||
[inputView layoutIfNeeded];
|
||||
_keyboardVisible = NO;
|
||||
_inputAccessoryHeight = 0.0f;
|
||||
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
// If already connected to a HW keyboard, start
|
||||
// monitoring key presses
|
||||
if (GCKeyboard.coalescedKeyboard != nil) {
|
||||
[inputView becomeFirstResponder];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)text {
|
||||
if (text.length) {
|
||||
[inputDelegate handleKeyPress:[text characterAtIndex:0] withModifierFlags:0];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
|
||||
[inputView returnKey];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)textFieldDidBeginEditing:(UITextField *)textField {
|
||||
if (ConfMan.getBool("keyboard_fn_bar"))
|
||||
[inputView attachAccessoryView];
|
||||
}
|
||||
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
||||
[inputView detachAccessoryView];
|
||||
}
|
||||
|
||||
-(UITextField *)inputView {
|
||||
return inputView;
|
||||
}
|
||||
|
||||
- (void)setInputDelegate:(id)delegate {
|
||||
inputDelegate = delegate;
|
||||
}
|
||||
|
||||
- (void)handleKeyPress:(unichar)c withModifierFlags:(int)f {
|
||||
[inputDelegate handleKeyPress:c withModifierFlags:f];
|
||||
}
|
||||
|
||||
- (void)handleMainMenuKey {
|
||||
[inputDelegate handleMainMenuKey];
|
||||
}
|
||||
|
||||
- (void)showKeyboard {
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
if ([inputView isFirstResponder] &&
|
||||
GCKeyboard.coalescedKeyboard != nil) {
|
||||
if (ConfMan.getBool("keyboard_fn_bar")) {
|
||||
[inputView attachAccessoryView];
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
[inputView becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)hideKeyboard {
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
if ([inputView isFirstResponder] &&
|
||||
GCKeyboard.coalescedKeyboard != nil) {
|
||||
if (!ConfMan.getBool("keyboard_fn_bar")) {
|
||||
[inputView detachAccessoryView];
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
[inputView endEditing:YES];
|
||||
}
|
||||
|
||||
- (BOOL)isKeyboardShown {
|
||||
return [inputView isFirstResponder];
|
||||
}
|
||||
@end
|
||||
46
backends/platform/ios7/ios7_main.mm
Normal file
46
backends/platform/ios7/ios7_main.mm
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
|
||||
int iOS7_argc;
|
||||
char **iOS7_argv;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int returnCode;
|
||||
|
||||
@autoreleasepool {
|
||||
iOS7_argc = argc;
|
||||
iOS7_argv = argv;
|
||||
|
||||
returnCode = UIApplicationMain(argc, argv, @"UIApplication", @"iOS7AppDelegate");
|
||||
}
|
||||
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
45
backends/platform/ios7/ios7_misc.mm
Normal file
45
backends/platform/ios7/ios7_misc.mm
Normal file
@@ -0,0 +1,45 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
|
||||
#include "backends/platform/ios7/ios7_common.h"
|
||||
#include "common/str.h"
|
||||
|
||||
Common::String iOS7_getDocumentsDir() {
|
||||
#if TARGET_OS_IOS
|
||||
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
|
||||
#else
|
||||
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] firstObject];
|
||||
#endif
|
||||
return Common::String([url fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
Common::String iOS7_getAppBundleDir() {
|
||||
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
|
||||
if (bundlePath == nil)
|
||||
return Common::String();
|
||||
return Common::String([bundlePath fileSystemRepresentation]);
|
||||
}
|
||||
34
backends/platform/ios7/ios7_mouse_controller.h
Normal file
34
backends/platform/ios7/ios7_mouse_controller.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_MOUSE_CONTROLLER_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_MOUSE_CONTROLLER_H
|
||||
|
||||
#include "backends/platform/ios7/ios7_game_controller.h"
|
||||
|
||||
API_AVAILABLE(ios(14.0))
|
||||
@interface MouseController : GameController
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* BACKENDS_PLATFORM_IOS7_IOS7_MOUSE_CONTROLLER_H */
|
||||
84
backends/platform/ios7/ios7_mouse_controller.mm
Normal file
84
backends/platform/ios7/ios7_mouse_controller.mm
Normal file
@@ -0,0 +1,84 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "backends/platform/ios7/ios7_mouse_controller.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
#include <GameController/GameController.h>
|
||||
|
||||
@implementation MouseController {
|
||||
#ifdef __IPHONE_14_0
|
||||
GCMouse *_mouse;
|
||||
CGFloat _dxReminder, _dyReminder;
|
||||
#endif
|
||||
}
|
||||
|
||||
@dynamic view;
|
||||
@dynamic isConnected;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view {
|
||||
self = [super initWithView:view];
|
||||
|
||||
if (self) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(mouseDidConnect:)
|
||||
name:@"GCMouseDidConnectNotification"
|
||||
object:nil];
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_14_0
|
||||
_dxReminder = 0.0;
|
||||
_dyReminder = 0.0;
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)mouseDidConnect:(NSNotification *)notification {
|
||||
#ifdef __IPHONE_14_0
|
||||
[self setIsConnected:YES];
|
||||
_mouse = (GCMouse*)notification.object;
|
||||
|
||||
_mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float deltaX, float deltaY) {
|
||||
CGFloat scaledDeltaX = deltaX * [[self view] contentScaleFactor] + _dxReminder;
|
||||
CGFloat scaledDeltaY = deltaY * [[self view] contentScaleFactor] + _dyReminder;
|
||||
// Add any reminding delta values to be summed up and get the integer part of the delta
|
||||
int dx = (int)(scaledDeltaX);
|
||||
int dy = (int)(scaledDeltaY);
|
||||
// Save the new reminders
|
||||
_dxReminder = scaledDeltaX - (CGFloat)dx;
|
||||
_dyReminder = scaledDeltaY - (CGFloat)dy;
|
||||
|
||||
[[self view] addEvent:InternalEvent(kInputMouseDelta, -dx, dy)];
|
||||
};
|
||||
|
||||
_mouse.mouseInput.leftButton.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[[self view] addEvent:InternalEvent(pressed ? kInputMouseLeftButtonDown : kInputMouseLeftButtonUp, 0, 0)];
|
||||
};
|
||||
|
||||
_mouse.mouseInput.rightButton.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
|
||||
[[self view] addEvent:InternalEvent(pressed ? kInputMouseRightButtonDown : kInputMouseRightButtonUp, 0, 0)];
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
602
backends/platform/ios7/ios7_options.mm
Normal file
602
backends/platform/ios7/ios7_options.mm
Normal file
@@ -0,0 +1,602 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "gui/gui-manager.h"
|
||||
#include "gui/message.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "gui/widget.h"
|
||||
#include "gui/widgets/popup.h"
|
||||
|
||||
#include "common/translation.h"
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
|
||||
#include <TargetConditionals.h>
|
||||
|
||||
enum {
|
||||
kGamepadControllerOpacityChanged = 'gcoc',
|
||||
};
|
||||
|
||||
class IOS7OptionsWidget final : public GUI::OptionsContainerWidget {
|
||||
public:
|
||||
explicit IOS7OptionsWidget(GuiObject *boss, const Common::String &name, const Common::String &domain);
|
||||
~IOS7OptionsWidget() override;
|
||||
|
||||
// OptionsContainerWidget API
|
||||
void load() override;
|
||||
bool save() override;
|
||||
bool hasKeys() override;
|
||||
void setEnabled(bool e) override;
|
||||
|
||||
private:
|
||||
// OptionsContainerWidget API
|
||||
void defineLayout(GUI::ThemeEval &layouts, const Common::String &layoutName, const Common::String &overlayedLayout) const override;
|
||||
void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) override;
|
||||
uint32 loadDirectionalInput(const Common::String &setting, bool acceptDefault, uint32 defaultValue);
|
||||
void saveDirectionalInput(const Common::String &setting, uint32 input);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
uint32 loadTouchMode(const Common::String &setting, bool acceptDefault, uint32 defaultValue);
|
||||
void saveTouchMode(const Common::String &setting, uint32 mode);
|
||||
uint32 loadOrientation(const Common::String &setting, bool acceptDefault, uint32 defaultValue);
|
||||
void saveOrientation(const Common::String &setting, uint32 orientation);
|
||||
#endif
|
||||
|
||||
GUI::CheckboxWidget *_gamepadControllerCheckbox;
|
||||
GUI::StaticTextWidget *_gamepadControllerOpacityDesc;
|
||||
GUI::SliderWidget *_gamepadControllerOpacitySlider;
|
||||
GUI::StaticTextWidget *_gamepadControllerOpacityLabel;
|
||||
GUI::StaticTextWidget *_gamepadControllerDirectionalInputDesc;
|
||||
GUI::PopUpWidget *_gamepadControllerDirectionalInputPopUp;
|
||||
GUI::CheckboxWidget *_gamepadControllerMinimalLayoutCheckbox;
|
||||
|
||||
GUI::CheckboxWidget *_keyboardFnBarCheckbox;
|
||||
#if TARGET_OS_IOS
|
||||
GUI::StaticTextWidget *_preferredTouchModeDesc;
|
||||
GUI::StaticTextWidget *_preferredTouchModeMenusDesc;
|
||||
GUI::PopUpWidget *_preferredTouchModeMenusPopUp;
|
||||
GUI::StaticTextWidget *_preferredTouchMode2DGamesDesc;
|
||||
GUI::PopUpWidget *_preferredTouchMode2DGamesPopUp;
|
||||
GUI::StaticTextWidget *_preferredTouchMode3DGamesDesc;
|
||||
GUI::PopUpWidget *_preferredTouchMode3DGamesPopUp;
|
||||
|
||||
GUI::StaticTextWidget *_orientationDesc;
|
||||
GUI::StaticTextWidget *_orientationMenusDesc;
|
||||
GUI::PopUpWidget *_orientationMenusPopUp;
|
||||
GUI::StaticTextWidget *_orientationGamesDesc;
|
||||
GUI::PopUpWidget *_orientationGamesPopUp;
|
||||
|
||||
GUI::CheckboxWidget *_onscreenCheckbox;
|
||||
#endif
|
||||
bool _enabled;
|
||||
};
|
||||
|
||||
IOS7OptionsWidget::IOS7OptionsWidget(GuiObject *boss, const Common::String &name, const Common::String &domain) :
|
||||
OptionsContainerWidget(boss, name, "IOS7OptionsDialog", domain), _enabled(true) {
|
||||
|
||||
_gamepadControllerCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadController", _("Show Gamepad Controller (iOS 15 and later)"));
|
||||
_gamepadControllerOpacityDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerOpacity", _("Gamepad opacity"));
|
||||
_gamepadControllerOpacitySlider = new GUI::SliderWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerOpacitySlider", _("Gamepad opacity"), kGamepadControllerOpacityChanged);
|
||||
_gamepadControllerOpacityLabel = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerOpacityLabel", Common::U32String(" "), Common::U32String(), GUI::ThemeEngine::kFontStyleBold, Common::UNK_LANG, false);
|
||||
_gamepadControllerOpacitySlider->setMinValue(1);
|
||||
_gamepadControllerOpacitySlider->setMaxValue(10);
|
||||
_gamepadControllerDirectionalInputDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerLeftButton", _("Directional button:"));
|
||||
_gamepadControllerDirectionalInputPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerLeftButtonPopUp");
|
||||
_gamepadControllerDirectionalInputPopUp->appendEntry(_("Thumbstick"), kDirectionalInputThumbstick);
|
||||
_gamepadControllerDirectionalInputPopUp->appendEntry(_("Dpad"), kDirectionalInputDpad);
|
||||
_gamepadControllerMinimalLayoutCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.GamepadControllerMinimalLayout", _("Use minimal gamepad layout"));
|
||||
|
||||
_keyboardFnBarCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.KeyboardFunctionBar", _("Show keyboard function bar"));
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
_preferredTouchModeDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.PreferredTouchModeText", _("Choose the preferred touch mode:"));
|
||||
|
||||
const bool inAppDomain = domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
|
||||
if (inAppDomain) {
|
||||
_preferredTouchModeMenusDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.TouchModeMenusText", _("In menus"));
|
||||
_preferredTouchModeMenusPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.TouchModeMenus");
|
||||
_preferredTouchModeMenusPopUp->appendEntry(_("Touchpad emulation"), kTouchModeTouchpad);
|
||||
_preferredTouchModeMenusPopUp->appendEntry(_("Direct mouse"), kTouchModeDirect); // TODO: Find a better name
|
||||
} else {
|
||||
_preferredTouchModeMenusDesc = nullptr;
|
||||
_preferredTouchModeMenusPopUp = nullptr;
|
||||
}
|
||||
|
||||
_preferredTouchMode2DGamesDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.TouchMode2DGamesText", _("In 2D games"));
|
||||
_preferredTouchMode2DGamesPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.TouchMode2DGames");
|
||||
_preferredTouchMode3DGamesDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.TouchMode3DGamesText", _("In 3D games"));
|
||||
_preferredTouchMode3DGamesPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.TouchMode3DGames");
|
||||
|
||||
if (!inAppDomain) {
|
||||
_preferredTouchMode2DGamesPopUp->appendEntry(_("<default>"), kTouchModeTouchpad);
|
||||
_preferredTouchMode3DGamesPopUp->appendEntry(_("<default>"), kTouchModeTouchpad);
|
||||
}
|
||||
|
||||
_preferredTouchMode2DGamesPopUp->appendEntry(_("Touchpad emulation"), kTouchModeTouchpad);
|
||||
_preferredTouchMode3DGamesPopUp->appendEntry(_("Touchpad emulation"), kTouchModeTouchpad);
|
||||
|
||||
_preferredTouchMode2DGamesPopUp->appendEntry(_("Direct mouse"), kTouchModeDirect); // TODO: Find a better name
|
||||
_preferredTouchMode3DGamesPopUp->appendEntry(_("Direct mouse"), kTouchModeDirect);
|
||||
|
||||
_orientationDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OrientationText", _("Select the orientation:"));
|
||||
if (inAppDomain) {
|
||||
_orientationMenusDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OMenusText", _("In menus"));
|
||||
_orientationMenusPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.OMenus");
|
||||
_orientationMenusPopUp->appendEntry(_("Automatic"), kScreenOrientationAuto);
|
||||
_orientationMenusPopUp->appendEntry(_("Portrait"), kScreenOrientationPortrait);
|
||||
_orientationMenusPopUp->appendEntry(_("Landscape"), kScreenOrientationLandscape);
|
||||
} else {
|
||||
_orientationMenusDesc = nullptr;
|
||||
_orientationMenusPopUp = nullptr;
|
||||
}
|
||||
|
||||
_orientationGamesDesc = new GUI::StaticTextWidget(widgetsBoss(), "IOS7OptionsDialog.OGamesText", _("In games"));
|
||||
_orientationGamesPopUp = new GUI::PopUpWidget(widgetsBoss(), "IOS7OptionsDialog.OGames");
|
||||
|
||||
if (!inAppDomain) {
|
||||
_orientationGamesPopUp->appendEntry(_("<default>"), kScreenOrientationAuto);
|
||||
}
|
||||
|
||||
_orientationGamesPopUp->appendEntry(_("Automatic"), kScreenOrientationAuto);
|
||||
_orientationGamesPopUp->appendEntry(_("Portrait"), kScreenOrientationPortrait);
|
||||
_orientationGamesPopUp->appendEntry(_("Landscape"), kScreenOrientationLandscape);
|
||||
|
||||
_onscreenCheckbox = new GUI::CheckboxWidget(widgetsBoss(), "IOS7OptionsDialog.OnscreenControl", _("Show On-screen control"));
|
||||
#endif
|
||||
|
||||
// setEnabled is normally only called from the EditGameDialog, but some options (GamepadController)
|
||||
// should be disabled in all domains if system is running a lower version of iOS than 15.0.
|
||||
setEnabled(_enabled);
|
||||
}
|
||||
|
||||
IOS7OptionsWidget::~IOS7OptionsWidget() {
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::defineLayout(GUI::ThemeEval &layouts, const Common::String &layoutName, const Common::String &overlayedLayout) const {
|
||||
|
||||
layouts.addDialog(layoutName, overlayedLayout)
|
||||
.addLayout(GUI::ThemeLayout::kLayoutVertical)
|
||||
#if TARGET_OS_IOS
|
||||
.addWidget("OnscreenControl", "Checkbox")
|
||||
#endif
|
||||
.addWidget("GamepadController", "Checkbox")
|
||||
.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("GamepadControllerLeftButton", "OptionsLabel")
|
||||
.addWidget("GamepadControllerLeftButtonPopUp", "PopUp")
|
||||
.closeLayout()
|
||||
.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("GamepadControllerOpacity", "OptionsLabel")
|
||||
.addWidget("GamepadControllerOpacitySlider", "Slider")
|
||||
.addWidget("GamepadControllerOpacityLabel", "OptionsLabel")
|
||||
.closeLayout()
|
||||
.addWidget("GamepadControllerMinimalLayout", "Checkbox")
|
||||
.addWidget("KeyboardFunctionBar", "Checkbox");
|
||||
#if TARGET_OS_IOS
|
||||
layouts.addWidget("PreferredTouchModeText", "", -1, layouts.getVar("Globals.Line.Height"));
|
||||
|
||||
const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
|
||||
if (inAppDomain) {
|
||||
layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("TouchModeMenusText", "OptionsLabel")
|
||||
.addWidget("TouchModeMenus", "PopUp")
|
||||
.closeLayout();
|
||||
}
|
||||
layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("TouchMode2DGamesText", "OptionsLabel")
|
||||
.addWidget("TouchMode2DGames", "PopUp")
|
||||
.closeLayout();
|
||||
|
||||
layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("TouchMode3DGamesText", "OptionsLabel")
|
||||
.addWidget("TouchMode3DGames", "PopUp")
|
||||
.closeLayout();
|
||||
|
||||
layouts.addWidget("OrientationText", "", -1, layouts.getVar("Globals.Line.Height"));
|
||||
if (inAppDomain) {
|
||||
layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("OMenusText", "OptionsLabel")
|
||||
.addWidget("OMenus", "PopUp")
|
||||
.closeLayout();
|
||||
}
|
||||
layouts.addLayout(GUI::ThemeLayout::kLayoutHorizontal)
|
||||
.addPadding(0, 0, 0, 0)
|
||||
.addWidget("OGamesText", "OptionsLabel")
|
||||
.addWidget("OGames", "PopUp")
|
||||
.closeLayout();
|
||||
#endif
|
||||
layouts.closeLayout()
|
||||
.closeDialog();
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
switch (cmd) {
|
||||
case kGamepadControllerOpacityChanged: {
|
||||
const int newValue = _gamepadControllerOpacitySlider->getValue();
|
||||
_gamepadControllerOpacityLabel->setValue(newValue);
|
||||
_gamepadControllerOpacityLabel->markAsDirty();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
GUI::OptionsContainerWidget::handleCommand(sender, cmd, data);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 IOS7OptionsWidget::loadDirectionalInput(const Common::String &setting, bool acceptDefault, uint32 defaultValue) {
|
||||
if (!acceptDefault || ConfMan.hasKey(setting, _domain)) {
|
||||
Common::String input = ConfMan.get(setting, _domain);
|
||||
if (input == "thumbstick") {
|
||||
return kDirectionalInputThumbstick;
|
||||
} else if (input == "dpad") {
|
||||
return kScreenOrientationPortrait;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} else {
|
||||
return kDirectionalInputThumbstick;
|
||||
}
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::saveDirectionalInput(const Common::String &setting, uint32 input) {
|
||||
switch (input) {
|
||||
case kDirectionalInputThumbstick:
|
||||
ConfMan.set(setting, "thumbstick", _domain);
|
||||
break;
|
||||
case kDirectionalInputDpad:
|
||||
ConfMan.set(setting, "dpad", _domain);
|
||||
break;
|
||||
default:
|
||||
// default
|
||||
ConfMan.removeKey(setting, _domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
uint32 IOS7OptionsWidget::loadTouchMode(const Common::String &setting, bool acceptDefault, uint32 defaultValue) {
|
||||
if (!acceptDefault || ConfMan.hasKey(setting, _domain)) {
|
||||
Common::String mode = ConfMan.get(setting, _domain);
|
||||
if (mode == "direct") {
|
||||
return kTouchModeDirect;
|
||||
} else if (mode == "touchpad") {
|
||||
return kTouchModeTouchpad;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} else {
|
||||
return iOS7_isBigDevice() ? kTouchModeDirect : kTouchModeTouchpad;
|
||||
}
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::saveTouchMode(const Common::String &setting, uint32 mode) {
|
||||
switch (mode) {
|
||||
case kTouchModeDirect:
|
||||
ConfMan.set(setting, "direct", _domain);
|
||||
break;
|
||||
case kTouchModeTouchpad:
|
||||
ConfMan.set(setting, "touchpad", _domain);
|
||||
break;
|
||||
default:
|
||||
// default
|
||||
ConfMan.removeKey(setting, _domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 IOS7OptionsWidget::loadOrientation(const Common::String &setting, bool acceptDefault, uint32 defaultValue) {
|
||||
if (!acceptDefault || ConfMan.hasKey(setting, _domain)) {
|
||||
Common::String orientation = ConfMan.get(setting, _domain);
|
||||
if (orientation == "auto") {
|
||||
return kScreenOrientationAuto;
|
||||
} else if (orientation == "portrait") {
|
||||
return kScreenOrientationPortrait;
|
||||
} else if (orientation == "landscape") {
|
||||
return kScreenOrientationLandscape;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
} else {
|
||||
return kScreenOrientationAuto;
|
||||
}
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::saveOrientation(const Common::String &setting, uint32 orientation) {
|
||||
switch (orientation) {
|
||||
case kScreenOrientationAuto:
|
||||
ConfMan.set(setting, "auto", _domain);
|
||||
break;
|
||||
case kScreenOrientationPortrait:
|
||||
ConfMan.set(setting, "portrait", _domain);
|
||||
break;
|
||||
case kScreenOrientationLandscape:
|
||||
ConfMan.set(setting, "landscape", _domain);
|
||||
break;
|
||||
default:
|
||||
// default
|
||||
ConfMan.removeKey(setting, _domain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void IOS7OptionsWidget::load() {
|
||||
const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
|
||||
_gamepadControllerCheckbox->setState(ConfMan.getBool("gamepad_controller", _domain));
|
||||
_gamepadControllerOpacitySlider->setValue(ConfMan.getInt("gamepad_controller_opacity", _domain));
|
||||
_gamepadControllerOpacityLabel->setValue(_gamepadControllerOpacitySlider->getValue());
|
||||
_gamepadControllerDirectionalInputPopUp->setSelectedTag(loadDirectionalInput("gamepad_controller_directional_input", !inAppDomain, kDirectionalInputThumbstick));
|
||||
_gamepadControllerMinimalLayoutCheckbox->setState(ConfMan.getBool("gamepad_controller_minimal_layout", _domain));
|
||||
|
||||
_keyboardFnBarCheckbox->setState(ConfMan.getBool("keyboard_fn_bar", _domain));
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
if (inAppDomain) {
|
||||
_preferredTouchModeMenusPopUp->setSelectedTag(loadTouchMode("touch_mode_menus", !inAppDomain, kTouchModeDirect));
|
||||
}
|
||||
_preferredTouchMode2DGamesPopUp->setSelectedTag(loadTouchMode("touch_mode_2d_games", !inAppDomain, kTouchModeTouchpad));
|
||||
_preferredTouchMode3DGamesPopUp->setSelectedTag(loadTouchMode("touch_mode_3d_games", !inAppDomain, kTouchModeDirect));
|
||||
|
||||
if (inAppDomain) {
|
||||
_orientationMenusPopUp->setSelectedTag(loadOrientation("orientation_menus", !inAppDomain, kScreenOrientationAuto));
|
||||
}
|
||||
_orientationGamesPopUp->setSelectedTag(loadOrientation("orientation_games", !inAppDomain, kScreenOrientationAuto));
|
||||
|
||||
_onscreenCheckbox->setState(ConfMan.getBool("onscreen_control", _domain));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool IOS7OptionsWidget::save() {
|
||||
#if TARGET_OS_IOS
|
||||
const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
#endif
|
||||
|
||||
if (_enabled) {
|
||||
ConfMan.setBool("gamepad_controller", _gamepadControllerCheckbox->getState(), _domain);
|
||||
ConfMan.setInt("gamepad_controller_opacity", _gamepadControllerOpacitySlider->getValue(), _domain);
|
||||
ConfMan.setInt("gamepad_controller_directional_input", _gamepadControllerDirectionalInputPopUp->getSelectedTag(), _domain);
|
||||
ConfMan.setBool("gamepad_controller_minimal_layout", _gamepadControllerMinimalLayoutCheckbox->getState(), _domain);
|
||||
|
||||
ConfMan.setBool("keyboard_fn_bar", _keyboardFnBarCheckbox->getState(), _domain);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
if (inAppDomain) {
|
||||
saveTouchMode("touch_mode_menus", _preferredTouchModeMenusPopUp->getSelectedTag());
|
||||
}
|
||||
saveTouchMode("touch_mode_2d_games", _preferredTouchMode2DGamesPopUp->getSelectedTag());
|
||||
saveTouchMode("touch_mode_3d_games", _preferredTouchMode3DGamesPopUp->getSelectedTag());
|
||||
|
||||
if (inAppDomain) {
|
||||
saveOrientation("orientation_menus", _orientationMenusPopUp->getSelectedTag());
|
||||
}
|
||||
saveOrientation("orientation_games", _orientationGamesPopUp->getSelectedTag());
|
||||
|
||||
ConfMan.setBool("onscreen_control", _onscreenCheckbox->getState(), _domain);
|
||||
#endif
|
||||
} else {
|
||||
ConfMan.removeKey("gamepad_controller", _domain);
|
||||
ConfMan.removeKey("gamepad_controller_opacity", _domain);
|
||||
ConfMan.removeKey("gamepad_controller_directional_input", _domain);
|
||||
ConfMan.removeKey("gamepad_controller_minimal_layout", _domain);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
if (inAppDomain) {
|
||||
ConfMan.removeKey("touch_mode_menus", _domain);
|
||||
}
|
||||
ConfMan.removeKey("touch_mode_2d_games", _domain);
|
||||
ConfMan.removeKey("touch_mode_3d_games", _domain);
|
||||
|
||||
ConfMan.removeKey("keyboard_fn_bar", _domain);
|
||||
|
||||
if (inAppDomain) {
|
||||
ConfMan.removeKey("orientation_menus", _domain);
|
||||
}
|
||||
ConfMan.removeKey("orientation_games", _domain);
|
||||
|
||||
ConfMan.removeKey("onscreen_control", _domain);
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IOS7OptionsWidget::hasKeys() {
|
||||
bool hasKeys = ConfMan.hasKey("gamepad_controller", _domain) ||
|
||||
ConfMan.hasKey("gamepad_controller_opacity", _domain) ||
|
||||
ConfMan.hasKey("gamepad_controller_directional_input", _domain) ||
|
||||
ConfMan.hasKey("gamepad_controller_minimal_layout", _domain) ||
|
||||
ConfMan.hasKey("touch_mode_menus", _domain) ||
|
||||
ConfMan.hasKey("touch_mode_2d_games", _domain) ||
|
||||
ConfMan.hasKey("touch_mode_3d_games", _domain);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
hasKeys = hasKeys || (_domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain) && ConfMan.hasKey("orientation_menus", _domain)) ||
|
||||
ConfMan.hasKey("orientation_games", _domain) ||
|
||||
ConfMan.hasKey("onscreen_control", _domain);
|
||||
#endif
|
||||
|
||||
return hasKeys;
|
||||
}
|
||||
|
||||
void IOS7OptionsWidget::setEnabled(bool e) {
|
||||
_enabled = e;
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
_onscreenCheckbox->setEnabled(e);
|
||||
|
||||
#if __IPHONE_15_0
|
||||
// On-screen controls (virtual controller is supported in iOS 15 and later)
|
||||
if (@available(iOS 15.0, *)) {
|
||||
_gamepadControllerCheckbox->setEnabled(e);
|
||||
_gamepadControllerDirectionalInputPopUp->setEnabled(e);
|
||||
_gamepadControllerOpacityDesc->setEnabled(e);
|
||||
_gamepadControllerOpacitySlider->setEnabled(e);
|
||||
_gamepadControllerOpacityLabel->setEnabled(e);
|
||||
_gamepadControllerMinimalLayoutCheckbox->setEnabled(e);
|
||||
} else {
|
||||
_gamepadControllerCheckbox->setEnabled(false);
|
||||
_gamepadControllerDirectionalInputPopUp->setEnabled(false);
|
||||
_gamepadControllerOpacityDesc->setEnabled(false);
|
||||
_gamepadControllerOpacitySlider->setEnabled(false);
|
||||
_gamepadControllerOpacityLabel->setEnabled(false);
|
||||
_gamepadControllerMinimalLayoutCheckbox->setEnabled(false);
|
||||
}
|
||||
#endif /* __IPHONE_15_0 */
|
||||
#else /* TARGET_OS_IOS */
|
||||
_gamepadControllerCheckbox->setEnabled(false);
|
||||
_gamepadControllerDirectionalInputDesc->setEnabled(false);
|
||||
_gamepadControllerDirectionalInputPopUp->setEnabled(false);
|
||||
_gamepadControllerOpacityDesc->setEnabled(false);
|
||||
_gamepadControllerOpacitySlider->setEnabled(false);
|
||||
_gamepadControllerOpacityLabel->setEnabled(false);
|
||||
_gamepadControllerMinimalLayoutCheckbox->setEnabled(false);
|
||||
#endif /* TARGET_OS_IOS */
|
||||
|
||||
_keyboardFnBarCheckbox->setEnabled(e);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
const bool inAppDomain = _domain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
|
||||
if (inAppDomain) {
|
||||
_preferredTouchModeMenusDesc->setEnabled(e);
|
||||
_preferredTouchModeMenusPopUp->setEnabled(e);
|
||||
}
|
||||
_preferredTouchMode2DGamesDesc->setEnabled(e);
|
||||
_preferredTouchMode2DGamesPopUp->setEnabled(e);
|
||||
_preferredTouchMode3DGamesDesc->setEnabled(e);
|
||||
_preferredTouchMode3DGamesPopUp->setEnabled(e);
|
||||
|
||||
if (inAppDomain) {
|
||||
_orientationMenusDesc->setEnabled(e);
|
||||
_orientationMenusPopUp->setEnabled(e);
|
||||
}
|
||||
_orientationGamesDesc->setEnabled(e);
|
||||
_orientationGamesPopUp->setEnabled(e);
|
||||
#endif
|
||||
}
|
||||
|
||||
GUI::OptionsContainerWidget *OSystem_iOS7::buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const {
|
||||
return new IOS7OptionsWidget(boss, name, target);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::registerDefaultSettings(const Common::String &target) const {
|
||||
ConfMan.registerDefault("gamepad_controller", false);
|
||||
ConfMan.registerDefault("gamepad_controller_opacity", 6);
|
||||
ConfMan.registerDefault("gamepad_controller_directional_input", kDirectionalInputThumbstick);
|
||||
ConfMan.registerDefault("gamepad_controller_minimal_layout", false);
|
||||
|
||||
ConfMan.registerDefault("touch_mode_menus", "direct");
|
||||
ConfMan.registerDefault("touch_mode_2d_games", "touchpad");
|
||||
ConfMan.registerDefault("touch_mode_3d_games", "gamepad");
|
||||
|
||||
ConfMan.registerDefault("touch_mode_menus", "direct");
|
||||
ConfMan.registerDefault("touch_mode_2d_games", "touchpad");
|
||||
ConfMan.registerDefault("touch_mode_3d_games", "gamepad");
|
||||
|
||||
ConfMan.registerDefault("keyboard_fn_bar", isiOSAppOnMac() ? false : true);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
ConfMan.registerDefault("orientation_menus", "auto");
|
||||
ConfMan.registerDefault("orientation_games", "auto");
|
||||
|
||||
ConfMan.registerDefault("onscreen_control", isiOSAppOnMac() ? false : true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void OSystem_iOS7::applyBackendSettings() {
|
||||
virtualController(ConfMan.getBool("gamepad_controller"));
|
||||
// _currentTouchMode is applied by the graphic manager
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
applyOrientationSettings();
|
||||
updateTouchMode();
|
||||
if (isKeyboardShown()) {
|
||||
setShowKeyboard(false);
|
||||
setShowKeyboard(true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
void OSystem_iOS7::applyOrientationSettings() {
|
||||
const Common::String activeDomain = ConfMan.getActiveDomainName();
|
||||
const bool inAppDomain = activeDomain.empty() ||
|
||||
activeDomain.equalsIgnoreCase(Common::ConfigManager::kApplicationDomain);
|
||||
|
||||
Common::String setting;
|
||||
|
||||
if (inAppDomain) {
|
||||
setting = "orientation_menus";
|
||||
} else {
|
||||
setting = "orientation_games";
|
||||
}
|
||||
|
||||
Common::String orientation = ConfMan.get(setting);
|
||||
if (orientation == "portrait") {
|
||||
setSupportedScreenOrientation(kScreenOrientationPortrait);
|
||||
} else if (orientation == "landscape") {
|
||||
setSupportedScreenOrientation(kScreenOrientationLandscape);
|
||||
} else {
|
||||
setSupportedScreenOrientation(kScreenOrientationAuto);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void OSystem_iOS7::applyTouchSettings(bool _3dMode, bool overlayShown) {
|
||||
#if TARGET_OS_IOS
|
||||
Common::String setting;
|
||||
Common::String defaultMode;
|
||||
|
||||
if (overlayShown) {
|
||||
setting = "touch_mode_menus";
|
||||
defaultMode = "direct";
|
||||
} else if (_3dMode) {
|
||||
setting = "touch_mode_3d_games";
|
||||
defaultMode = "direct";
|
||||
} else {
|
||||
setting = "touch_mode_2d_games";
|
||||
defaultMode = "touchpad";
|
||||
}
|
||||
|
||||
Common::String preferredTouchMode = ConfMan.get(setting);
|
||||
if (preferredTouchMode == "direct") {
|
||||
_currentTouchMode = kTouchModeDirect;
|
||||
} else if (preferredTouchMode == "touchpad") {
|
||||
_currentTouchMode = kTouchModeTouchpad;
|
||||
} else {
|
||||
_currentTouchMode = kTouchModeTouchpad;
|
||||
}
|
||||
|
||||
updateTouchMode();
|
||||
#else
|
||||
(void)_3dMode;
|
||||
(void)overlayShown;
|
||||
#endif
|
||||
}
|
||||
422
backends/platform/ios7/ios7_osys_events.cpp
Normal file
422
backends/platform/ios7/ios7_osys_events.cpp
Normal file
@@ -0,0 +1,422 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "gui/message.h"
|
||||
#include "common/translation.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "backends/graphics/ios/ios-graphics.h"
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
|
||||
static const int kQueuedInputEventDelay = 50;
|
||||
|
||||
bool OSystem_iOS7::pollEvent(Common::Event &event) {
|
||||
//printf("pollEvent()\n");
|
||||
|
||||
long curTime = getMillis();
|
||||
|
||||
if (_queuedInputEvent.type != Common::EVENT_INVALID && curTime >= _queuedEventTime) {
|
||||
event = _queuedInputEvent;
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
return true;
|
||||
}
|
||||
|
||||
InternalEvent internalEvent;
|
||||
|
||||
if (iOS7_fetchEvent(&internalEvent)) {
|
||||
switch (internalEvent.type) {
|
||||
case kInputTouchBegan:
|
||||
if (!handleEvent_touchBegan(event, internalEvent.value1, internalEvent.value2))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputTouchMoved:
|
||||
if (!handleEvent_touchMoved(event, internalEvent.value1, internalEvent.value2))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputMouseLeftButtonDown:
|
||||
handleEvent_mouseLeftButtonDown(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputMouseLeftButtonUp:
|
||||
handleEvent_mouseLeftButtonUp(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputMouseRightButtonDown:
|
||||
handleEvent_mouseRightButtonDown(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputMouseRightButtonUp:
|
||||
handleEvent_mouseRightButtonUp(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputMouseDelta:
|
||||
handleEvent_mouseDelta(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputOrientationChanged:
|
||||
handleEvent_orientationChanged(internalEvent.value1);
|
||||
return false;
|
||||
|
||||
case kInputApplicationSuspended:
|
||||
handleEvent_applicationSuspended();
|
||||
return false;
|
||||
|
||||
case kInputApplicationResumed:
|
||||
handleEvent_applicationResumed();
|
||||
return false;
|
||||
|
||||
case kInputApplicationSaveState:
|
||||
handleEvent_applicationSaveState();
|
||||
return false;
|
||||
|
||||
case kInputApplicationRestoreState:
|
||||
handleEvent_applicationRestoreState();
|
||||
return false;
|
||||
|
||||
case kInputApplicationClearState:
|
||||
handleEvent_applicationClearState();
|
||||
return false;
|
||||
|
||||
case kInputKeyPressed:
|
||||
handleEvent_keyPressed(event, internalEvent.value1, internalEvent.value2);
|
||||
break;
|
||||
|
||||
case kInputSwipe:
|
||||
if (!handleEvent_swipe(event, internalEvent.value1, internalEvent.value2))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputTap:
|
||||
if (!handleEvent_tap(event, (UIViewTapDescription) internalEvent.value1, internalEvent.value2))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputLongPress:
|
||||
if (!handleEvent_longPress(event, (UIViewLongPressDescription) internalEvent.value1, internalEvent.value2))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputMainMenu:
|
||||
event.type = Common::EVENT_MAINMENU;
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
break;
|
||||
|
||||
case kInputJoystickAxisMotion:
|
||||
event.type = Common::EVENT_JOYAXIS_MOTION;
|
||||
event.joystick.axis = internalEvent.value1;
|
||||
event.joystick.position = internalEvent.value2;
|
||||
break;
|
||||
|
||||
case kInputJoystickButtonDown:
|
||||
event.type = Common::EVENT_JOYBUTTON_DOWN;
|
||||
event.joystick.button = internalEvent.value1;
|
||||
break;
|
||||
|
||||
case kInputJoystickButtonUp:
|
||||
event.type = Common::EVENT_JOYBUTTON_UP;
|
||||
event.joystick.button = internalEvent.value1;
|
||||
break;
|
||||
|
||||
case kInputScreenChanged:
|
||||
rebuildSurface();
|
||||
dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->notifyResize(getScreenWidth(), getScreenHeight());
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
break;
|
||||
|
||||
case kInputTouchModeChanged:
|
||||
handleEvent_touchModeChanged();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::handleEvent_touchBegan(Common::Event &event, int x, int y) {
|
||||
_lastPadX = x;
|
||||
_lastPadY = y;
|
||||
|
||||
if (_currentTouchMode == kTouchModeDirect) {
|
||||
Common::Point mouse(x, y);
|
||||
dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->notifyMousePosition(mouse);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::handleEvent_touchMoved(Common::Event &event, int x, int y) {
|
||||
int deltaX = _lastPadX - x;
|
||||
int deltaY = _lastPadY - y;
|
||||
_lastPadX = x;
|
||||
_lastPadY = y;
|
||||
|
||||
if (_currentTouchMode == kTouchModeTouchpad) {
|
||||
handleEvent_mouseDelta(event, deltaX, deltaY);
|
||||
} else {
|
||||
// Update mouse position
|
||||
Common::Point mousePos(x, y);
|
||||
dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->notifyMousePosition(mousePos);
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
handleEvent_mouseEvent(event, deltaX, deltaY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseLeftButtonDown(Common::Event &event, int x, int y) {
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseLeftButtonUp(Common::Event &event, int x, int y) {
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseRightButtonDown(Common::Event &event, int x, int y) {
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseRightButtonUp(Common::Event &event, int x, int y) {
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseDelta(Common::Event &event, int deltaX, int deltaY) {
|
||||
Common::Point mouseOldPos = dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->getMousePosition();
|
||||
|
||||
Common::Point newMousePos((int)(mouseOldPos.x - (int)((float)deltaX * getMouseSpeed())), (int)(mouseOldPos.y - (int)((float)deltaY * getMouseSpeed())));
|
||||
|
||||
// Update mouse position
|
||||
dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->notifyMousePosition(newMousePos);
|
||||
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
handleEvent_mouseEvent(event, deltaX, deltaY);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_mouseEvent(Common::Event &event, int relX, int relY) {
|
||||
Common::Point mouse = dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->getMousePosition();
|
||||
dynamic_cast<iOSGraphicsManager *>(_graphicsManager)->notifyMousePosition(mouse);
|
||||
|
||||
event.relMouse.x = relX;
|
||||
event.relMouse.y = relY;
|
||||
event.mouse = mouse;
|
||||
}
|
||||
|
||||
|
||||
void OSystem_iOS7::handleEvent_orientationChanged(int orientation) {
|
||||
//printf("Orientation: %i\n", orientation);
|
||||
|
||||
ScreenOrientation newOrientation = (ScreenOrientation)orientation;
|
||||
|
||||
if (_screenOrientation != newOrientation) {
|
||||
_screenOrientation = newOrientation;
|
||||
rebuildSurface();
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_touchModeChanged() {
|
||||
switch (_currentTouchMode) {
|
||||
case kTouchModeDirect:
|
||||
_currentTouchMode = kTouchModeTouchpad;
|
||||
break;
|
||||
case kTouchModeTouchpad:
|
||||
default:
|
||||
_currentTouchMode = kTouchModeDirect;
|
||||
break;
|
||||
}
|
||||
|
||||
updateTouchMode();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::rebuildSurface() {
|
||||
updateOutputSurface();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationSuspended() {
|
||||
suspendLoop();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationResumed() {
|
||||
rebuildSurface();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_keyPressed(Common::Event &event, int keyPressed, int modifierFlags) {
|
||||
int ascii = keyPressed;
|
||||
//printf("key: %i\n", keyPressed);
|
||||
|
||||
// Map LF character to Return key/CR character
|
||||
if (keyPressed == 10) {
|
||||
keyPressed = Common::KEYCODE_RETURN;
|
||||
ascii = Common::ASCII_RETURN;
|
||||
}
|
||||
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
_queuedInputEvent.type = Common::EVENT_KEYUP;
|
||||
|
||||
event.kbd.flags = _queuedInputEvent.kbd.flags = modifierFlags;
|
||||
event.kbd.keycode = _queuedInputEvent.kbd.keycode = (Common::KeyCode)keyPressed;
|
||||
event.kbd.ascii = _queuedInputEvent.kbd.ascii = ascii;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::handleEvent_swipe(Common::Event &event, int direction, int touches) {
|
||||
if (touches == 3) {
|
||||
Common::KeyCode keycode = Common::KEYCODE_INVALID;
|
||||
switch ((UIViewSwipeDirection)direction) {
|
||||
case kUIViewSwipeUp:
|
||||
keycode = Common::KEYCODE_UP;
|
||||
break;
|
||||
case kUIViewSwipeDown:
|
||||
keycode = Common::KEYCODE_DOWN;
|
||||
break;
|
||||
case kUIViewSwipeLeft:
|
||||
keycode = Common::KEYCODE_LEFT;
|
||||
break;
|
||||
case kUIViewSwipeRight:
|
||||
keycode = Common::KEYCODE_RIGHT;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
event.kbd.keycode = _queuedInputEvent.kbd.keycode = keycode;
|
||||
event.kbd.ascii = _queuedInputEvent.kbd.ascii = 0;
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
_queuedInputEvent.type = Common::EVENT_KEYUP;
|
||||
event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (touches == 2) {
|
||||
switch ((UIViewSwipeDirection)direction) {
|
||||
case kUIViewSwipeUp: {
|
||||
return false;
|
||||
}
|
||||
|
||||
case kUIViewSwipeDown: {
|
||||
// Swipe down
|
||||
event.type = Common::EVENT_MAINMENU;
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
return true;
|
||||
}
|
||||
|
||||
case kUIViewSwipeRight: {
|
||||
// Swipe right
|
||||
if (_currentTouchMode == kTouchModeDirect) {
|
||||
_currentTouchMode = kTouchModeTouchpad;
|
||||
} else {
|
||||
_currentTouchMode = kTouchModeDirect;
|
||||
}
|
||||
updateTouchMode();
|
||||
|
||||
Common::U32String dialogMsg;
|
||||
if (_currentTouchMode == kTouchModeTouchpad)
|
||||
dialogMsg = _("Touchpad emulation");
|
||||
else
|
||||
dialogMsg = _("Direct mouse");
|
||||
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
}
|
||||
|
||||
case kUIViewSwipeLeft: {
|
||||
// Swipe left
|
||||
bool connect = !ConfMan.getBool("gamepad_controller");
|
||||
ConfMan.setBool("gamepad_controller", connect);
|
||||
ConfMan.flushToDisk();
|
||||
virtualController(connect);
|
||||
return false;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::handleEvent_tap(Common::Event &event, UIViewTapDescription type, int touches) {
|
||||
if (touches == 1) {
|
||||
if (type == kUIViewTapSingle) {
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
|
||||
_queuedInputEvent.type = Common::EVENT_LBUTTONUP;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
handleEvent_mouseEvent(_queuedInputEvent, 0, 0);
|
||||
return true;
|
||||
}
|
||||
} else if (touches == 2) {
|
||||
if (type == kUIViewTapSingle) {
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
|
||||
_queuedInputEvent.type = Common::EVENT_RBUTTONUP;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
handleEvent_mouseEvent(_queuedInputEvent, 0, 0);
|
||||
return true;
|
||||
} else if (type == kUIViewTapDouble) {
|
||||
event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_ESCAPE;
|
||||
event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_ESCAPE;
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
_queuedInputEvent.type = Common::EVENT_KEYUP;
|
||||
event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
|
||||
_queuedEventTime = getMillis() + kQueuedInputEventDelay;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::handleEvent_longPress(Common::Event &event, UIViewLongPressDescription type, int touches) {
|
||||
if (touches == 1) {
|
||||
if (type == UIViewLongPressStarted) {
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
return true;
|
||||
} else if (touches == 2) {
|
||||
if (type == UIViewLongPressStarted) {
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
} else {
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
handleEvent_mouseEvent(event, 0, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
478
backends/platform/ios7/ios7_osys_main.cpp
Normal file
478
backends/platform/ios7/ios7_osys_main.cpp
Normal file
@@ -0,0 +1,478 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "common/scummsys.h"
|
||||
#include "common/util.h"
|
||||
#include "common/rect.h"
|
||||
#include "common/file.h"
|
||||
#include "common/fs.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/translation.h"
|
||||
#include "common/formats/ini-file.h"
|
||||
|
||||
#include "base/main.h"
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "engines/metaengine.h"
|
||||
|
||||
#include "graphics/cursorman.h"
|
||||
#include "gui/gui-manager.h"
|
||||
|
||||
#include "backends/graphics/ios/ios-graphics.h"
|
||||
#include "backends/saves/default/default-saves.h"
|
||||
#include "backends/timer/default/default-timer.h"
|
||||
#include "backends/mutex/pthread/pthread-mutex.h"
|
||||
#include "backends/fs/chroot/chroot-fs-factory.h"
|
||||
#include "backends/fs/posix/posix-fs.h"
|
||||
#include "audio/mixer.h"
|
||||
#include "audio/mixer_intern.h"
|
||||
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
|
||||
|
||||
AQCallbackStruct OSystem_iOS7::s_AudioQueue;
|
||||
SoundProc OSystem_iOS7::s_soundCallback = NULL;
|
||||
void *OSystem_iOS7::s_soundParam = NULL;
|
||||
|
||||
class SandboxedSaveFileManager : public DefaultSaveFileManager {
|
||||
Common::Path _sandboxRootPath;
|
||||
public:
|
||||
|
||||
SandboxedSaveFileManager(const Common::Path &sandboxRootPath, const Common::Path &defaultSavepath)
|
||||
: DefaultSaveFileManager(defaultSavepath), _sandboxRootPath(sandboxRootPath) {
|
||||
}
|
||||
|
||||
Common::ErrorCode removeFile(const Common::FSNode &fileNode) override {
|
||||
Common::Path chrootedFile(fileNode.getPath());
|
||||
Common::Path realFilePath(_sandboxRootPath.join(chrootedFile));
|
||||
|
||||
if (remove(realFilePath.toString(Common::Path::kNativeSeparator).c_str()) == 0)
|
||||
return Common::kNoError;
|
||||
if (errno == EACCES)
|
||||
return Common::kWritePermissionDenied;
|
||||
if (errno == ENOENT)
|
||||
return Common::kPathDoesNotExist;
|
||||
return Common::kUnknownError;
|
||||
}
|
||||
};
|
||||
|
||||
OSystem_iOS7::OSystem_iOS7() :
|
||||
_mixer(NULL), _queuedEventTime(0),
|
||||
_screenOrientation(kScreenOrientationAuto),
|
||||
_runningTasks(0) {
|
||||
_queuedInputEvent.type = Common::EVENT_INVALID;
|
||||
_currentTouchMode = kTouchModeTouchpad;
|
||||
|
||||
_chrootBasePath = iOS7_getDocumentsDir();
|
||||
ChRootFilesystemFactory *chFsFactory = new ChRootFilesystemFactory(_chrootBasePath);
|
||||
_fsFactory = chFsFactory;
|
||||
// Add virtual drive for bundle path
|
||||
Common::String appBubdlePath = iOS7_getAppBundleDir();
|
||||
if (!appBubdlePath.empty())
|
||||
chFsFactory->addVirtualDrive("appbundle:", appBubdlePath);
|
||||
}
|
||||
|
||||
OSystem_iOS7::~OSystem_iOS7() {
|
||||
AudioQueueDispose(s_AudioQueue.queue, true);
|
||||
|
||||
delete _mixer;
|
||||
delete _graphicsManager;
|
||||
}
|
||||
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
Common::Array<uint> OSystem_iOS7::getSupportedAntiAliasingLevels() const {
|
||||
Common::Array<uint> levels;
|
||||
|
||||
if (!OpenGLContext.framebufferObjectMultisampleSupported) {
|
||||
return levels;
|
||||
}
|
||||
|
||||
GLint numLevels;
|
||||
GLint *glLevels;
|
||||
|
||||
// We take the format used by Renderer3D
|
||||
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_NUM_SAMPLE_COUNTS, 1, &numLevels);
|
||||
if (numLevels == 0) {
|
||||
return levels;
|
||||
}
|
||||
|
||||
glLevels = new GLint[numLevels];
|
||||
glGetInternalformativ(GL_RENDERBUFFER, GL_RGBA8, GL_SAMPLES, numLevels, glLevels);
|
||||
|
||||
// SDL returns values in ascending order while glGetInternalformativ returns them in descending order.
|
||||
// Revert our result to match SDL
|
||||
for(numLevels--; numLevels >= 0; numLevels--) {
|
||||
levels.push_back(glLevels[numLevels]);
|
||||
}
|
||||
|
||||
delete glLevels;
|
||||
return levels;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_OPENGL) && defined(USE_GLAD)
|
||||
void *OSystem_iOS7::getOpenGLProcAddress(const char *name) const {
|
||||
return dlsym(RTLD_DEFAULT, name);
|
||||
}
|
||||
#endif
|
||||
|
||||
int OSystem_iOS7::timerHandler(int t) {
|
||||
DefaultTimerManager *tm = (DefaultTimerManager *)g_system->getTimerManager();
|
||||
tm->handler();
|
||||
return t;
|
||||
}
|
||||
|
||||
void OSystem_iOS7::initBackend() {
|
||||
_savefileManager = new SandboxedSaveFileManager(Common::Path(_chrootBasePath, Common::Path::kNativeSeparator), "/Savegames");
|
||||
|
||||
_timerManager = new DefaultTimerManager();
|
||||
|
||||
_startTime = CACurrentMediaTime();
|
||||
|
||||
_graphicsManager = new iOSGraphicsManager();
|
||||
|
||||
setupMixer();
|
||||
|
||||
setTimerCallback(&OSystem_iOS7::timerHandler, 10);
|
||||
|
||||
ConfMan.registerDefault("iconspath", Common::Path("/"));
|
||||
|
||||
EventsBaseBackend::initBackend();
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::hasFeature(Feature f) {
|
||||
switch (f) {
|
||||
case kFeatureCursorPalette:
|
||||
case kFeatureCursorAlpha:
|
||||
case kFeatureFilteringMode:
|
||||
case kFeatureVirtualKeyboard:
|
||||
#if TARGET_OS_IOS
|
||||
case kFeatureClipboardSupport:
|
||||
#endif
|
||||
case kFeatureOpenUrl:
|
||||
case kFeatureNoQuit:
|
||||
case kFeatureKbdMouseSpeed:
|
||||
case kFeatureTouchscreen:
|
||||
#ifdef SCUMMVM_NEON
|
||||
case kFeatureCpuNEON:
|
||||
#endif
|
||||
return true;
|
||||
|
||||
default:
|
||||
return ModularGraphicsBackend::hasFeature(f);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::setFeatureState(Feature f, bool enable) {
|
||||
switch (f) {
|
||||
case kFeatureVirtualKeyboard:
|
||||
setShowKeyboard(enable);
|
||||
break;
|
||||
|
||||
default:
|
||||
ModularGraphicsBackend::setFeatureState(f, enable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::getFeatureState(Feature f) {
|
||||
switch (f) {
|
||||
case kFeatureVirtualKeyboard:
|
||||
return isKeyboardShown();
|
||||
|
||||
default:
|
||||
return ModularGraphicsBackend::getFeatureState(f);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::suspendLoop() {
|
||||
bool done = false;
|
||||
|
||||
PauseToken pt;
|
||||
if (g_engine)
|
||||
pt = g_engine->pauseEngine();
|
||||
|
||||
// We also need to stop the audio queue and restart it later in case there
|
||||
// is an audio interruption that render it invalid.
|
||||
stopSoundsystem();
|
||||
|
||||
InternalEvent event;
|
||||
while (!done) {
|
||||
if (iOS7_fetchEvent(&event)) {
|
||||
if (event.type == kInputApplicationResumed)
|
||||
done = true;
|
||||
else if (event.type == kInputApplicationSaveState)
|
||||
handleEvent_applicationSaveState();
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
startSoundsystem();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::saveState() {
|
||||
// Clear any previous restore state to avoid having and obsolete one if we don't save it again below.
|
||||
clearState();
|
||||
|
||||
// If there is an engine running and it both accepts autosave and loading from the launcher (required to restore the state),
|
||||
// do an autosave and save the current running target and autosave slot to a state file.
|
||||
if (g_engine && g_engine->hasFeature(Engine::kSupportsSavingDuringRuntime) && g_engine->canSaveAutosaveCurrently() &&
|
||||
g_engine->getMetaEngine()->hasFeature(MetaEngine::kSupportsLoadingDuringStartup)) {
|
||||
Common::String targetName(ConfMan.getActiveDomainName());
|
||||
int saveSlot = g_engine->getAutosaveSlot();
|
||||
if (saveSlot == -1)
|
||||
return;
|
||||
// Make sure we do not overwrite a user save
|
||||
SaveStateDescriptor desc = g_engine->getMetaEngine()->querySaveMetaInfos(targetName.c_str(), saveSlot);
|
||||
if (desc.getSaveSlot() != -1 && !desc.isAutosave())
|
||||
return;
|
||||
|
||||
// Do the auto-save, and if successful create the state file with the target and save slot.
|
||||
if (g_engine->saveGameState(saveSlot, _("Autosave"), true).getCode() == Common::kNoError) {
|
||||
Common::INIFile stateFile;
|
||||
stateFile.addSection("state");
|
||||
stateFile.setKey("restore_target", "state", targetName);
|
||||
stateFile.setKey("restore_slot", "state", Common::String::format("%d", saveSlot));
|
||||
stateFile.saveToFile("/scummvm.state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::restoreState() {
|
||||
// If the g_engine is still running (i.e. the application was not terminated) we don't need to do anything other than clear the saved state.
|
||||
if (g_engine) {
|
||||
clearState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Read the state
|
||||
Common::FSNode node("/scummvm.state");
|
||||
Common::File stateFile;
|
||||
if (!stateFile.open(node))
|
||||
return;
|
||||
|
||||
Common::String targetName, slotString;
|
||||
int saveSlot = -1;
|
||||
Common::INIFile stateIniFile;
|
||||
if (stateIniFile.loadFromStream(stateFile) &&
|
||||
stateIniFile.getKey("restore_target", "state", targetName) &&
|
||||
stateIniFile.getKey("restore_slot", "state", slotString) &&
|
||||
!slotString.empty()) {
|
||||
char *errpos;
|
||||
saveSlot = (int)strtol(slotString.c_str(), &errpos, 10);
|
||||
if (slotString.c_str() == errpos)
|
||||
saveSlot = -1;
|
||||
}
|
||||
|
||||
clearState();
|
||||
|
||||
// Reload the state
|
||||
if (!targetName.empty() && saveSlot != -1) {
|
||||
ConfMan.setInt("save_slot", saveSlot, Common::ConfigManager::kTransientDomain);
|
||||
ConfMan.setActiveDomain(targetName);
|
||||
if (GUI::GuiManager::hasInstance())
|
||||
g_gui.exitLoop();
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::clearState() {
|
||||
Common::String statePath = _chrootBasePath + "/scummvm.state";
|
||||
remove(statePath.c_str());
|
||||
}
|
||||
|
||||
uint32 OSystem_iOS7::getMillis(bool skipRecord) {
|
||||
CFTimeInterval timeInSeconds = CACurrentMediaTime();
|
||||
return (uint32) ((timeInSeconds - _startTime) * 1000.0);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::delayMillis(uint msecs) {
|
||||
//printf("delayMillis(%d)\n", msecs);
|
||||
usleep(msecs * 1000);
|
||||
}
|
||||
|
||||
float OSystem_iOS7::getMouseSpeed() {
|
||||
switch (ConfMan.getInt("kbdmouse_speed")) {
|
||||
case 0:
|
||||
return 0.25;
|
||||
case 1:
|
||||
return 0.5;
|
||||
case 2:
|
||||
return 0.75;
|
||||
case 3:
|
||||
return 1.0;
|
||||
case 4:
|
||||
return 1.25;
|
||||
case 5:
|
||||
return 1.5;
|
||||
case 6:
|
||||
return 1.75;
|
||||
case 7:
|
||||
return 2.0;
|
||||
default:
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::setTimerCallback(TimerProc callback, int interval) {
|
||||
//printf("setTimerCallback()\n");
|
||||
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
||||
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
|
||||
|
||||
if (timer)
|
||||
{
|
||||
dispatch_source_set_timer(timer, dispatch_walltime(NULL, 0), interval * NSEC_PER_MSEC, interval * NSEC_PER_MSEC / 10);
|
||||
dispatch_source_set_event_handler(timer, ^{ callback(interval); });
|
||||
dispatch_resume(timer);
|
||||
}
|
||||
}
|
||||
|
||||
Common::MutexInternal *OSystem_iOS7::createMutex() {
|
||||
return createPthreadMutexInternal();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::quit() {
|
||||
}
|
||||
|
||||
void OSystem_iOS7::getTimeAndDate(TimeDate &td, bool skipRecord) const {
|
||||
time_t curTime = time(0);
|
||||
struct tm t = *localtime(&curTime);
|
||||
td.tm_sec = t.tm_sec;
|
||||
td.tm_min = t.tm_min;
|
||||
td.tm_hour = t.tm_hour;
|
||||
td.tm_mday = t.tm_mday;
|
||||
td.tm_mon = t.tm_mon;
|
||||
td.tm_year = t.tm_year;
|
||||
td.tm_wday = t.tm_wday;
|
||||
}
|
||||
|
||||
Audio::Mixer *OSystem_iOS7::getMixer() {
|
||||
assert(_mixer);
|
||||
return _mixer;
|
||||
}
|
||||
|
||||
OSystem_iOS7 *OSystem_iOS7::sharedInstance() {
|
||||
static OSystem_iOS7 *instance = new OSystem_iOS7();
|
||||
return instance;
|
||||
}
|
||||
|
||||
Common::Path OSystem_iOS7::getDefaultConfigFileName() {
|
||||
return Common::Path("/Preferences");
|
||||
}
|
||||
|
||||
void OSystem_iOS7::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
|
||||
// Get URL of the Resource directory of the .app bundle
|
||||
CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
|
||||
if (fileUrl) {
|
||||
// Try to convert the URL to an absolute path
|
||||
UInt8 buf[MAXPATHLEN];
|
||||
if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
|
||||
// Success: Add it to the search path
|
||||
Common::String bundlePath((const char *)buf);
|
||||
POSIXFilesystemNode *posixNode = new POSIXFilesystemNode(bundlePath);
|
||||
s.add("__IOS_BUNDLE__", new Common::FSDirectory(AbstractFSNode::makeFSNode(posixNode)), priority);
|
||||
}
|
||||
CFRelease(fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void iOS7_buildSharedOSystemInstance() {
|
||||
OSystem_iOS7::sharedInstance();
|
||||
}
|
||||
|
||||
void iOS7_setSafeAreaInsets(int l, int r, int t, int b) {
|
||||
ModularGraphicsBackend *sys = dynamic_cast<ModularGraphicsBackend *>(g_system);
|
||||
if (!sys) {
|
||||
return;
|
||||
}
|
||||
iOSGraphicsManager *gfx = dynamic_cast<iOSGraphicsManager *>(sys->getGraphicsManager());
|
||||
if (!gfx) {
|
||||
return;
|
||||
}
|
||||
gfx->setSafeAreaInsets(l, r, t, b);
|
||||
}
|
||||
|
||||
TouchMode iOS7_getCurrentTouchMode() {
|
||||
OSystem_iOS7 *sys = dynamic_cast<OSystem_iOS7 *>(g_system);
|
||||
if (!sys) {
|
||||
// If the system has not finished loading, just return a
|
||||
// default value.
|
||||
return kTouchModeDirect;
|
||||
}
|
||||
return sys->getCurrentTouchMode();
|
||||
}
|
||||
|
||||
void iOS7_main(int argc, char **argv) {
|
||||
|
||||
//OSystem_iOS7::migrateApp();
|
||||
|
||||
Common::String logFilePath = iOS7_getDocumentsDir() + "/scummvm.log";
|
||||
// Only log to file when not attached to debugger console
|
||||
FILE *logFile = isatty(STDERR_FILENO) != 1 ? fopen(logFilePath.c_str(), "a") : nullptr;
|
||||
if (logFile != nullptr) {
|
||||
// We check for log file size; if it's too big, we rewrite it.
|
||||
// This happens only upon app launch
|
||||
// NOTE: We don't check for file size each time we write a log message.
|
||||
long sz = ftell(logFile);
|
||||
if (sz > MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES) {
|
||||
fclose(logFile);
|
||||
fprintf(stdout, "Default log file is bigger than %dKB. It will be overwritten!", MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES / 1024);
|
||||
|
||||
// Create the log file from scratch overwriting the previous one
|
||||
logFile = fopen(logFilePath.c_str(), "w");
|
||||
if (logFile == nullptr)
|
||||
fprintf(stdout, "Could not open default log file for rewrite!");
|
||||
}
|
||||
if (logFile != NULL) {
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
*stdout = *logFile;
|
||||
*stderr = *logFile;
|
||||
setbuf(stdout, NULL);
|
||||
setbuf(stderr, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
chdir(iOS7_getDocumentsDir().c_str());
|
||||
|
||||
g_system = OSystem_iOS7::sharedInstance();
|
||||
assert(g_system);
|
||||
|
||||
// Invoke the actual ScummVM main entry point:
|
||||
scummvm_main(argc, (const char *const *) argv);
|
||||
g_system->quit(); // TODO: Consider removing / replacing this!
|
||||
|
||||
if (logFile != NULL) {
|
||||
//*stdout = NULL;
|
||||
//*stderr = NULL;
|
||||
fclose(logFile);
|
||||
}
|
||||
}
|
||||
206
backends/platform/ios7/ios7_osys_main.h
Normal file
206
backends/platform/ios7/ios7_osys_main.h
Normal file
@@ -0,0 +1,206 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_OSYS_MAIN_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_OSYS_MAIN_H
|
||||
|
||||
#include "graphics/surface.h"
|
||||
#include "backends/platform/ios7/ios7_common.h"
|
||||
#include "backends/modular-backend.h"
|
||||
#include "backends/keymapper/hardware-input.h"
|
||||
#include "common/events.h"
|
||||
#include "common/str.h"
|
||||
#include "common/ustr.h"
|
||||
#include "audio/mixer_intern.h"
|
||||
#include "backends/fs/posix/posix-fs-factory.h"
|
||||
#include "graphics/palette.h"
|
||||
|
||||
#include <AudioToolbox/AudioQueue.h>
|
||||
|
||||
#define AUDIO_BUFFERS 3
|
||||
#define WAVE_BUFFER_SIZE 2048
|
||||
#define AUDIO_SAMPLE_RATE 44100
|
||||
#define MAX_IOS7_SCUMMVM_LOG_FILESIZE_IN_BYTES (100*1024)
|
||||
|
||||
typedef void (*SoundProc)(void *param, byte *buf, int len);
|
||||
typedef int (*TimerProc)(int interval);
|
||||
|
||||
struct AQCallbackStruct {
|
||||
AudioQueueRef queue;
|
||||
uint32 frameCount;
|
||||
AudioQueueBufferRef buffers[AUDIO_BUFFERS];
|
||||
AudioStreamBasicDescription dataFormat;
|
||||
};
|
||||
|
||||
class OSystem_iOS7 : public ModularGraphicsBackend, public EventsBaseBackend {
|
||||
protected:
|
||||
static AQCallbackStruct s_AudioQueue;
|
||||
static SoundProc s_soundCallback;
|
||||
static void *s_soundParam;
|
||||
|
||||
Audio::MixerImpl *_mixer;
|
||||
|
||||
CFTimeInterval _startTime;
|
||||
|
||||
int _runningTasks;
|
||||
|
||||
long _lastMouseDown;
|
||||
long _queuedEventTime;
|
||||
Common::Event _queuedInputEvent;
|
||||
TouchMode _currentTouchMode;
|
||||
int _lastPadX;
|
||||
int _lastPadY;
|
||||
|
||||
ScreenOrientation _screenOrientation;
|
||||
|
||||
Common::String _lastErrorMessage;
|
||||
|
||||
Common::String _chrootBasePath;
|
||||
|
||||
public:
|
||||
|
||||
OSystem_iOS7();
|
||||
virtual ~OSystem_iOS7();
|
||||
|
||||
static OSystem_iOS7 *sharedInstance();
|
||||
|
||||
void initBackend() override;
|
||||
|
||||
void engineInit() override;
|
||||
void engineDone() override;
|
||||
|
||||
void taskStarted(Task) override;
|
||||
void taskFinished(Task) override;
|
||||
|
||||
void updateStartSettings(const Common::String &executable, Common::String &command, Common::StringMap &settings, Common::StringArray& additionalArgs) override;
|
||||
|
||||
bool hasFeature(Feature f) override;
|
||||
void setFeatureState(Feature f, bool enable) override;
|
||||
bool getFeatureState(Feature f) override;
|
||||
|
||||
TouchMode getCurrentTouchMode() const { return _currentTouchMode; };
|
||||
void setCurrentTouchMode(TouchMode mode) { _currentTouchMode = mode; };
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
void applyOrientationSettings();
|
||||
void setSupportedScreenOrientation(ScreenOrientation screenOrientation);
|
||||
#endif
|
||||
void applyTouchSettings(bool _3dMode, bool overlayShown);
|
||||
|
||||
uint createOpenGLContext();
|
||||
void destroyOpenGLContext();
|
||||
void refreshScreen() const;
|
||||
int getScreenWidth() const;
|
||||
int getScreenHeight() const;
|
||||
float getSystemHiDPIScreenFactor() const;
|
||||
|
||||
#if defined(USE_OPENGL) && defined(USE_GLAD)
|
||||
void *getOpenGLProcAddress(const char *name) const override;
|
||||
#endif
|
||||
#if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
|
||||
OpenGL::ContextType getOpenGLType() const override { return OpenGL::kContextGLES2; }
|
||||
Common::Array<uint> getSupportedAntiAliasingLevels() const override;
|
||||
#endif
|
||||
|
||||
public:
|
||||
bool pollEvent(Common::Event &event) override;
|
||||
uint32 getMillis(bool skipRecord = false) override;
|
||||
void delayMillis(uint msecs) override;
|
||||
Common::MutexInternal *createMutex() override;
|
||||
|
||||
static void mixCallback(void *sys, byte *samples, int len);
|
||||
virtual void setupMixer(void);
|
||||
virtual void setTimerCallback(TimerProc callback, int interval);
|
||||
void quit() override;
|
||||
|
||||
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
|
||||
void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
|
||||
|
||||
Common::HardwareInputSet *getHardwareInputSet() override;
|
||||
|
||||
Audio::Mixer *getMixer() override;
|
||||
|
||||
void startSoundsystem();
|
||||
void stopSoundsystem();
|
||||
|
||||
Common::Path getDefaultConfigFileName() override;
|
||||
|
||||
void logMessage(LogMessageType::Type type, const char *message) override;
|
||||
void fatalError() override;
|
||||
|
||||
bool hasTextInClipboard() override;
|
||||
Common::U32String getTextFromClipboard() override;
|
||||
bool setTextInClipboard(const Common::U32String &text) override;
|
||||
|
||||
bool openUrl(const Common::String &url) override;
|
||||
const char * const *buildHelpDialogData() override;
|
||||
Common::String getSystemLanguage() const override;
|
||||
|
||||
bool isConnectionLimited() override;
|
||||
void virtualController(bool connect);
|
||||
bool isiOSAppOnMac() const;
|
||||
|
||||
virtual Common::Path getDefaultLogFileName() override { return Common::Path("/scummvm.log"); }
|
||||
|
||||
virtual GUI::OptionsContainerWidget* buildBackendOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const override;
|
||||
virtual void applyBackendSettings() override;
|
||||
virtual void registerDefaultSettings(const Common::String &target) const override;
|
||||
|
||||
protected:
|
||||
void updateOutputSurface();
|
||||
void updateTouchMode();
|
||||
void setShowKeyboard(bool);
|
||||
bool isKeyboardShown() const;
|
||||
|
||||
void suspendLoop();
|
||||
void saveState();
|
||||
void restoreState();
|
||||
void clearState();
|
||||
static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB);
|
||||
static int timerHandler(int t);
|
||||
|
||||
bool handleEvent_swipe(Common::Event &event, int direction, int touches);
|
||||
bool handleEvent_tap(Common::Event &event, UIViewTapDescription type, int touches);
|
||||
bool handleEvent_longPress(Common::Event &event, UIViewLongPressDescription type, int touches);
|
||||
void handleEvent_keyPressed(Common::Event &event, int keyPressed, int modifierFlags);
|
||||
void handleEvent_orientationChanged(int orientation);
|
||||
void handleEvent_touchModeChanged();
|
||||
void handleEvent_applicationSuspended();
|
||||
void handleEvent_applicationResumed();
|
||||
void handleEvent_applicationSaveState();
|
||||
void handleEvent_applicationRestoreState();
|
||||
void handleEvent_applicationClearState();
|
||||
|
||||
bool handleEvent_touchBegan(Common::Event &event, int x, int y);
|
||||
bool handleEvent_touchMoved(Common::Event &event, int x, int y);
|
||||
|
||||
void handleEvent_mouseLeftButtonDown(Common::Event &event, int x, int y);
|
||||
void handleEvent_mouseLeftButtonUp(Common::Event &event, int x, int y);
|
||||
void handleEvent_mouseRightButtonDown(Common::Event &event, int x, int y);
|
||||
void handleEvent_mouseRightButtonUp(Common::Event &event, int x, int y);
|
||||
void handleEvent_mouseDelta(Common::Event &event, int deltaX, int deltaY);
|
||||
void handleEvent_mouseEvent(Common::Event &event, int relX, int relY);
|
||||
|
||||
void rebuildSurface();
|
||||
float getMouseSpeed();
|
||||
};
|
||||
|
||||
#endif
|
||||
402
backends/platform/ios7/ios7_osys_misc.mm
Normal file
402
backends/platform/ios7/ios7_osys_misc.mm
Normal file
@@ -0,0 +1,402 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
// Needs to be included first as system headers redefine NO and YES, which clashes
|
||||
// with the DisposeAfterUse::Flag enum used in Common stream classes.
|
||||
#include "common/file.h"
|
||||
#include "common/translation.h"
|
||||
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
#include "base/version.h"
|
||||
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <UIKit/UIKit.h>
|
||||
#include <SystemConfiguration/SCNetworkReachability.h>
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
static inline void execute_on_main_thread_async(void (^block)(void)) {
|
||||
if ([NSThread currentThread] == [NSThread mainThread]) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), block);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::updateStartSettings(const Common::String &executable, Common::String &command, Common::StringMap &settings, Common::StringArray& additionalArgs) {
|
||||
NSBundle* bundle = [NSBundle mainBundle];
|
||||
// Check if scummvm is running from an app bundle
|
||||
if (!bundle || ![bundle bundleIdentifier]) {
|
||||
// Use default autostart implementation
|
||||
EventsBaseBackend::updateStartSettings(executable, command, settings, additionalArgs);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the bundle contains a scummvm.ini, use it as initial config
|
||||
NSString *iniPath = [bundle pathForResource:@"scummvm" ofType:@"ini"];
|
||||
if (iniPath && !settings.contains("initial-cfg"))
|
||||
settings["initial-cfg"] = "appbundle:/scummvm.ini";
|
||||
|
||||
// If a command was specified on the command line, do not override it
|
||||
if (!command.empty())
|
||||
return;
|
||||
|
||||
// Check if we have an autorun file with additional arguments
|
||||
NSString *autorunPath = [bundle pathForResource:@"scummvm-autorun" ofType:nil];
|
||||
if (autorunPath) {
|
||||
Common::File autorun;
|
||||
Common::String line;
|
||||
if (autorun.open(Common::FSNode("appbundle:/scummvm-autorun"))) {
|
||||
while (!autorun.eos()) {
|
||||
line = autorun.readLine();
|
||||
if (!line.empty() && line[0] != '#')
|
||||
additionalArgs.push_back(line);
|
||||
}
|
||||
}
|
||||
autorun.close();
|
||||
}
|
||||
|
||||
// If the bundle contains a game directory, auto-detect it
|
||||
NSString *gamePath = [[bundle resourcePath] stringByAppendingPathComponent:@"game"];
|
||||
BOOL isDir = false;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:gamePath isDirectory:&isDir];
|
||||
if (exists && isDir) {
|
||||
// Use auto-detection
|
||||
command = "auto-detect";
|
||||
settings["path"] = "appbundle:/game";
|
||||
return;
|
||||
}
|
||||
|
||||
// The rest of the function has some commands executed only the first time after each version change
|
||||
// Check the last version stored in the user settings.
|
||||
NSString *versionString = [NSString stringWithUTF8String:gScummVMFullVersion];
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSString *lastVersion = [defaults stringForKey:@"lastVersion"];
|
||||
if (lastVersion && [lastVersion isEqualToString:versionString])
|
||||
return;
|
||||
[defaults setObject:versionString forKey:@"lastVersion"];
|
||||
|
||||
// If the bundle contains a games directory, add them to the launcher
|
||||
NSString *gamesPath = [[bundle resourcePath] stringByAppendingPathComponent:@"games"];
|
||||
isDir = false;
|
||||
exists = [[NSFileManager defaultManager] fileExistsAtPath:gamesPath isDirectory:&isDir];
|
||||
if (exists && isDir) {
|
||||
// Detect and add games
|
||||
command = "add";
|
||||
settings["path"] = "appbundle:/games";
|
||||
settings["recursive"] = "true";
|
||||
settings["exit"] = "false";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Common::String OSystem_iOS7::getSystemLanguage() const {
|
||||
NSString *language = [[NSLocale preferredLanguages] firstObject];
|
||||
if (language == nil)
|
||||
return Common::String();
|
||||
Common::String lang([language cStringUsingEncoding:NSISOLatin1StringEncoding]);
|
||||
// Depending on the iOS version this may use an underscore (e.g. en_US) or a
|
||||
// dash (en-US). Make sure we always return one with an underscore.
|
||||
Common::replace(lang, "-", "_");
|
||||
return lang;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::hasTextInClipboard() {
|
||||
#if TARGET_OS_IOS
|
||||
return [[UIPasteboard generalPasteboard] containsPasteboardTypes:UIPasteboardTypeListString];
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
Common::U32String OSystem_iOS7::getTextFromClipboard() {
|
||||
if (!hasTextInClipboard())
|
||||
return Common::U32String();
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
UIPasteboard *pb = [UIPasteboard generalPasteboard];
|
||||
NSString *str = pb.string;
|
||||
if (str == nil)
|
||||
return Common::U32String();
|
||||
|
||||
// If translations are supported, use the current TranslationManager charset and otherwise
|
||||
// use ASCII. If the string cannot be represented using the requested encoding we get a null
|
||||
// pointer below, which is fine as ScummVM would not know what to do with the string anyway.
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
NSStringEncoding stringEncoding = NSUTF32LittleEndianStringEncoding;
|
||||
#else
|
||||
NSStringEncoding stringEncoding = NSUTF32BigEndianStringEncoding;
|
||||
#endif
|
||||
NSUInteger textLength = [str length];
|
||||
uint32 *text = new uint32[textLength];
|
||||
|
||||
if (![str getBytes:text maxLength:4*textLength usedLength:NULL encoding: stringEncoding options:0 range:NSMakeRange(0, textLength) remainingRange:NULL]) {
|
||||
delete[] text;
|
||||
return Common::U32String();
|
||||
}
|
||||
|
||||
Common::U32String u32String(text, textLength);
|
||||
delete[] text;
|
||||
|
||||
return u32String;
|
||||
#else
|
||||
return Common::U32String();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::setTextInClipboard(const Common::U32String &text) {
|
||||
#if TARGET_OS_IOS
|
||||
#ifdef SCUMM_LITTLE_ENDIAN
|
||||
NSStringEncoding stringEncoding = NSUTF32LittleEndianStringEncoding;
|
||||
#else
|
||||
NSStringEncoding stringEncoding = NSUTF32BigEndianStringEncoding;
|
||||
#endif
|
||||
UIPasteboard *pb = [UIPasteboard generalPasteboard];
|
||||
NSString *nsstring = [[NSString alloc] initWithBytes:text.c_str() length:4*text.size() encoding: stringEncoding];
|
||||
[pb setString:nsstring];
|
||||
[nsstring release];
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::openUrl(const Common::String &url) {
|
||||
UIApplication *application = [UIApplication sharedApplication];
|
||||
NSURL *nsurl = [NSURL URLWithString:[NSString stringWithCString:url.c_str() encoding:NSISOLatin1StringEncoding]];
|
||||
// The way to oipen a URL has changed in iOS 10. Check if the iOS 10 method is recognized
|
||||
// and otherwise use the old method.
|
||||
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
|
||||
execute_on_main_thread_async(^ {
|
||||
[application openURL:nsurl options:@{} completionHandler:nil];
|
||||
});
|
||||
} else {
|
||||
execute_on_main_thread_async(^ {
|
||||
[application openURL:nsurl];
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::isConnectionLimited() {
|
||||
// If we are connected to the internet through a cellular network, return true
|
||||
SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [@"www.google.com" UTF8String]);
|
||||
if (!ref)
|
||||
return false;
|
||||
SCNetworkReachabilityFlags flags = 0;
|
||||
SCNetworkReachabilityGetFlags(ref, &flags);
|
||||
CFRelease(ref);
|
||||
return (flags & kSCNetworkReachabilityFlagsIsWWAN);
|
||||
}
|
||||
|
||||
Common::HardwareInputSet *OSystem_iOS7::getHardwareInputSet() {
|
||||
using namespace Common;
|
||||
|
||||
CompositeHardwareInputSet *inputSet = new CompositeHardwareInputSet();
|
||||
// Mouse is always supported, either through touch or device
|
||||
inputSet->addHardwareInputSet(new MouseHardwareInputSet(defaultMouseButtons));
|
||||
|
||||
if ([[iOS7AppDelegate iPhoneView] isGamepadControllerSupported]) {
|
||||
inputSet->addHardwareInputSet(new JoystickHardwareInputSet(defaultJoystickButtons, defaultJoystickAxes));
|
||||
}
|
||||
|
||||
inputSet->addHardwareInputSet(new KeyboardHardwareInputSet(defaultKeys, defaultModifiers));
|
||||
|
||||
return inputSet;
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationSaveState() {
|
||||
[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
|
||||
saveState();
|
||||
[[iOS7AppDelegate iPhoneView] endBackgroundSaveStateTask];
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationRestoreState() {
|
||||
restoreState();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::handleEvent_applicationClearState() {
|
||||
clearState();
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
static const char * const helpTabs[] = {
|
||||
|
||||
_s("Getting help"),
|
||||
"",
|
||||
_s(
|
||||
"## Help, I'm lost!\n"
|
||||
"\n"
|
||||
"First, make sure you have the games and necessary game files ready. Check the **Where to Get the Games** section under the **General** tab. Once obtained, follow the steps outlined in the **Adding Games** tab to finish adding them on this device.\n"
|
||||
"\n"
|
||||
"Need more help? Refer to our [online documentation for iOS](https://docs.scummvm.org/en/latest/other_platforms/ios.html). Got questions? Swing by our [support forums](https://forums.scummvm.org/viewforum.php?f=15) or hop on our [Discord server](https://discord.gg/4cDsMNtcpG), which includes an [iOS support channel](https://discord.com/channels/581224060529148060/1149456560922316911).\n"
|
||||
"\n"
|
||||
"Oh, and heads up, many of our supported games are intentionally tricky, sometimes mind-bogglingly so. If you're stuck in a game, think about checking out a game walkthrough. Good luck!\n"
|
||||
),
|
||||
|
||||
_s("Touch Controls"),
|
||||
"ios-help.zip",
|
||||
_s(
|
||||
"## Touch control modes\n"
|
||||
"The touch control mode can be changed by tapping or clicking on the controller icon in the upper right corner, by swiping two fingers from left to right, or in the global settings from the Launcher go to **Global Options > Backend > Choose the preferred touch mode**. It's possible to configure the touch mode for three situations (ScummVM menus, 2D games and 3D games).\n"
|
||||
"\n"
|
||||
"### Direct mouse \n"
|
||||
"\n"
|
||||
"The touch controls are direct. The pointer jumps to where the finger touches the screen (default for menus).\n"
|
||||
"\n"
|
||||
" {w=10em}\n"
|
||||
"\n"
|
||||
"### Touchpad emulation \n"
|
||||
"\n"
|
||||
"The touch controls are indirect, like on a laptop touchpad.\n"
|
||||
"\n"
|
||||
" {w=10em}\n"
|
||||
"\n"
|
||||
"To select the preferred touch mode for menus, 2D games, and 3D games, go to **Global Options > Backend > Choose the preferred touch mode**.\n"
|
||||
"\n"
|
||||
"## Touch actions \n"
|
||||
"\n"
|
||||
"| Gesture | Action \n"
|
||||
"| ------------------|-------------------\n"
|
||||
"| `One finger tap` | Left mouse click \n"
|
||||
"| `Two fingers tap` | Right mouse click \n"
|
||||
"| `Two fingers double tap` | ESC \n"
|
||||
"| `One finger press & hold for >0.5s` | Left mouse button hold and drag, such as for selection from action wheel in Curse of Monkey Island \n"
|
||||
"| `Two fingers press & hold for >0.5s` | Right mouse button hold and drag, such as for selection from action wheel in Tony Tough \n"
|
||||
"| `Two fingers swipe (left to right)` | Toggles between the touch modes \n"
|
||||
"| `Two fingers swipe (right to left)` | Toggles virtual controller (>iOS 15) \n"
|
||||
"| `Two fingers swipe (top to bottom)` | Access Global Main Menu in games \n"
|
||||
"| `Pinch (zoom in/out)` | Enables/disables keyboard \n"
|
||||
"\n"
|
||||
"### Virtual Gamepad \n"
|
||||
"\n"
|
||||
"Devices running iOS 15 or later can connect virtual gamepad controller by swiping two fingers from right to left or through **Global Options > Backend**. The directional button can be configured to either a thumbstick or a dpad.\n"
|
||||
"**Note** While the virtual controller is connected it is not possible to perform mouse clicks using tap gestures since they are disabled as long as the virtual controller is visible. Left mouse clicks are performed by pressing the A button. Tap gestures are enabled again when virtual controller is disconnected.\n"
|
||||
"\n"
|
||||
"### Global Main Menu\n"
|
||||
"\n"
|
||||
"To open the Global Main Menu, tap on the menu icon at the top right of the screen or swipe two fingers downwards.\n"
|
||||
"\n"
|
||||
" {w=10em}\n"
|
||||
"\n"
|
||||
"## Virtual keyboard\n"
|
||||
"\n"
|
||||
"To open the virtual keyboard, long press on the controller icon at the top right of the screen, perform a pinch gesture (zoom out) or tap on any editable text field. To hide the virtual keyboard, tap the controller icon again, do an opposite pinch gesture (zoom in) or tap outside the text field.\n"
|
||||
"\n"
|
||||
"\n"
|
||||
" {w=10em}\n"
|
||||
"\n"
|
||||
),
|
||||
_s("External keyboard"),
|
||||
"",
|
||||
_s(
|
||||
"## Use of keyboard\n"
|
||||
"External keyboards are supported and from iOS 13.4 most of the special keys, e.g. function keys, Home and End, are mapped. \n"
|
||||
"For external keyboards missing the special keys, e.g. the Apple Magic Keyboard for iPads, the special keys can be triggered using the following key combinations: \n"
|
||||
"\n"
|
||||
"\n"
|
||||
"| Key combination | Action \n"
|
||||
"| ------------------|-------------------\n"
|
||||
"| `CMD + 1` | F1 \n"
|
||||
"| `CMD + 2` | F2 \n"
|
||||
"| `...` | ... \n"
|
||||
"| `CMD + 0` | F10 \n"
|
||||
"| `CMD + SHIFT + 1` | F11 \n"
|
||||
"| `CMD + SHIFT + 2` | F12 \n"
|
||||
"| `CMD + UP` | PAGE UP \n"
|
||||
"| `CMD + DOWN` | PAGE DOWN \n"
|
||||
"| `CMD + LEFT` | HOME \n"
|
||||
"| `CMD + RIGHT` | END \n"
|
||||
"\n"
|
||||
),
|
||||
_s("Adding Games"),
|
||||
"ios-help.zip",
|
||||
_s(
|
||||
"## Adding Games \n"
|
||||
"\n"
|
||||
"1. Copy the required game files to the ScummVM application. There are several ways to do that, see our [Transferring game files documentation](https://docs.scummvm.org/en/latest/other_platforms/ios.html#transferring-game-files) for more information.\n"
|
||||
"\n"
|
||||
"2. Select **Add Game...** from the launcher. \n"
|
||||
"\n"
|
||||
"3. In the ScummVM file browser, double-tap to browse to your added folder. Add a game by selecting the sub-folder containing the game files, then tap **Choose**. \n"
|
||||
"\n"
|
||||
"To add more games, repeat the steps above. \n"
|
||||
"\n"
|
||||
"See our [iOS documentation](https://docs.scummvm.org/en/latest/other_platforms/ios.html) for more information.\n"
|
||||
),
|
||||
|
||||
0 // End of list
|
||||
};
|
||||
#else //TVOS
|
||||
static const char * const helpTabs[] = {
|
||||
|
||||
_s("Touch Controls"),
|
||||
"",
|
||||
_s(
|
||||
"## Touch actions \n"
|
||||
"\n"
|
||||
"### Press Touch area \n"
|
||||
"\n"
|
||||
"Press Touch area to perform a left mouse click"
|
||||
"\n"
|
||||
"### Play/Pause\n"
|
||||
"\n"
|
||||
"Press Play/Pause to perform a right mouse click\n"
|
||||
"\n"
|
||||
"### Global Main Menu\n"
|
||||
"\n"
|
||||
"To open the Global Main Menu, press Back/Menu button.\n"
|
||||
"\n"
|
||||
"## Virtual keyboard\n"
|
||||
"\n"
|
||||
"To open the virtual keyboard, press and hold the Play/Pause button. To hide the virtual keyboard, press the Back/Menu button.\n"
|
||||
"\n"
|
||||
),
|
||||
|
||||
_s("Adding Games"),
|
||||
"",
|
||||
_s(
|
||||
"## Adding Games \n"
|
||||
"\n"
|
||||
"1. Copy the required game files to the ScummVM application. There are several ways to do that, see our [Transferring game files documentation](https://docs.scummvm.org/en/latest/other_platforms/tvos.html#transferring-game-files) for more information.\n"
|
||||
"\n"
|
||||
"2. Select **Add Game...** from the launcher. \n"
|
||||
"\n"
|
||||
"3. In the ScummVM file browser, double-tap to browse to your added folder. Add a game by selecting the sub-folder containing the game files, then tap **Choose**. \n"
|
||||
"\n"
|
||||
"To add more games, repeat the steps above. \n"
|
||||
"\n"
|
||||
"See our [tvOS documentation](https://docs.scummvm.org/en/latest/other_platforms/tvos.html) for more information.\n"
|
||||
),
|
||||
|
||||
0 // End of list
|
||||
};
|
||||
#endif
|
||||
|
||||
const char * const *OSystem_iOS7::buildHelpDialogData() {
|
||||
return helpTabs;
|
||||
}
|
||||
104
backends/platform/ios7/ios7_osys_sound.cpp
Normal file
104
backends/platform/ios7/ios7_osys_sound.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
|
||||
void OSystem_iOS7::AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB) {
|
||||
//printf("AQBufferCallback()\n");
|
||||
if (s_AudioQueue.frameCount > 0 && s_soundCallback != NULL) {
|
||||
outQB->mAudioDataByteSize = 4 * s_AudioQueue.frameCount;
|
||||
s_soundCallback(s_soundParam, (byte *)outQB->mAudioData, outQB->mAudioDataByteSize);
|
||||
AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
|
||||
} else {
|
||||
AudioQueueStop(s_AudioQueue.queue, false);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::mixCallback(void *sys, byte *samples, int len) {
|
||||
OSystem_iOS7 *this_ = (OSystem_iOS7 *)sys;
|
||||
assert(this_);
|
||||
|
||||
if (this_->_mixer) {
|
||||
this_->_mixer->mixCallback(samples, len);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::setupMixer() {
|
||||
_mixer = new Audio::MixerImpl(AUDIO_SAMPLE_RATE, true, WAVE_BUFFER_SIZE);
|
||||
|
||||
s_soundCallback = mixCallback;
|
||||
s_soundParam = this;
|
||||
|
||||
startSoundsystem();
|
||||
}
|
||||
|
||||
void OSystem_iOS7::startSoundsystem() {
|
||||
s_AudioQueue.dataFormat.mSampleRate = AUDIO_SAMPLE_RATE;
|
||||
s_AudioQueue.dataFormat.mFormatID = kAudioFormatLinearPCM;
|
||||
s_AudioQueue.dataFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
|
||||
s_AudioQueue.dataFormat.mBytesPerPacket = 4;
|
||||
s_AudioQueue.dataFormat.mFramesPerPacket = 1;
|
||||
s_AudioQueue.dataFormat.mBytesPerFrame = 4;
|
||||
s_AudioQueue.dataFormat.mChannelsPerFrame = 2;
|
||||
s_AudioQueue.dataFormat.mBitsPerChannel = 16;
|
||||
s_AudioQueue.frameCount = WAVE_BUFFER_SIZE;
|
||||
|
||||
if (AudioQueueNewOutput(&s_AudioQueue.dataFormat, AQBufferCallback, &s_AudioQueue, 0, kCFRunLoopCommonModes, 0, &s_AudioQueue.queue)) {
|
||||
printf("Couldn't set the AudioQueue callback!\n");
|
||||
_mixer->setReady(false);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 bufferBytes = s_AudioQueue.frameCount * s_AudioQueue.dataFormat.mBytesPerFrame;
|
||||
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
if (AudioQueueAllocateBuffer(s_AudioQueue.queue, bufferBytes, &s_AudioQueue.buffers[i])) {
|
||||
printf("Error allocating AudioQueue buffer!\n");
|
||||
_mixer->setReady(false);
|
||||
return;
|
||||
}
|
||||
|
||||
AQBufferCallback(&s_AudioQueue, s_AudioQueue.queue, s_AudioQueue.buffers[i]);
|
||||
}
|
||||
|
||||
AudioQueueSetParameter(s_AudioQueue.queue, kAudioQueueParam_Volume, 1.0);
|
||||
if (AudioQueueStart(s_AudioQueue.queue, NULL)) {
|
||||
printf("Error starting the AudioQueue!\n");
|
||||
_mixer->setReady(false);
|
||||
return;
|
||||
}
|
||||
|
||||
_mixer->setReady(true);
|
||||
}
|
||||
|
||||
void OSystem_iOS7::stopSoundsystem() {
|
||||
AudioQueueStop(s_AudioQueue.queue, true);
|
||||
|
||||
for (int i = 0; i < AUDIO_BUFFERS; i++) {
|
||||
AudioQueueFreeBuffer(s_AudioQueue.queue, s_AudioQueue.buffers[i]);
|
||||
}
|
||||
|
||||
AudioQueueDispose(s_AudioQueue.queue, true);
|
||||
_mixer->setReady(false);
|
||||
}
|
||||
298
backends/platform/ios7/ios7_osys_video.mm
Normal file
298
backends/platform/ios7/ios7_osys_video.mm
Normal file
@@ -0,0 +1,298 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "backends/platform/ios7/ios7_osys_main.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
|
||||
#define UIViewParentController(__view) ({ \
|
||||
UIResponder *__responder = __view; \
|
||||
while ([__responder isKindOfClass:[UIView class]]) \
|
||||
__responder = [__responder nextResponder]; \
|
||||
(UIViewController *)__responder; \
|
||||
})
|
||||
|
||||
static void displayAlert(void *ctx) {
|
||||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Fatal Error"
|
||||
message:[NSString stringWithCString:(const char *)ctx encoding:NSUTF8StringEncoding]
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
OSystem_iOS7::sharedInstance()->quit();
|
||||
abort();
|
||||
}];
|
||||
|
||||
[alert addAction:defaultAction];
|
||||
[UIViewParentController([iOS7AppDelegate iPhoneView]) presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
void OSystem_iOS7::fatalError() {
|
||||
if (_lastErrorMessage.size()) {
|
||||
dispatch_async_f(dispatch_get_main_queue(), (void *)_lastErrorMessage.c_str(), displayAlert);
|
||||
for(;;);
|
||||
}
|
||||
else {
|
||||
OSystem::fatalError();
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::logMessage(LogMessageType::Type type, const char *message) {
|
||||
FILE *output = 0;
|
||||
|
||||
if (type == LogMessageType::kInfo || type == LogMessageType::kDebug)
|
||||
output = stdout;
|
||||
else
|
||||
output = stderr;
|
||||
|
||||
if (type == LogMessageType::kError) {
|
||||
_lastErrorMessage = message;
|
||||
NSString *messageString = [NSString stringWithUTF8String:message];
|
||||
NSLog(@"%@", messageString);
|
||||
}
|
||||
|
||||
fputs(message, output);
|
||||
fflush(output);
|
||||
}
|
||||
|
||||
static inline void execute_on_main_thread(void (^block)(void)) {
|
||||
if ([NSThread currentThread] == [NSThread mainThread]) {
|
||||
block();
|
||||
}
|
||||
else {
|
||||
dispatch_sync(dispatch_get_main_queue(), block);
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::engineInit() {
|
||||
EventsBaseBackend::engineInit();
|
||||
// Prevent the device going to sleep during game play (and in particular cut scenes)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
||||
});
|
||||
[[iOS7AppDelegate iPhoneView] setIsInGame:YES];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
applyOrientationSettings();
|
||||
updateTouchMode();
|
||||
|
||||
// Automatically open the keyboard when starting a game and in portrait mode.
|
||||
// This is preferred for text input games and there's a lot of screen space to
|
||||
// utilize for the keyboard anyway.
|
||||
if (_screenOrientation == kScreenOrientationPortrait ||
|
||||
_screenOrientation == kScreenOrientationFlippedPortrait) {
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] showKeyboard];
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OSystem_iOS7::engineDone() {
|
||||
EventsBaseBackend::engineDone();
|
||||
// Allow the device going to sleep if idle while in the Launcher
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
||||
});
|
||||
[[iOS7AppDelegate iPhoneView] setIsInGame:NO];
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
applyOrientationSettings();
|
||||
updateTouchMode();
|
||||
|
||||
// Hide keyboard when going back to launcher
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] hideKeyboard];
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void OSystem_iOS7::taskStarted(Task task) {
|
||||
EventsBaseBackend::taskStarted(task);
|
||||
if (_runningTasks++ == 0) {
|
||||
// Prevent the device going to sleep while a task is running
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
|
||||
});
|
||||
}
|
||||
}
|
||||
void OSystem_iOS7::taskFinished(Task task) {
|
||||
EventsBaseBackend::taskFinished(task);
|
||||
if (--_runningTasks == 0) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void OSystem_iOS7::updateOutputSurface() {
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] initSurface];
|
||||
});
|
||||
}
|
||||
|
||||
void OSystem_iOS7::updateTouchMode() {
|
||||
#if TARGET_OS_IOS
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] updateTouchMode];
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void OSystem_iOS7::virtualController(bool connect) {
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] virtualController:connect];
|
||||
});
|
||||
}
|
||||
|
||||
bool OSystem_iOS7::isiOSAppOnMac() const {
|
||||
__block bool isiOSAppOnMac = false;
|
||||
execute_on_main_thread(^ {
|
||||
isiOSAppOnMac = [[iOS7AppDelegate iPhoneView] isiOSAppOnMac];
|
||||
});
|
||||
return isiOSAppOnMac;
|
||||
}
|
||||
|
||||
void OSystem_iOS7::setShowKeyboard(bool show) {
|
||||
if (show) {
|
||||
#if TARGET_OS_IOS
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] showKeyboard];
|
||||
});
|
||||
#elif TARGET_OS_TV
|
||||
// Delay the showing of keyboard 1 second so the user
|
||||
// is able to see the message
|
||||
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC));
|
||||
dispatch_after(delay, dispatch_get_main_queue(), ^(void){
|
||||
[[iOS7AppDelegate iPhoneView] showKeyboard];
|
||||
});
|
||||
#endif
|
||||
} else {
|
||||
// If in game, do not hide the keyboard in portrait mode as it is shown automatically and not
|
||||
// just when asked with the kFeatureVirtualKeyboard.
|
||||
if (_screenOrientation == kScreenOrientationLandscape || _screenOrientation == kScreenOrientationFlippedLandscape || ![[iOS7AppDelegate iPhoneView] isInGame]) {
|
||||
execute_on_main_thread(^ {
|
||||
[[iOS7AppDelegate iPhoneView] hideKeyboard];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
void OSystem_iOS7::setSupportedScreenOrientation(ScreenOrientation screenOrientation) {
|
||||
bool shouldUpdateScreenOrientation = false;
|
||||
|
||||
switch (screenOrientation) {
|
||||
case kScreenOrientationPortrait:
|
||||
case kScreenOrientationFlippedPortrait:
|
||||
[[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskPortrait];
|
||||
if (_screenOrientation != kScreenOrientationPortrait &&
|
||||
_screenOrientation != kScreenOrientationFlippedPortrait) {
|
||||
shouldUpdateScreenOrientation = true;
|
||||
}
|
||||
break;
|
||||
case kScreenOrientationLandscape:
|
||||
case kScreenOrientationFlippedLandscape:
|
||||
[[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskLandscape];
|
||||
if (_screenOrientation != kScreenOrientationLandscape &&
|
||||
_screenOrientation != kScreenOrientationFlippedLandscape) {
|
||||
shouldUpdateScreenOrientation = true;
|
||||
}
|
||||
break;
|
||||
case kScreenOrientationAuto:
|
||||
default:
|
||||
[[iOS7AppDelegate iPhoneView] setSupportedScreenOrientations:UIInterfaceOrientationMaskAll];
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_16_0
|
||||
if (@available(iOS 16.0, *)) {
|
||||
execute_on_main_thread(^ {
|
||||
[UIViewParentController([iOS7AppDelegate iPhoneView]) setNeedsUpdateOfSupportedInterfaceOrientations];
|
||||
});
|
||||
// We don't end up here if orientation is set to auto.
|
||||
// Also, we won't know for sure if it will select right or left for landscape
|
||||
// orientation, or normal or upside down (most probably normal) for portrait.
|
||||
// The _screenOrientation will be set accordingly when handling the orientationChanged
|
||||
// event so just set it to what we're given for now.
|
||||
_screenOrientation = screenOrientation;
|
||||
} else
|
||||
#endif
|
||||
if (shouldUpdateScreenOrientation) {
|
||||
switch (screenOrientation) {
|
||||
case kScreenOrientationPortrait:
|
||||
case kScreenOrientationFlippedPortrait:
|
||||
execute_on_main_thread(^ {
|
||||
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
|
||||
});
|
||||
_screenOrientation = kScreenOrientationPortrait;
|
||||
break;
|
||||
case kScreenOrientationLandscape:
|
||||
case kScreenOrientationFlippedLandscape:
|
||||
execute_on_main_thread(^ {
|
||||
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeRight) forKey:@"orientation"];
|
||||
});
|
||||
_screenOrientation = kScreenOrientationLandscape;
|
||||
break;
|
||||
case kScreenOrientationAuto:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool OSystem_iOS7::isKeyboardShown() const {
|
||||
__block bool isShown = false;
|
||||
execute_on_main_thread(^{
|
||||
isShown = [[iOS7AppDelegate iPhoneView] isKeyboardShown];
|
||||
});
|
||||
return isShown;
|
||||
}
|
||||
|
||||
uint OSystem_iOS7::createOpenGLContext() {
|
||||
return [[iOS7AppDelegate iPhoneView] createOpenGLContext];
|
||||
}
|
||||
|
||||
void OSystem_iOS7::destroyOpenGLContext() {
|
||||
[[iOS7AppDelegate iPhoneView] destroyOpenGLContext];
|
||||
}
|
||||
|
||||
void OSystem_iOS7::refreshScreen() const {
|
||||
[[iOS7AppDelegate iPhoneView] refreshScreen];
|
||||
}
|
||||
|
||||
int OSystem_iOS7::getScreenWidth() const {
|
||||
return [[iOS7AppDelegate iPhoneView] getScreenWidth];
|
||||
}
|
||||
|
||||
int OSystem_iOS7::getScreenHeight() const {
|
||||
return [[iOS7AppDelegate iPhoneView] getScreenHeight];
|
||||
}
|
||||
|
||||
float OSystem_iOS7::getSystemHiDPIScreenFactor() const {
|
||||
return [[UIScreen mainScreen] scale];
|
||||
}
|
||||
|
||||
32
backends/platform/ios7/ios7_scene_delegate.h
Normal file
32
backends/platform/ios7/ios7_scene_delegate.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_SCENE_DELEGATE_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_SCENE_DELEGATE_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
API_AVAILABLE(ios(13.0))
|
||||
@interface iOS7SceneDelegate : NSObject<UIWindowSceneDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
58
backends/platform/ios7/ios7_scene_delegate.mm
Normal file
58
backends/platform/ios7/ios7_scene_delegate.mm
Normal file
@@ -0,0 +1,58 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "backends/platform/ios7/ios7_scene_delegate.h"
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
API_AVAILABLE(ios(13.0))
|
||||
@implementation iOS7SceneDelegate
|
||||
|
||||
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
|
||||
|
||||
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
||||
[iOS7AppDelegate setKeyWindow:[[UIWindow alloc] initWithWindowScene:windowScene]];
|
||||
}
|
||||
|
||||
- (void)sceneDidDisconnect:(UIScene *)scene {
|
||||
}
|
||||
|
||||
- (void)sceneDidBecomeActive:(UIScene *)scene {
|
||||
[[iOS7AppDelegate iPhoneView] applicationResume];
|
||||
}
|
||||
|
||||
- (void)sceneWillResignActive:(UIScene *)scene {
|
||||
[[iOS7AppDelegate iPhoneView] applicationSuspend];
|
||||
}
|
||||
|
||||
- (void)sceneDidEnterBackground:(UIScene *)scene {
|
||||
// Start the background task before sending the application entered background event.
|
||||
// This is because this event will be handled in a separate thread and it will likely
|
||||
// no be started before we return from this function.
|
||||
[[iOS7AppDelegate iPhoneView] beginBackgroundSaveStateTask];
|
||||
|
||||
[[iOS7AppDelegate iPhoneView] saveApplicationState];
|
||||
}
|
||||
|
||||
- (void)sceneWillEnterForeground:(UIScene *)scene {
|
||||
}
|
||||
|
||||
@end
|
||||
44
backends/platform/ios7/ios7_scummvm_view_controller.h
Normal file
44
backends/platform/ios7/ios7_scummvm_view_controller.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_SCUMMVM_VIEW_CONTROLLER_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_SCUMMVM_VIEW_CONTROLLER_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface iOS7ScummVMViewController : UIViewController {
|
||||
#if TARGET_OS_IOS
|
||||
UIInterfaceOrientation currentOrientation;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (UIInterfaceOrientation)interfaceOrientation;
|
||||
|
||||
- (UIInterfaceOrientation)currentOrientation;
|
||||
-(void) updateCurrentOrientation;
|
||||
-(void) setCurrentOrientation:(UIInterfaceOrientation)orientation;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
122
backends/platform/ios7/ios7_scummvm_view_controller.mm
Normal file
122
backends/platform/ios7/ios7_scummvm_view_controller.mm
Normal file
@@ -0,0 +1,122 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "backends/platform/ios7/ios7_scummvm_view_controller.h"
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
@implementation iOS7ScummVMViewController
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
#if TARGET_OS_IOS
|
||||
self->currentOrientation = UIInterfaceOrientationUnknown;
|
||||
#endif
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)prefersHomeIndicatorAutoHidden {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)prefersPointerLocked {
|
||||
/* This hides the OS cursor so ScummVM has to draw one */
|
||||
return YES;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
|
||||
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
|
||||
return UIRectEdgeAll;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)interfaceOrientation {
|
||||
if (@available(iOS 13.0, *)) {
|
||||
return [[[[self view] window] windowScene] interfaceOrientation];
|
||||
} else {
|
||||
return [[UIApplication sharedApplication] statusBarOrientation];
|
||||
}
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientation)currentOrientation {
|
||||
return currentOrientation;
|
||||
}
|
||||
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
|
||||
return [[iOS7AppDelegate iPhoneView] supportedScreenOrientations];
|
||||
}
|
||||
|
||||
-(void) updateCurrentOrientation {
|
||||
UIInterfaceOrientation interfaceOrientation = [self interfaceOrientation];
|
||||
if (interfaceOrientation != UIInterfaceOrientationUnknown)
|
||||
[self setCurrentOrientation: interfaceOrientation];
|
||||
}
|
||||
|
||||
-(void) setCurrentOrientation:(UIInterfaceOrientation)orientation {
|
||||
if (orientation != currentOrientation) {
|
||||
currentOrientation = orientation;
|
||||
[[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:currentOrientation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated];
|
||||
|
||||
UIInterfaceOrientation orientation = [self interfaceOrientation];
|
||||
if (orientation != UIInterfaceOrientationUnknown && orientation != currentOrientation) {
|
||||
currentOrientation = orientation;
|
||||
[[iOS7AppDelegate iPhoneView] interfaceOrientationChanged:orientation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
|
||||
// In iOS 16, make sure that the current orientation is updated when the
|
||||
// function viewWillTransitionToSize is called to make sure it's updated
|
||||
// when the adjustViewFrameForSafeArea is called. This makes sure that the
|
||||
// screen size is updated correctly when forcing the orientation based on
|
||||
// the backend user setting.
|
||||
UIInterfaceOrientation orientationAfter = [self interfaceOrientation];
|
||||
if (orientationAfter != UIInterfaceOrientationUnknown) {
|
||||
[self setCurrentOrientation:orientationAfter];
|
||||
}
|
||||
// In iOS 15 (and below), set the current orientation when the transition
|
||||
// animation finishes to make sure that the interface orientation has been
|
||||
// updated to make sure the virtual controller is connected/disconnected
|
||||
// properly based on the orientation.
|
||||
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
||||
UIInterfaceOrientation orientation = [self interfaceOrientation];
|
||||
if (orientation != UIInterfaceOrientationUnknown) {
|
||||
[self setCurrentOrientation:orientation];
|
||||
if (@available(iOS 11.0, *)) {
|
||||
[self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
38
backends/platform/ios7/ios7_touch_controller.h
Normal file
38
backends/platform/ios7/ios7_touch_controller.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_TOUCH_CONTROLLER_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_TOUCH_CONTROLLER_H
|
||||
|
||||
#include "backends/platform/ios7/ios7_game_controller.h"
|
||||
|
||||
@interface TouchController : GameController
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view;
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* BACKENDS_PLATFORM_IOS7_IOS7_TOUCH_CONTROLLER_H */
|
||||
89
backends/platform/ios7/ios7_touch_controller.mm
Normal file
89
backends/platform/ios7/ios7_touch_controller.mm
Normal file
@@ -0,0 +1,89 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "backends/platform/ios7/ios7_touch_controller.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
|
||||
@implementation TouchController {
|
||||
UITouch *_touch;
|
||||
}
|
||||
|
||||
@dynamic view;
|
||||
@dynamic isConnected;
|
||||
|
||||
- (id)initWithView:(iPhoneView *)view {
|
||||
self = [super initWithView:view];
|
||||
|
||||
_touch = nil;
|
||||
// Touches should always be present in iOS view
|
||||
[self setIsConnected:YES];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)shouldHandleTouch:(UITouch *)touch {
|
||||
// In iOS touchpads will trigger UITouchTypeIndirect events
|
||||
// However, they will also send mose events. Make sure to
|
||||
// block the UITouchTypeIndirect but not in Apple TV OS where
|
||||
// they are required as the Apple TV remote sends touh events
|
||||
// but no mouse events.
|
||||
#if TARGET_OS_IOS
|
||||
return touch != nil && (touch.type == UITouchTypeDirect || touch.type == UITouchTypePencil);
|
||||
#else
|
||||
return YES;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
_touch = [touches anyObject];
|
||||
|
||||
if ([self shouldHandleTouch:_touch]) {
|
||||
CGPoint p = [self getLocationInView:_touch];
|
||||
[[self view] addEvent:InternalEvent(kInputTouchBegan, p.x, p.y)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
UITouch *t = [touches anyObject];
|
||||
|
||||
if (t != _touch) {
|
||||
// We shouldn't end up here but if we do bail out
|
||||
return;
|
||||
}
|
||||
_touch = t;
|
||||
if ([self shouldHandleTouch:_touch]) {
|
||||
CGPoint p = [self getLocationInView:_touch];
|
||||
[[self view] addEvent:InternalEvent(kInputTouchMoved, p.x, p.y)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
_touch = nil;
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
_touch = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
106
backends/platform/ios7/ios7_video.h
Normal file
106
backends/platform/ios7/ios7_video.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_PLATFORM_IOS7_IOS7_VIDEO_H
|
||||
#define BACKENDS_PLATFORM_IOS7_IOS7_VIDEO_H
|
||||
|
||||
#include <UIKit/UIKit.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
|
||||
#include <OpenGLES/EAGL.h>
|
||||
#include <OpenGLES/ES2/gl.h>
|
||||
#include <OpenGLES/ES2/glext.h>
|
||||
|
||||
#include "backends/platform/ios7/ios7_keyboard.h"
|
||||
#include "backends/platform/ios7/ios7_common.h"
|
||||
#include "backends/platform/ios7/ios7_game_controller.h"
|
||||
|
||||
#include "common/list.h"
|
||||
|
||||
typedef struct {
|
||||
GLfloat x, y;
|
||||
GLfloat u,v;
|
||||
} GLVertex;
|
||||
|
||||
uint getSizeNextPOT(uint size);
|
||||
|
||||
@interface iPhoneView : UIView {
|
||||
Common::List<InternalEvent> _events;
|
||||
NSLock *_eventLock;
|
||||
SoftKeyboard *_keyboardView;
|
||||
Common::List<GameController*> _controllers;
|
||||
#if TARGET_OS_IOS
|
||||
UIInterfaceOrientation _currentOrientation;
|
||||
#endif
|
||||
UIBackgroundTaskIdentifier _backgroundSaveStateTask;
|
||||
|
||||
EAGLContext *_mainContext;
|
||||
EAGLContext *_openGLContext;
|
||||
GLuint _viewRenderbuffer;
|
||||
|
||||
GLint _renderBufferWidth;
|
||||
GLint _renderBufferHeight;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) BOOL isInGame;
|
||||
@property (nonatomic, assign) UIInterfaceOrientationMask supportedScreenOrientations;
|
||||
|
||||
- (id)initWithFrame:(struct CGRect)frame;
|
||||
|
||||
- (uint)createOpenGLContext;
|
||||
- (void)destroyOpenGLContext;
|
||||
- (void)refreshScreen;
|
||||
- (int)getScreenWidth;
|
||||
- (int)getScreenHeight;
|
||||
|
||||
- (void)initSurface;
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)interfaceOrientationChanged:(UIInterfaceOrientation)orientation;
|
||||
- (void)updateTouchMode;
|
||||
- (BOOL)isiOSAppOnMac;
|
||||
#endif
|
||||
|
||||
- (void)showKeyboard;
|
||||
- (void)hideKeyboard;
|
||||
- (BOOL)isKeyboardShown;
|
||||
|
||||
- (void)handleMainMenuKey;
|
||||
|
||||
- (void)applicationSuspend;
|
||||
- (void)applicationResume;
|
||||
|
||||
- (void)saveApplicationState;
|
||||
- (void)clearApplicationState;
|
||||
- (void)restoreApplicationState;
|
||||
|
||||
- (void) beginBackgroundSaveStateTask;
|
||||
- (void) endBackgroundSaveStateTask;
|
||||
|
||||
- (void)addEvent:(InternalEvent)event;
|
||||
- (bool)fetchEvent:(InternalEvent *)event;
|
||||
|
||||
- (bool)isGamepadControllerSupported;
|
||||
- (void)virtualController:(bool)connect;
|
||||
@end
|
||||
|
||||
#endif
|
||||
931
backends/platform/ios7/ios7_video.mm
Normal file
931
backends/platform/ios7/ios7_video.mm
Normal file
@@ -0,0 +1,931 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// Disable symbol overrides so that we can use system headers.
|
||||
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
||||
|
||||
#include "common/events.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "backends/platform/ios7/ios7_video.h"
|
||||
#include "backends/platform/ios7/ios7_touch_controller.h"
|
||||
#include "backends/platform/ios7/ios7_mouse_controller.h"
|
||||
#include "backends/platform/ios7/ios7_gamepad_controller.h"
|
||||
|
||||
#include "backends/platform/ios7/ios7_app_delegate.h"
|
||||
|
||||
#ifdef __IPHONE_14_0
|
||||
#include <GameController/GameController.h>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
static long g_lastTick = 0;
|
||||
static int g_frames = 0;
|
||||
#endif
|
||||
|
||||
void printError(const char *error_message) {
|
||||
NSString *messageString = [NSString stringWithUTF8String:error_message];
|
||||
NSLog(@"%@", messageString);
|
||||
fprintf(stderr, "%s\n", error_message);
|
||||
}
|
||||
|
||||
#define printOpenGLError() printOglError(__FILE__, __LINE__)
|
||||
|
||||
void printOglError(const char *file, int line) {
|
||||
GLenum glErr = glGetError();
|
||||
while (glErr != GL_NO_ERROR) {
|
||||
Common::String error = Common::String::format("glError: %u (%s: %d)", glErr, file, line);
|
||||
printError(error.c_str());
|
||||
glErr = glGetError();
|
||||
}
|
||||
}
|
||||
|
||||
bool iOS7_isBigDevice() {
|
||||
#if TARGET_OS_IOS
|
||||
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
||||
#elif TARGET_OS_TV
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void execute_on_main_thread(void (^block)(void)) {
|
||||
if ([NSThread currentThread] == [NSThread mainThread]) {
|
||||
block();
|
||||
}
|
||||
else {
|
||||
dispatch_sync(dispatch_get_main_queue(), block);
|
||||
}
|
||||
}
|
||||
|
||||
bool iOS7_fetchEvent(InternalEvent *event) {
|
||||
__block bool fetched;
|
||||
execute_on_main_thread(^{
|
||||
fetched = [[iOS7AppDelegate iPhoneView] fetchEvent:event];
|
||||
});
|
||||
return fetched;
|
||||
}
|
||||
|
||||
@implementation iPhoneView {
|
||||
#if TARGET_OS_IOS
|
||||
UIButton *_menuButton;
|
||||
UIButton *_toggleTouchModeButton;
|
||||
UITapGestureRecognizer *oneFingerTapGesture;
|
||||
UITapGestureRecognizer *twoFingerTapGesture;
|
||||
UITapGestureRecognizer *pencilThreeTapGesture;
|
||||
UILongPressGestureRecognizer *oneFingerLongPressGesture;
|
||||
UILongPressGestureRecognizer *twoFingerLongPressGesture;
|
||||
UILongPressGestureRecognizer *pencilTwoTapLongTouchGesture;
|
||||
CGPoint touchesBegan;
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (Class)layerClass {
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
|
||||
// According to Apple doc layoutSublayersOfLayer: is supported from iOS 10.0.
|
||||
// This doesn't seem to be correct since the instance method layoutSublayers,
|
||||
// supported from iOS 2.0, default calls the layoutSublayersOfLayer: method
|
||||
// of the layer’s delegate object. It's been verified that this function is
|
||||
// called in at least iOS 9.3.5.
|
||||
- (void)layoutSublayersOfLayer:(CAEAGLLayer *)layer {
|
||||
if (layer == self.layer) {
|
||||
[self addEvent:InternalEvent(kInputScreenChanged, 0, 0)];
|
||||
}
|
||||
[super layoutSublayersOfLayer:layer];
|
||||
}
|
||||
|
||||
- (void)createContext {
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = @{
|
||||
kEAGLDrawablePropertyRetainedBacking: @NO,
|
||||
kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8,
|
||||
};
|
||||
|
||||
_mainContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
||||
|
||||
// Not all iDevices support OpenGLES 3, fallback to OpenGLES 2
|
||||
if (_mainContext == nil) {
|
||||
_mainContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
}
|
||||
// In case creating the OpenGL ES context failed, we will error out here.
|
||||
if (_mainContext == nil) {
|
||||
printError("Could not create OpenGL ES context.");
|
||||
abort();
|
||||
}
|
||||
|
||||
// main thread will always use _mainContext
|
||||
[EAGLContext setCurrentContext:_mainContext];
|
||||
}
|
||||
|
||||
- (uint)createOpenGLContext {
|
||||
// Create OpenGL context with the sharegroup from the context
|
||||
// connected to the Apple Core Animation layer
|
||||
if (!_openGLContext && _mainContext) {
|
||||
_openGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 sharegroup:_mainContext.sharegroup];
|
||||
|
||||
// Not all iDevices support OpenGLES 3, fallback to OpenGLES 2
|
||||
if (_openGLContext == nil) {
|
||||
_openGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:_mainContext.sharegroup];
|
||||
}
|
||||
if (_openGLContext == nil) {
|
||||
printError("Could not create OpenGL ES context using sharegroup");
|
||||
abort();
|
||||
}
|
||||
// background thread will always use _openGLContext
|
||||
if ([EAGLContext setCurrentContext:_openGLContext]) {
|
||||
[self setupRenderBuffer];
|
||||
}
|
||||
}
|
||||
return _viewRenderbuffer;
|
||||
}
|
||||
|
||||
- (void)destroyOpenGLContext {
|
||||
[_openGLContext release];
|
||||
_openGLContext = nil;
|
||||
}
|
||||
|
||||
- (void)refreshScreen {
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _viewRenderbuffer);
|
||||
[_openGLContext presentRenderbuffer:GL_RENDERBUFFER];
|
||||
}
|
||||
|
||||
- (int)getScreenWidth {
|
||||
return _renderBufferWidth;
|
||||
}
|
||||
|
||||
- (int)getScreenHeight {
|
||||
return _renderBufferHeight;
|
||||
}
|
||||
|
||||
- (void)setupRenderBuffer {
|
||||
execute_on_main_thread(^{
|
||||
if (!_viewRenderbuffer) {
|
||||
glGenRenderbuffers(1, &_viewRenderbuffer);
|
||||
printOpenGLError();
|
||||
}
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, _viewRenderbuffer);
|
||||
printOpenGLError();
|
||||
if (![_mainContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:(id <EAGLDrawable>) self.layer]) {
|
||||
printError("Failed renderbufferStorage");
|
||||
}
|
||||
// Retrieve the render buffer size. This *should* match the frame size,
|
||||
// i.e. g_fullWidth and g_fullHeight.
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &_renderBufferWidth);
|
||||
printOpenGLError();
|
||||
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_renderBufferHeight);
|
||||
printOpenGLError();
|
||||
});
|
||||
}
|
||||
|
||||
- (void)deleteRenderbuffer {
|
||||
glDeleteRenderbuffers(1, &_viewRenderbuffer);
|
||||
}
|
||||
|
||||
- (void)setupGestureRecognizers {
|
||||
#if TARGET_OS_IOS
|
||||
UILongPressGestureRecognizer *longPressKeyboard = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressKeyboard:)];
|
||||
[_toggleTouchModeButton addGestureRecognizer:longPressKeyboard];
|
||||
[longPressKeyboard setNumberOfTouchesRequired:1];
|
||||
[longPressKeyboard release];
|
||||
|
||||
oneFingerTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerTap:)];
|
||||
[oneFingerTapGesture setNumberOfTapsRequired:1];
|
||||
[oneFingerTapGesture setNumberOfTouchesRequired:1];
|
||||
[oneFingerTapGesture setAllowedTouchTypes:@[@(UITouchTypeDirect),@(UITouchTypePencil)]];
|
||||
[oneFingerTapGesture setDelaysTouchesBegan:NO];
|
||||
[oneFingerTapGesture setDelaysTouchesEnded:NO];
|
||||
|
||||
twoFingerTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerTap:)];
|
||||
[twoFingerTapGesture setNumberOfTapsRequired:1];
|
||||
[twoFingerTapGesture setNumberOfTouchesRequired:2];
|
||||
[twoFingerTapGesture setAllowedTouchTypes:@[@(UITouchTypeDirect)]];
|
||||
[twoFingerTapGesture setDelaysTouchesBegan:NO];
|
||||
[twoFingerTapGesture setDelaysTouchesEnded:NO];
|
||||
|
||||
pencilThreeTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pencilThreeTap:)];
|
||||
[pencilThreeTapGesture setNumberOfTapsRequired:3];
|
||||
[pencilThreeTapGesture setNumberOfTouchesRequired:1];
|
||||
[pencilThreeTapGesture setAllowedTouchTypes:@[@(UITouchTypePencil)]];
|
||||
[pencilThreeTapGesture setDelaysTouchesBegan:NO];
|
||||
[pencilThreeTapGesture setDelaysTouchesEnded:NO];
|
||||
|
||||
// Default long press duration is 0.5 seconds which suits us well
|
||||
oneFingerLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(oneFingerLongPress:)];
|
||||
[oneFingerLongPressGesture setNumberOfTouchesRequired:1];
|
||||
[oneFingerLongPressGesture setAllowedTouchTypes:@[@(UITouchTypeDirect),@(UITouchTypePencil)]];
|
||||
[oneFingerLongPressGesture setDelaysTouchesBegan:NO];
|
||||
[oneFingerLongPressGesture setDelaysTouchesEnded:NO];
|
||||
[oneFingerLongPressGesture setCancelsTouchesInView:NO];
|
||||
[oneFingerLongPressGesture canPreventGestureRecognizer:oneFingerTapGesture];
|
||||
|
||||
twoFingerLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerLongPress:)];
|
||||
[twoFingerLongPressGesture setNumberOfTouchesRequired:2];
|
||||
[twoFingerLongPressGesture setAllowedTouchTypes:@[@(UITouchTypeDirect)]];
|
||||
[twoFingerLongPressGesture setDelaysTouchesBegan:NO];
|
||||
[twoFingerLongPressGesture setDelaysTouchesEnded:NO];
|
||||
[twoFingerLongPressGesture setCancelsTouchesInView:NO];
|
||||
[twoFingerLongPressGesture canPreventGestureRecognizer:twoFingerTapGesture];
|
||||
|
||||
pencilTwoTapLongTouchGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pencilTwoTapLongTouch:)];
|
||||
[pencilTwoTapLongTouchGesture setNumberOfTouchesRequired:1];
|
||||
[pencilTwoTapLongTouchGesture setNumberOfTapsRequired:2];
|
||||
[pencilTwoTapLongTouchGesture setAllowedTouchTypes:@[@(UITouchTypePencil)]];
|
||||
[pencilTwoTapLongTouchGesture setMinimumPressDuration:0.5];
|
||||
[pencilTwoTapLongTouchGesture setDelaysTouchesBegan:NO];
|
||||
[pencilTwoTapLongTouchGesture setDelaysTouchesEnded:NO];
|
||||
[pencilTwoTapLongTouchGesture setCancelsTouchesInView:NO];
|
||||
|
||||
UIPinchGestureRecognizer *pinchKeyboard = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardPinch:)];
|
||||
|
||||
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersSwipeRight:)];
|
||||
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
|
||||
swipeRight.numberOfTouchesRequired = 2;
|
||||
swipeRight.delaysTouchesBegan = NO;
|
||||
swipeRight.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersSwipeLeft:)];
|
||||
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
|
||||
swipeLeft.numberOfTouchesRequired = 2;
|
||||
swipeLeft.delaysTouchesBegan = NO;
|
||||
swipeLeft.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersSwipeUp:)];
|
||||
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
|
||||
swipeUp.numberOfTouchesRequired = 2;
|
||||
swipeUp.delaysTouchesBegan = NO;
|
||||
swipeUp.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersSwipeDown:)];
|
||||
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
|
||||
swipeDown.numberOfTouchesRequired = 2;
|
||||
swipeDown.delaysTouchesBegan = NO;
|
||||
swipeDown.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeRight3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeRight:)];
|
||||
swipeRight3.direction = UISwipeGestureRecognizerDirectionRight;
|
||||
swipeRight3.numberOfTouchesRequired = 3;
|
||||
swipeRight3.delaysTouchesBegan = NO;
|
||||
swipeRight3.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeLeft3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeLeft:)];
|
||||
swipeLeft3.direction = UISwipeGestureRecognizerDirectionLeft;
|
||||
swipeLeft3.numberOfTouchesRequired = 3;
|
||||
swipeLeft3.delaysTouchesBegan = NO;
|
||||
swipeLeft3.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeUp3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeUp:)];
|
||||
swipeUp3.direction = UISwipeGestureRecognizerDirectionUp;
|
||||
swipeUp3.numberOfTouchesRequired = 3;
|
||||
swipeUp3.delaysTouchesBegan = NO;
|
||||
swipeUp3.delaysTouchesEnded = NO;
|
||||
|
||||
UISwipeGestureRecognizer *swipeDown3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeDown:)];
|
||||
swipeDown3.direction = UISwipeGestureRecognizerDirectionDown;
|
||||
swipeDown3.numberOfTouchesRequired = 3;
|
||||
swipeDown3.delaysTouchesBegan = NO;
|
||||
swipeDown3.delaysTouchesEnded = NO;
|
||||
|
||||
UITapGestureRecognizer *doubleTapTwoFingers = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersDoubleTap:)];
|
||||
doubleTapTwoFingers.numberOfTapsRequired = 2;
|
||||
doubleTapTwoFingers.numberOfTouchesRequired = 2;
|
||||
doubleTapTwoFingers.delaysTouchesBegan = NO;
|
||||
doubleTapTwoFingers.delaysTouchesEnded = NO;
|
||||
|
||||
[self addGestureRecognizer:pinchKeyboard];
|
||||
[self addGestureRecognizer:swipeRight];
|
||||
[self addGestureRecognizer:swipeLeft];
|
||||
[self addGestureRecognizer:swipeUp];
|
||||
[self addGestureRecognizer:swipeDown];
|
||||
[self addGestureRecognizer:swipeRight3];
|
||||
[self addGestureRecognizer:swipeLeft3];
|
||||
[self addGestureRecognizer:swipeUp3];
|
||||
[self addGestureRecognizer:swipeDown3];
|
||||
[self addGestureRecognizer:doubleTapTwoFingers];
|
||||
[self addGestureRecognizer:oneFingerTapGesture];
|
||||
[self addGestureRecognizer:twoFingerTapGesture];
|
||||
[self addGestureRecognizer:oneFingerLongPressGesture];
|
||||
[self addGestureRecognizer:twoFingerLongPressGesture];
|
||||
[self addGestureRecognizer:pencilThreeTapGesture];
|
||||
[self addGestureRecognizer:pencilTwoTapLongTouchGesture];
|
||||
|
||||
[pinchKeyboard release];
|
||||
[swipeRight release];
|
||||
[swipeLeft release];
|
||||
[swipeUp release];
|
||||
[swipeDown release];
|
||||
[swipeRight3 release];
|
||||
[swipeLeft3 release];
|
||||
[swipeUp3 release];
|
||||
[swipeDown3 release];
|
||||
[doubleTapTwoFingers release];
|
||||
[oneFingerTapGesture release];
|
||||
[twoFingerTapGesture release];
|
||||
[oneFingerLongPressGesture release];
|
||||
[twoFingerLongPressGesture release];
|
||||
[pencilThreeTapGesture release];
|
||||
[pencilTwoTapLongTouchGesture release];
|
||||
#elif TARGET_OS_TV
|
||||
UITapGestureRecognizer *tapUpGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeUp:)];
|
||||
[tapUpGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeUpArrow)]];
|
||||
|
||||
UITapGestureRecognizer *tapDownGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeDown:)];
|
||||
[tapDownGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeDownArrow)]];
|
||||
|
||||
UITapGestureRecognizer *tapLeftGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeLeft:)];
|
||||
[tapLeftGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeLeftArrow)]];
|
||||
|
||||
UITapGestureRecognizer *tapRightGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(threeFingersSwipeRight:)];
|
||||
[tapRightGestureRecognizer setAllowedPressTypes:@[@(UIPressTypeRightArrow)]];
|
||||
|
||||
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showKeyboard)];
|
||||
[longPressGestureRecognizer setAllowedPressTypes:@[[NSNumber numberWithInteger:UIPressTypePlayPause]]];
|
||||
[longPressGestureRecognizer setMinimumPressDuration:1.0];
|
||||
|
||||
[self addGestureRecognizer:tapUpGestureRecognizer];
|
||||
[self addGestureRecognizer:tapDownGestureRecognizer];
|
||||
[self addGestureRecognizer:tapLeftGestureRecognizer];
|
||||
[self addGestureRecognizer:tapRightGestureRecognizer];
|
||||
[self addGestureRecognizer:longPressGestureRecognizer];
|
||||
|
||||
[tapUpGestureRecognizer release];
|
||||
[tapDownGestureRecognizer release];
|
||||
[tapLeftGestureRecognizer release];
|
||||
[tapRightGestureRecognizer release];
|
||||
[longPressGestureRecognizer release];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(struct CGRect)frame {
|
||||
self = [super initWithFrame: frame];
|
||||
|
||||
_backgroundSaveStateTask = UIBackgroundTaskInvalid;
|
||||
#if TARGET_OS_IOS
|
||||
_currentOrientation = UIInterfaceOrientationUnknown;
|
||||
|
||||
// On-screen control buttons
|
||||
UIImage *menuBtnImage = [UIImage imageNamed:@"ic_action_menu"];
|
||||
_menuButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width - menuBtnImage.size.width, 0, menuBtnImage.size.width, menuBtnImage.size.height)];
|
||||
[_menuButton setImage:menuBtnImage forState:UIControlStateNormal];
|
||||
[_menuButton setAlpha:0.5];
|
||||
[_menuButton addTarget:self action:@selector(handleMainMenuKey) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:_menuButton];
|
||||
|
||||
// The mode will be updated when OSystem has loaded its presets
|
||||
UIImage *toggleTouchModeBtnImage = [UIImage imageNamed:@"ic_action_touchpad"];
|
||||
_toggleTouchModeButton = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width - menuBtnImage.size.width - toggleTouchModeBtnImage.size.width, 0, toggleTouchModeBtnImage.size.width, toggleTouchModeBtnImage.size.height)];
|
||||
[_toggleTouchModeButton setImage:toggleTouchModeBtnImage forState:UIControlStateNormal];
|
||||
[_toggleTouchModeButton setAlpha:0.5];
|
||||
[_toggleTouchModeButton addTarget:self action:@selector(triggerTouchModeChanged) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self addSubview:_toggleTouchModeButton];
|
||||
#endif
|
||||
|
||||
[self setupGestureRecognizers];
|
||||
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
_controllers.push_back([[MouseController alloc] initWithView:self]);
|
||||
_controllers.push_back([[GamepadController alloc] initWithView:self]);
|
||||
}
|
||||
_controllers.push_back([[TouchController alloc] initWithView:self]);
|
||||
|
||||
[self setContentScaleFactor:[[UIScreen mainScreen] scale]];
|
||||
|
||||
_keyboardView = nil;
|
||||
_eventLock = [[NSLock alloc] init];
|
||||
|
||||
// Initialize the OpenGL ES context
|
||||
[self createContext];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)triggerTouchModeChanged {
|
||||
BOOL hwKeyboardConnected = NO;
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, *)) {
|
||||
if (GCKeyboard.coalescedKeyboard != nil) {
|
||||
hwKeyboardConnected = YES;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if ([self isKeyboardShown] && !hwKeyboardConnected) {
|
||||
[self hideKeyboard];
|
||||
} else {
|
||||
[self addEvent:InternalEvent(kInputTouchModeChanged, 0, 0)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTouchMode {
|
||||
UIImage *btnImage;
|
||||
TouchMode currentTouchMode = iOS7_getCurrentTouchMode();
|
||||
bool isEnabled = ConfMan.getBool("onscreen_control");
|
||||
|
||||
if (currentTouchMode == kTouchModeDirect) {
|
||||
btnImage = [UIImage imageNamed:@"ic_action_mouse"];
|
||||
} else if (currentTouchMode == kTouchModeTouchpad) {
|
||||
btnImage = [UIImage imageNamed:@"ic_action_touchpad"];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
[_toggleTouchModeButton setImage: btnImage forState:UIControlStateNormal];
|
||||
|
||||
[_toggleTouchModeButton setEnabled:isEnabled];
|
||||
[_toggleTouchModeButton setHidden:!isEnabled];
|
||||
[_menuButton setEnabled:isEnabled && [self isInGame]];
|
||||
[_menuButton setHidden:!isEnabled || ![self isInGame]];
|
||||
}
|
||||
|
||||
- (BOOL)isiOSAppOnMac {
|
||||
#ifdef __IPHONE_14_0
|
||||
if (@available(iOS 14.0, *)) {
|
||||
return [NSProcessInfo processInfo].isiOSAppOnMac;
|
||||
}
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)dealloc {
|
||||
[_keyboardView release];
|
||||
|
||||
[_eventLock release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)initSurface {
|
||||
[self setupRenderBuffer];
|
||||
|
||||
if (_keyboardView == nil) {
|
||||
_keyboardView = [[SoftKeyboard alloc] initWithFrame:CGRectZero];
|
||||
[_keyboardView setInputDelegate:self];
|
||||
[self addSubview:[_keyboardView inputView]];
|
||||
[self addSubview: _keyboardView];
|
||||
}
|
||||
|
||||
[self adjustViewFrameForSafeArea];
|
||||
#if TARGET_OS_IOS
|
||||
// The virtual controller does not fit in portrait orientation on iPhones
|
||||
// Make sure to disconnect the virtual controller in those cases
|
||||
if (!iOS7_isBigDevice() &&
|
||||
(_currentOrientation == UIInterfaceOrientationPortrait ||
|
||||
_currentOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
|
||||
[self virtualController:false];
|
||||
} else {
|
||||
// Connect or disconnect the virtual controller
|
||||
[self virtualController:ConfMan.getBool("gamepad_controller")];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
-(void)adjustViewFrameForSafeArea {
|
||||
// The code below does not quite compile with SDKs older than 11.0.
|
||||
// warning: instance method '-safeAreaInsets' not found (return type defaults to 'id')
|
||||
// error: no viable conversion from 'id' to 'UIEdgeInsets'
|
||||
// So for now disable this code when compiled with an older SDK, which means it is only
|
||||
// available when running on iOS 11+ if it has been compiled on iOS 11+
|
||||
#ifdef __IPHONE_11_0
|
||||
if ( @available(iOS 11, tvOS 11, *) ) {
|
||||
#if TARGET_OS_IOS
|
||||
UIEdgeInsets inset = [[[UIApplication sharedApplication] keyWindow] safeAreaInsets];
|
||||
// Skip the safe area inset at the bottom.
|
||||
// We want to utilize as much screen area as possible and few
|
||||
// games and launcher elements are put at the very bottom of
|
||||
// the screen.
|
||||
// The insets seem to be expressed in logical coordinate space
|
||||
// (measured in points) while we expect the device coordinate
|
||||
// space (measured in pixels), so we scale it using contentScaleFactor
|
||||
CGFloat scale = [self contentScaleFactor];
|
||||
iOS7_setSafeAreaInsets(inset.left * scale, inset.right * scale, inset.top * scale, 0);
|
||||
|
||||
// Add a margin to the on-screen control buttons. The shape of the iPhone
|
||||
// screen corners on the later models have the shape of squircles rather
|
||||
// than circles which cause button images to become cropped if placed too
|
||||
// close to the corner. iPads have 90 degrees screen corners and does have
|
||||
// the same problem with cropped images. However add the same margin for
|
||||
// consistency.
|
||||
const CGFloat margin = 20;
|
||||
// Touch mode button on top
|
||||
[_toggleTouchModeButton setFrame:CGRectMake(self.frame.size.width - _toggleTouchModeButton.imageView.image.size.width - margin, margin, _toggleTouchModeButton.imageView.image.size.width, _toggleTouchModeButton.imageView.image.size.height)];
|
||||
// Burger menu button below
|
||||
[_menuButton setFrame:CGRectMake(self.frame.size.width - _menuButton.imageView.image.size.width - margin, _toggleTouchModeButton.imageView.image.size.height + margin, _menuButton.imageView.image.size.width, _menuButton.imageView.image.size.height)];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_11_0
|
||||
// This delegate method is called when the safe area of the view changes
|
||||
-(void)safeAreaInsetsDidChange {
|
||||
[super safeAreaInsetsDidChange];
|
||||
|
||||
[self adjustViewFrameForSafeArea];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)addEvent:(InternalEvent)event {
|
||||
[_eventLock lock];
|
||||
_events.push_back(event);
|
||||
[_eventLock unlock];
|
||||
}
|
||||
|
||||
- (bool)fetchEvent:(InternalEvent *)event {
|
||||
[_eventLock lock];
|
||||
if (_events.empty()) {
|
||||
[_eventLock unlock];
|
||||
return false;
|
||||
}
|
||||
|
||||
*event = *_events.begin();
|
||||
_events.pop_front();
|
||||
[_eventLock unlock];
|
||||
return true;
|
||||
}
|
||||
|
||||
- (bool)isGamepadControllerSupported {
|
||||
if (@available(iOS 14.0, tvOS 14.0, *)) {
|
||||
// Both virtual and hardware controllers are supported
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)enableGestures:(BOOL)enabled {
|
||||
[oneFingerTapGesture setEnabled:enabled];
|
||||
[twoFingerTapGesture setEnabled:enabled];
|
||||
[oneFingerLongPressGesture setEnabled:enabled];
|
||||
[twoFingerLongPressGesture setEnabled:enabled];
|
||||
[pencilThreeTapGesture setEnabled:enabled];
|
||||
[pencilTwoTapLongTouchGesture setEnabled:enabled];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)virtualController:(bool)connect {
|
||||
if (@available(iOS 15.0, *)) {
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isKindOfClass:GamepadController.class]) {
|
||||
[(GamepadController*)c virtualController:connect];
|
||||
#if TARGET_OS_IOS
|
||||
if (connect) {
|
||||
[self enableGestures:NO];
|
||||
} else {
|
||||
[self enableGestures:YES];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)interfaceOrientationChanged:(UIInterfaceOrientation)orientation {
|
||||
ScreenOrientation screenOrientation;
|
||||
if (orientation == UIInterfaceOrientationPortrait) {
|
||||
screenOrientation = kScreenOrientationPortrait;
|
||||
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
|
||||
screenOrientation = kScreenOrientationFlippedPortrait;
|
||||
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
|
||||
screenOrientation = kScreenOrientationLandscape;
|
||||
} else { // UIInterfaceOrientationLandscapeLeft
|
||||
screenOrientation = kScreenOrientationFlippedLandscape;
|
||||
}
|
||||
|
||||
// This function is executed also on older device models. The screens
|
||||
// have sharp corners and no safe area insets. Use a constant margin.
|
||||
const CGFloat margin = 10;
|
||||
// Touch mode button on top
|
||||
[_toggleTouchModeButton setFrame:CGRectMake(self.frame.size.width - _toggleTouchModeButton.imageView.image.size.width - margin, margin, _toggleTouchModeButton.imageView.image.size.width, _toggleTouchModeButton.imageView.image.size.height)];
|
||||
// Burger menu button below
|
||||
[_menuButton setFrame:CGRectMake(self.frame.size.width - _menuButton.imageView.image.size.width - margin, _toggleTouchModeButton.imageView.image.size.height + margin, _menuButton.imageView.image.size.width, _menuButton.imageView.image.size.height)];
|
||||
|
||||
[self addEvent:InternalEvent(kInputOrientationChanged, screenOrientation, 0)];
|
||||
if (UIInterfaceOrientationIsLandscape(orientation)) {
|
||||
[self hideKeyboard];
|
||||
} else {
|
||||
// Automatically open the keyboard if changing orientation in a game
|
||||
if ([self isInGame])
|
||||
[self showKeyboard];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)showKeyboard {
|
||||
[_keyboardView showKeyboard];
|
||||
#if TARGET_OS_IOS
|
||||
[_toggleTouchModeButton setImage:[UIImage imageNamed:@"ic_action_keyboard"] forState:UIControlStateNormal];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)hideKeyboard {
|
||||
[_keyboardView hideKeyboard];
|
||||
#if TARGET_OS_IOS
|
||||
[self updateTouchMode];
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL)isKeyboardShown {
|
||||
return [_keyboardView isKeyboardShown];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
#if TARGET_OS_IOS
|
||||
UITouch *touch = [touches anyObject];
|
||||
touchesBegan = [touch locationInView:self];
|
||||
#endif
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isKindOfClass:TouchController.class]) {
|
||||
[(TouchController *)c touchesBegan:touches withEvent:event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
#if TARGET_OS_IOS
|
||||
UITouch *touch = [touches anyObject];
|
||||
CGPoint touchesMoved = [touch locationInView:self];
|
||||
int allowedPencilMovement = 10;
|
||||
switch (touch.type) {
|
||||
// This prevents touches automatically clicking things after
|
||||
// moving around the screen
|
||||
case UITouchTypePencil:
|
||||
// Apple Pencil touches are much more precise, so this
|
||||
// allows some pixels of movement before invalidating the gesture.
|
||||
if (abs(touchesBegan.x - touchesMoved.x) > allowedPencilMovement ||
|
||||
abs(touchesBegan.y - touchesMoved.y) > allowedPencilMovement) {
|
||||
[oneFingerTapGesture setState:UIGestureRecognizerStateCancelled];
|
||||
[pencilThreeTapGesture setState:UIGestureRecognizerStateCancelled];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (touchesBegan.x != touchesMoved.x ||
|
||||
touchesBegan.y != touchesMoved.y) {
|
||||
[oneFingerTapGesture setState:UIGestureRecognizerStateCancelled];
|
||||
[twoFingerTapGesture setState:UIGestureRecognizerStateCancelled];
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isKindOfClass:TouchController.class]) {
|
||||
[(TouchController *)c touchesMoved:touches withEvent:event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isKindOfClass:TouchController.class]) {
|
||||
[(TouchController *)c touchesEnded:touches withEvent:event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (GameController *c : _controllers) {
|
||||
if ([c isKindOfClass:TouchController.class]) {
|
||||
[(TouchController *)c touchesCancelled:touches withEvent:event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_TV
|
||||
// UIKit calls these methods when a button is pressed by the user.
|
||||
// These methods are used to determine which button was pressed and
|
||||
// to take any needed actions. The default implementation of these
|
||||
// methods forwardsm the message up the responder chain.
|
||||
// Button presses are already handled by the GameController class for
|
||||
// connected game controllers (including the Apple TV remote).
|
||||
// The Apple TV remote is not registered as a micro game controller
|
||||
// when running the application in tvOS simulator, hence these methods
|
||||
// only needs to be implemented for the tvOS simulator to handle presses
|
||||
// on the Apple TV remote.
|
||||
-(void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
|
||||
#if TARGET_OS_SIMULATOR
|
||||
UIPress *press = [presses anyObject];
|
||||
if (press.type == UIPressTypeMenu) {
|
||||
// Trigger on pressesEnded
|
||||
} else if (press.type == UIPressTypeSelect || press.type == UIPressTypePlayPause) {
|
||||
[self addEvent:InternalEvent(kInputJoystickButtonDown, press.type == UIPressTypeSelect ? Common::JOYSTICK_BUTTON_A : Common::JOYSTICK_BUTTON_B, 0)];
|
||||
}
|
||||
else {
|
||||
[super pressesBegan:presses withEvent:event];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
|
||||
#if TARGET_OS_SIMULATOR
|
||||
UIPress *press = [presses anyObject];
|
||||
if (press.type == UIPressTypeMenu) {
|
||||
[self handleMainMenuKey];
|
||||
} else if (press.type == UIPressTypeSelect || press.type == UIPressTypePlayPause) {
|
||||
[self addEvent:InternalEvent(kInputJoystickButtonUp, press.type == UIPressTypeSelect ? Common::JOYSTICK_BUTTON_A : Common::JOYSTICK_BUTTON_B, 0)];
|
||||
}
|
||||
else {
|
||||
[super pressesEnded:presses withEvent:event];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
|
||||
#if TARGET_OS_SIMULATOR
|
||||
[super pressesChanged:presses withEvent:event];
|
||||
#endif
|
||||
}
|
||||
|
||||
-(void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
|
||||
#if TARGET_OS_SIMULATOR
|
||||
[super pressesCancelled:presses withEvent:event];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)longPressKeyboard:(UILongPressGestureRecognizer *)recognizer {
|
||||
if (![self isKeyboardShown]) {
|
||||
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
||||
[self showKeyboard];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyboardPinch:(UIPinchGestureRecognizer *)recognizer {
|
||||
if ([recognizer scale] < 0.8)
|
||||
[self showKeyboard];
|
||||
else if ([recognizer scale] > 1.25)
|
||||
[self hideKeyboard];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)oneFingerTap:(UITapGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
[self addEvent:InternalEvent(kInputTap, kUIViewTapSingle, 1)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)twoFingerTap:(UITapGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
[self addEvent:InternalEvent(kInputTap, kUIViewTapSingle, 2)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pencilThreeTap:(UITapGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
// Click right mouse
|
||||
[self addEvent:InternalEvent(kInputTap, kUIViewTapSingle, 2)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)oneFingerLongPress:(UILongPressGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressStarted, 1)];
|
||||
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressEnded, 1)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)twoFingerLongPress:(UILongPressGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressStarted, 2)];
|
||||
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressEnded, 2)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)pencilTwoTapLongTouch:(UITapGestureRecognizer *)recognizer {
|
||||
if (recognizer.state == UIGestureRecognizerStateBegan) {
|
||||
// Hold right mouse
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressStarted, 2)];
|
||||
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
|
||||
// Release right mouse
|
||||
[self addEvent:InternalEvent(kInputLongPress, UIViewLongPressEnded, 2)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)twoFingersSwipeRight:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeRight, 2)];
|
||||
}
|
||||
|
||||
- (void)twoFingersSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeLeft, 2)];
|
||||
}
|
||||
|
||||
- (void)twoFingersSwipeUp:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeUp, 2)];
|
||||
}
|
||||
|
||||
- (void)twoFingersSwipeDown:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeDown, 2)];
|
||||
}
|
||||
|
||||
- (void)threeFingersSwipeRight:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeRight, 3)];
|
||||
}
|
||||
|
||||
- (void)threeFingersSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeLeft, 3)];
|
||||
}
|
||||
|
||||
- (void)threeFingersSwipeUp:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeUp, 3)];
|
||||
}
|
||||
|
||||
- (void)threeFingersSwipeDown:(UISwipeGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputSwipe, kUIViewSwipeDown, 3)];
|
||||
}
|
||||
|
||||
- (void)twoFingersDoubleTap:(UITapGestureRecognizer *)recognizer {
|
||||
[self addEvent:InternalEvent(kInputTap, kUIViewTapDouble, 2)];
|
||||
}
|
||||
|
||||
- (void)handleKeyPress:(unichar)c withModifierFlags:(int)f {
|
||||
if (c == '`') {
|
||||
[self addEvent:InternalEvent(kInputKeyPressed, '\033', f)];
|
||||
} else {
|
||||
[self addEvent:InternalEvent(kInputKeyPressed, c, f)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleMainMenuKey {
|
||||
if ([self isInGame]) {
|
||||
[self addEvent:InternalEvent(kInputMainMenu, 0, 0)];
|
||||
}
|
||||
#if TARGET_OS_TV
|
||||
else {
|
||||
// According to Apple's guidelines the app should return to the
|
||||
// home screen when pressing the menu button from the root view.
|
||||
[[UIApplication sharedApplication] performSelector:@selector(suspend)];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)applicationSuspend {
|
||||
// Make sure to hide the keyboard when suspended. Else the frame
|
||||
// sizing might become incorrect because the NotificationCenter
|
||||
// sends keyboard notifications on resume.
|
||||
[self hideKeyboard];
|
||||
[self addEvent:InternalEvent(kInputApplicationSuspended, 0, 0)];
|
||||
}
|
||||
|
||||
- (void)applicationResume {
|
||||
[self addEvent:InternalEvent(kInputApplicationResumed, 0, 0)];
|
||||
// The device may have changed orientation. Make sure to update
|
||||
// the screen size to the graphic manager.
|
||||
[self addEvent:InternalEvent(kInputScreenChanged, 0, 0)];
|
||||
}
|
||||
|
||||
- (void)saveApplicationState {
|
||||
[self addEvent:InternalEvent(kInputApplicationSaveState, 0, 0)];
|
||||
}
|
||||
|
||||
- (void)clearApplicationState {
|
||||
[self addEvent:InternalEvent(kInputApplicationClearState, 0, 0)];
|
||||
}
|
||||
|
||||
- (void)restoreApplicationState {
|
||||
[self addEvent:InternalEvent(kInputApplicationRestoreState, 0, 0)];
|
||||
}
|
||||
|
||||
- (void) beginBackgroundSaveStateTask {
|
||||
if (_backgroundSaveStateTask == UIBackgroundTaskInvalid) {
|
||||
_backgroundSaveStateTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
||||
[self endBackgroundSaveStateTask];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) endBackgroundSaveStateTask {
|
||||
if (_backgroundSaveStateTask != UIBackgroundTaskInvalid) {
|
||||
[[UIApplication sharedApplication] endBackgroundTask: _backgroundSaveStateTask];
|
||||
_backgroundSaveStateTask = UIBackgroundTaskInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
25
backends/platform/ios7/module.mk
Normal file
25
backends/platform/ios7/module.mk
Normal file
@@ -0,0 +1,25 @@
|
||||
MODULE := backends/platform/ios7
|
||||
|
||||
MODULE_OBJS := \
|
||||
ios7_osys_main.o \
|
||||
ios7_osys_events.o \
|
||||
ios7_osys_sound.o \
|
||||
ios7_osys_video.o \
|
||||
ios7_osys_misc.o \
|
||||
ios7_misc.o \
|
||||
ios7_main.o \
|
||||
ios7_options.o \
|
||||
ios7_video.o \
|
||||
ios7_keyboard.o \
|
||||
ios7_scummvm_view_controller.o \
|
||||
ios7_app_delegate.o \
|
||||
ios7_game_controller.o \
|
||||
ios7_touch_controller.o \
|
||||
ios7_mouse_controller.o \
|
||||
ios7_gamepad_controller.o \
|
||||
ios7_scene_delegate.o
|
||||
|
||||
# We don't use rules.mk but rather manually update OBJS and MODULE_DIRS.
|
||||
MODULE_OBJS := $(addprefix $(MODULE)/, $(MODULE_OBJS))
|
||||
OBJS := $(MODULE_OBJS) $(OBJS)
|
||||
MODULE_DIRS += $(sort $(dir $(MODULE_OBJS)))
|
||||
Reference in New Issue
Block a user