mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-01 14:21:41 +00:00
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.
This commit is contained in:
parent
568b06940e
commit
72518221d8
@ -29,6 +29,7 @@
|
||||
@implementation MouseController {
|
||||
#ifdef __IPHONE_14_0
|
||||
GCMouse *_mouse;
|
||||
CGFloat _dxReminder, _dyReminder;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -45,6 +46,9 @@
|
||||
object:nil];
|
||||
}
|
||||
|
||||
_dxReminder = 0.0;
|
||||
_dyReminder = 0.0;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -54,7 +58,18 @@
|
||||
_mouse = (GCMouse*)notification.object;
|
||||
|
||||
_mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float deltaX, float deltaY) {
|
||||
[[self view] addEvent:InternalEvent(kInputMouseDelta, (int)-deltaX, (int)deltaY)];
|
||||
CGFloat scaleX, scaleY;
|
||||
[[self view] getMouseScaleFactorX:&scaleX andY:&scaleY];
|
||||
CGFloat scaledDeltaX = deltaX * scaleX + _dxReminder;
|
||||
CGFloat scaledDeltaY = deltaY * scaleY + _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) {
|
||||
|
@ -139,6 +139,7 @@ uint getSizeNextPOT(uint size);
|
||||
- (void)addEvent:(InternalEvent)event;
|
||||
- (bool)fetchEvent:(InternalEvent *)event;
|
||||
|
||||
- (void)getMouseScaleFactorX:(CGFloat *)x andY:(CGFloat *)y;
|
||||
- (bool)getMouseCoords:(CGPoint)point eventX:(int *)x eventY:(int *)y;
|
||||
- (BOOL)isTouchControllerConnected;
|
||||
- (BOOL)isMouseControllerConnected;
|
||||
|
@ -866,6 +866,17 @@ uint getSizeNextPOT(uint size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
- (void)getMouseScaleFactorX:(CGFloat *)x andY:(CGFloat *)y {
|
||||
if (_videoContext.overlayInGUI) {
|
||||
// No scaling in overlay
|
||||
*x = (CGFloat)_videoContext.overlayWidth / self.bounds.size.width;
|
||||
*y = (CGFloat)_videoContext.overlayHeight / self.bounds.size.height;
|
||||
} else {
|
||||
*x = (CGFloat)_videoContext.screenWidth / self.bounds.size.width;
|
||||
*y = (CGFloat)_videoContext.screenHeight / self.bounds.size.height;
|
||||
}
|
||||
}
|
||||
|
||||
- (bool)getMouseCoords:(CGPoint)point eventX:(int *)x eventY:(int *)y {
|
||||
// We scale the input according to our scale factor to get actual screen
|
||||
// coordinates.
|
||||
|
Loading…
x
Reference in New Issue
Block a user