Commit graph

204 commits

Author SHA1 Message Date
Thierry Crozat
481f849c5a IOS7: Fix hiding keyboard in portrait mode when not in game 2023-07-04 23:14:49 +01:00
Lars Sundström
06e231a649 IOS7: Show keyboard automatically when in game and portrait mode
Open the iOS system keyboard automatically when starting a game and
screen orientation is portrait. If orientation changes to portrait,
open the keyboard automatically only if game is running.
2023-07-03 21:50:32 +02:00
Lars Sundström
3ee048d922 IOS7: Update logic for touch events for Apple TV remote
The Apple TV remote sends touch events of type UITouchTypeIndirect
since it's not touches made on the screen. In iOS touchpads might
send UITouchTypeIndirect touch events as well as mouse move events.

So in iOS we want to block touches of type UITouchTypeIndirect
while in TV OS we want them to be handled.

Touchpad mode for touch events is also required for the Apple TV
remote to work properly. Make sure to disable the possibility to
disable touchpad mode in TV OS.
2023-07-03 21:50:32 +02:00
Lars Sundström
d8bc349b37 IOS7: Resize main frame depending on keyboard size and orientation
It's important that the main frame, displaying the OpenGL rendered
graphics, has the proper dimensions and depending on the device
orientation. It's also important that the frame is not covered by
the iOS keyboard.

This commit calculates the frame size depening on the orientation
and the keyboard status. The keyboard knows its parent view and
can resize it when the keyboard becomes visible or hidden.

There are multiple scenarios where the frame size is changed.
 - When the keyboard is hidden/shown which can be automatically
   change depending on the device orientation
 - If the system demands the keyboard to get visible or hidden
 - When rotating the device
 - When suspending/resuming the application

There can also be combination of the scenarios above, e.g. if
suspending the application in landscape mode and resume it in
portrait mode.

A lot of effort has been put into testing different scenarios to
verify that the screen size becomes correct. However there might
be some scenario which has not been covered.
2023-07-03 21:50:32 +02:00
Lars Sundström
5d5564fceb IOS7: Hide word suggestion list in newer iOS versions
Since iOS 15 or 16 both auto correction and spelling check have to
be disabled to hide the word suggestion list above the keyboard.
2023-07-03 21:50:32 +02:00
Lars Sundström
598bc231ab IOS7: Cancel pending button if touch is moved within 250 ms
If not in "click-and-drag" mode, left mouse button down and up
events are sent on touches ended if the touch lasted less than
250 ms. If the touch lasted longer it was considered as a move
and no button events are sent.

This commit mimic that behaviour in touchpad mode when "click-
and-drag" mode is enabled. The left mouse button down event is
queued for 250 ms. If the touch is dragged within 250 ms it is
considered as a move and the queued mouse button down event is
cacelled. If no movement is made withing 250 ms the queued
mouse button event is processed.
2023-07-03 21:50:32 +02:00
Lars Sundström
b324c70748 IOS7: Implement switching of 2D/3D graphics managers
Implement the same "hacky" way to switch between the 2D and 3D
iOSGraphicsManagers as the Android and SDL backends.

This commit enables 3D capable games to utilise the horse powers
in the GPU to render graohic. Older iPhones and iPads (iPhone 6,
iPad Mini v1) are able to run quite advanced games without any
stuttering if run in Release mode.
2023-07-03 21:50:32 +02:00
Lars Sundström
fb4f7d6de2 IOS7: Remove old IOS7 graphic handling
Delete the old graphic handling in the IOS7 backend which is not
used anymore after implementing iOSGraphicsManager.

The Accelerate framework is not used anymore. The OpenGLGraphics
manager handles the different color formats.
2023-07-03 21:50:32 +02:00
Lars Sundström
d36074773b IOS7: Add internal event for signalling screen changes
When the screen dimension changes, e.g. on rotation of the device,
the graphic manager has to be informed of the new dimension to be
able to resize the surfaces.

To quickly redraw the entire screen, Common::EVENT_SCREEN_CHANGED
event is passed to the event handler.
2023-07-03 21:50:32 +02:00
Lars Sundström
e0ae1a1d47 IOS7: Rework mouse movements to use iOSGraphicsManager
Previously the mouse position in the view was tracked using the
pointerPosition property. Scaling and relative mosue movements
were calculated in the view using screen properties stored in the
videoContext structure. Now when moving to iOSGraphicsManager all
that handling will be handled by the WindowedGraphicsManager,
which the iOSGraphicsManager inherit.

Rework the input code to send down pure x and y position values,
scaled according to the view content scale factor.

Remove code related to mouse movement that is no longer needed.
2023-07-03 21:50:32 +02:00
Lars Sundström
208aa43d5b IOS7: Render openGLContext
Implement callbacks to set up OpenGL context, destroy context, get
scale factor and screen sizes. Implement rendering of graphics drawn
by the iOS graphicsManager.

This commit will enable graphics to be shown again. Screen rotation
and mouse movements are still to be adapted.
2023-07-03 21:50:32 +02:00
Lars Sundström
580d8424ca IOS7: Change OSystem_iOS7 to be a ModularGraphicsBackend
Remove all pure virtual functions in OSystem_iOS7 since they are
implemented by ModularGraphicsBackend.

This commit will break the graphics implementation in the ios7
backend and crash due to no OpenGL context created for the
graphicsManager to use.
2023-07-03 21:50:32 +02:00
Lars Sundström
e6232547d5 IOS7: Add iOSGraphicsManager class
The ios7 backend implements the graphic handling in the backend code.
iOS supports OpenGL through the OpenGL Framework since iOS 2.0. It's
marked as deprecated but is still shipped with the SDKs for iPhoneOS
and tvOS and will hopefully be so for some time.
The ios7 backend can therefore utilize the OpenGLGraphicsManager to
handle all graphics.

Implement an iOSGraphicsManager class that can be used in the ios7
backend. The iOSGraphicsManager will require some callback functions
in the ios7 backend. createOpenGLContext() will be called to ask the
backend to create an OpenGL context in which the graphic manager can
draw. The function returns the ID of the renderbuffer which shall be
used when creating the framebuffer object this differ iOS from other
platforms). A custom RenderBufferTarget class is added to address
this.

destroyOpenGLContext() will be called to make sure that the old GLES
context is not reused. notifyContextDestroy() does call the function
OpenGLContext.reset() but that will not destroy the context.

refreshScreen() will be called to ask the backend to present the
drawn graphics on the screen. getSystemHiDPIScreenFactor() is called
to get the screen scaling factor. getScreenWidth() and
getScreenHeight() are called to get the width and height of the
surface to draw on.

This commit adds the class but the ios7 backend doesn't make use of
it quite yet. To use it require the ios7 to be a child class of the
ModularGraphicsBackend. That change requires a lot of changes which
will be targeted in separate commits.

Update docportal and github ci worker to only disable the feature
opengl_classic_game since opengl and opengl_shaders are required to
compile the OpenGLGraphicsManager.
2023-07-03 21:50:32 +02:00
Thierry Crozat
13d449e553 IOS7: Add GUI option to show/hide the keyboard accessory bar 2023-06-25 21:49:33 +01:00
Lars Sundström
8e97e8dff4 IOS7: Refactor touchpad mode to utilize delta mouse function
Instead of having duplicated code, utilize the delta mouse function
also for touches when in touchpad mode.
2023-05-15 12:43:39 +02:00
Lars Sundström
01b9f728de IOS7: Implement relative mouse movements for touches
Send relative mouse movements from backend for touch events. The
relative x and y values are necessary for some games, e.g. Myst3.
2023-05-15 12:43:39 +02:00
Lars Sundström
d397938107 IOS7: Implement support for setting mouse pointer speed
Implement support to set the mouse pointer speed in settings.
The mouse pointer speed is applied to both mouse input and touch
input when in touchpad-mode.
2023-05-15 12:43:39 +02:00
Lars Sundström
72518221d8 IOS7: Scale mouse movements
The delta values are in number of pixels on the native screen
resolution. Need to scale down the delta values based on the
game resolution. Store reminders that are added to next deltas
to mitigate "dead zones" if doing small movements.
2023-05-15 12:43:39 +02:00
Lars Sundström
568b06940e IOS7: Add mouse input events
Add input events that can be used by mouse devices, e.g. mices and
touchpads. This event sends the raw input actions and doesn't care
about different controller modes such as click-and-drag.

Make the mouse controller utilize the new mouse input events.
2023-05-15 12:43:39 +02:00
Lars Sundström
5a0eccf337 IOS7: Rename mouse events to touch events
The current mouse events are handling events created from both touch
and mouse input. The events have lots of logic to deal with gestures
and different modes (touchpad mode, click-and-drag etc) which are not
applicable for hardware inputs.

Rename the current "mouse events" to "touch events" to clarify which
input that triggered an event. As this is the first commit in multi-
commit change, the mouse input need to use the "touch events" until
a new "mouse event" is implemented.
2023-05-15 12:43:39 +02:00
Lars Sundström
4de20a8032 IOS7: Adjust the frame on safeAreaInsetsDidChange calls
There is a race condition when iOS updates the safe insets and
the view is updated on orientation changes. When rotating the
device the callback function interfaceOrientationChanged is
called. This triggers rebuildSurface to be called, which will
call updateOutputSurface, which will trigger initSurface. That
function will finally will adjust the main frame towards the
safe areas by calling the function adjustViewFrameForSafeArea.

But it seems that when adjustViewFrameForSafeArea is called the
safe insets values are not updated which will lead to wrong
offset values in the frame for touches which will make the mouse
pointer inaccurate.

The iOS system makes calls to safeAreaInsetsDidChange whenever
the safe insets values are updated. Make sure to update the frame
on these calls to get correct touch offsets.
2023-05-09 14:33:56 +02:00
Lars Sundström
5817e72d0d IOS7: Implement Apple GCVirtualController
Apple introduced the GCVirtualController in iOS 15 which is a
software emulation of a real controller. The virtual controllers
can be configurable with different inputs. See more info at:
https://developer.apple.com/documentation/gamecontroller/gcvirtualcontroller

A simple gamepad configuration with a dPad and A and B buttons
is added. The user can enable/disable the virtual game controller
swiping two fingers right to left, or through the port-specific
option dialog.
2023-05-05 22:35:03 +02:00
Lars Sundström
045ddca927 IOS7: Add dpad actions to gamepad controller
Some game engines requires the dpad to control a character. The GRIM
engine is an example of this where the user steer the character by
the arrow keys or dpad controller.
2023-05-05 22:35:03 +02:00
Lars Sundström
fac7008914 IOS7: Call correct delegate method
The wrong delegate method was called for touchesCancelled. This
led to button presses ended too early if moving the fingers.
2023-05-05 22:35:03 +02:00
Lars Sundström
6d325f26c6 IOS7: Write changes to mouse modes to ConfMan
When changing "Touchpad mode" or "Mouse-click-and-drag mode" by
swipe gestures, these changes must be stored in ConfMan.
2023-05-05 22:35:03 +02:00
Lars Sundström
7861bca156 IOS7: Don't disable "touchpad" mode when enabling "click-and-drag"
The "touchpad" mode and "click-and-drag" mode was mutual exclusive
when enabling "click-and-drag" using swipe gesture.

The difference between "touchpad" mode and "click-and-drag" mode
is how the button down/up events are sent. In touchpad mode the
button down and button up events are sent on touches ended, while
in click-and-drag the button down event is sent on touches began
and button up on touches ended.
2023-05-05 22:35:03 +02:00
Lars Sundström
a690552301 IOS7: Remove legacy gesture recognizers
These gesture recognizers were inherited from the iphone port. The
ios7 port use the UIGestureRecognizers to accomplish the same.
2023-05-05 22:35:03 +02:00
Lars Sundström
9bc623a8a4 IOS7: Implement port-specifc option widget
Include the newly added ios7_options implementation to the project.
Change the file type to .mm which is Objective C++ to be able to use
the @availble mechanism.

Implement virtual functions and fix build errors in initial code.
Also add help section for the tvOS port when building for tvOS.

Add ios7_options to POTFILES to get automatic translation on the
help section.
2023-05-05 22:35:03 +02:00
Thierry Crozat
0b92f048dc IOS: Add back new delegate methods but keep old ones
On iOS 12 and below, the one delegate methods are called. On iOS13.2
and above if both sets are implemented only the new delegate methods
are called, which prevent getting the deprecation warning.
2023-05-03 21:35:17 +01:00
Thierry Crozat
d2554266b3 Revert "IOS7: Implement new delegate methods replacing deprecated ones"
This reverts commit 46d6a76b8e.
The commit broke saving and restoring state when compiling with SDK 13
or above and running on iOS 12 or below. The functions to save/restore
were no longer called.
2023-05-03 01:54:22 +01:00
Eugene Sandulenko
d362dc924e
BACKENDS: IOS7: Add inital code for port-specifc options 2023-05-02 11:13:02 +02:00
Lars Sundström
46d6a76b8e IOS7: Implement new delegate methods replacing deprecated ones
The delegate methods application:shouldRestoreApplicationState
is replaced with application:shouldRestoreSecureApplicationState
and the method application:shouldSaveApplicationState with
application:shouldSaveSecureApplicationState.

To support older versions of iOS, put them in a version check
macro.
2023-05-02 08:02:12 +02:00
Lars Sundström
50b67d97c4 IOS7: Implement use of Timer Dispatch Sources to drive timeHandler
The timeHandler was driven by calls to the pollEvent callback function.
Each time pollEvent was called the timeHandler called the TimeManager
handle function to advance in time and make sure scheduled tasks were
triggered.

This worked good for most game engines but some, e.g. the Hypno engine
was using the TimeManager to schedule tasks without calling pollEvent
since it was expecting nor handling events at the specific point in
time.

Since iOS have threads the timerHandler can be called from a separate
thread and not rely on pollEvent.
Implement timerHandler to use a Timer Dispatch Source which and make
it operate on a background thread rather than the main thread.
Read more on Dispatch Sources here:
https://developer.apple.com/library/archive/documentation/General/
Conceptual/ConcurrencyProgrammingGuide/GCDWorkQueues/GCDWorkQueues.html
2023-05-02 08:02:12 +02:00
Thierry Crozat
59c6d6fe4b IOS7: Add check of size for log file to make sure it does not grow too much 2023-04-27 01:24:30 +01:00
Thierry Crozat
c9b8bf2ca1 IOS7: Fix orientation detection when the view becomes visible 2023-04-27 01:24:30 +01:00
Thierry Crozat
e8d87fb92a IOS7: Create log file in Document folder
Previously no log file was used as it attempted to create it in
a directory not accessible by the application. The commit also fixes
accessing the log file from the Options dialog (it needs the
sandboxed path and not the full path).
2023-04-27 01:24:30 +01:00
Thierry Crozat
a36dba4db9 IOS7: Cleanup code to access Document and app bundle paths 2023-04-27 01:24:30 +01:00
Thierry Crozat
a0e32ee370 IOS7: Remove support for non-sandboxed mode 2023-04-26 22:31:31 +01:00
Thierry Crozat
4413600f2a IOS7: Fix missing override keyword 2023-04-26 08:29:59 +02:00
Thierry Crozat
788411b5fe IOS7: Remove checks that @available can be used
This was used in the past to make sure the code can be compiled
with old compilers that do not support using @available. But we
already dropped support for those old compilers, and in many
places already used @available without checking first that it can
be used.
2023-04-26 08:29:59 +02:00
Thierry Crozat
924d9e63e0 IOS7: Fix detection of orientation on some devices
The main change in to use the interface orientation and not the device
orientation. This may be different for example when locking the orientation.
This also changes the way orientation changes are detected using the
documented method. However this means dropping support for iOS 7 as this
method is only available since iOS 8, and alternative methods available in
iOS 7 have been deprecated in iOS 13.

Another change is to properly detect the interface orientation instead of
infering it from the view bounds, which was incorrect on some devices.
2023-04-26 08:29:59 +02:00
Eugene Sandulenko
986076bb13
IOS7: Report the scummvm.log file location 2023-03-27 00:24:46 +02:00
Thierry Crozat
308c409a87 IOS7: Fix detecting and running games directly in bundle 2023-03-24 21:11:50 +01:00
Thierry Crozat
cbd2b736df BACKENDS: Add possibility to specify virtual drive in ChRootFilesystemFactory
It allows to get access to additional directories outside of the sandbox root.
This is used on iOS to access files in the app bundle.
2023-03-24 21:11:50 +01:00
Thierry Crozat
4dff8f6220 IOS7: Support detecting, adding, and starting games from bundle 2023-03-24 21:11:50 +01:00
elasota
607e49756c BACKENDS: IOS7: Enable log message for unsupported cursor masks 2023-02-19 23:51:09 +01:00
elasota
3db67a33ac GRAPHICS: Add support for pixels with masks and inverted pixels 2023-02-19 23:51:09 +01:00
Lars Sundström
4dc9c876fd IOS7: Add support for 32 bit pixel formats
This enables some game engines only supporting 32 bit color formats,
e.g. 11th hour and Broken Sword 2.5.

Add support for the pixel formats RGBA8888 and ABGR8888. The pixel
formats are defined in big endian while iOS utilizes little endian,
thus requiring converting some formats to get correct color
representation.

Use the Apple Accelerate framework converting the format requiring
to minimize the CPU load since this is done every frame.
2023-02-09 22:52:11 +01:00
Lars Sundström
235ebcbfb8 IOS7: Fix compiler warnings
This commit fixes the compiler warnings regarding:
- The local declaration of 'view' hides instance variable [-Wshadow-ivar]
- Some of the gamepad controller buttons is only available in specific
versions of iOS and tvOS.
- Use of non-standard escape character '\E'. \E is a GNU shortcut.
2023-01-29 21:13:52 +00:00
Lars Sundström
fde0aa965d IOS7: Add general handling of the menu button on game controllers
Expose the handleMainMenuKey function and call that when pressing the
menu button on game controllers.
2023-01-29 21:13:52 +00:00