mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 05:38:56 +00:00
iPhone: Updated input event system to firmware 2.x standard
svn-id: r39984
This commit is contained in:
parent
f53b4d3de4
commit
741548cda6
@ -28,7 +28,9 @@ enum InputEvent {
|
||||
kInputMouseDown,
|
||||
kInputMouseUp,
|
||||
kInputMouseDragged,
|
||||
kInputMouseSecondToggled,
|
||||
kInputMouseSecondDragged,
|
||||
kInputMouseSecondDown,
|
||||
kInputMouseSecondUp,
|
||||
kInputOrientationChanged,
|
||||
kInputKeyPressed,
|
||||
kInputApplicationSuspended,
|
||||
|
@ -50,7 +50,6 @@ int main(int argc, char** argv) {
|
||||
[ NSAutoreleasePool alloc ] init
|
||||
];
|
||||
|
||||
UIApplicationUseLegacyEvents(1);
|
||||
int returnCode = UIApplicationMain(argc, argv, @"iPhoneMain", @"iPhoneMain");
|
||||
[ autoreleasePool release ];
|
||||
return returnCode;
|
||||
@ -86,7 +85,9 @@ int main(int argc, char** argv) {
|
||||
_window = [[UIWindow alloc] initWithFrame:rect];
|
||||
[_window retain];
|
||||
|
||||
_view = [[iPhoneView alloc] initWithFrame: rect];
|
||||
_view = [[iPhoneView alloc] initWithFrame: rect];
|
||||
_view.multipleTouchEnabled = YES;
|
||||
|
||||
[_window setContentView: _view];
|
||||
|
||||
//[_window orderFront: self];
|
||||
|
@ -279,109 +279,142 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
];
|
||||
}
|
||||
|
||||
- (void)mouseDown:(struct __GSEvent *)event {
|
||||
//printf("mouseDown()\n");
|
||||
CGPoint point = GSEventGetLocationInWindow(event);
|
||||
point = [self convertPoint:point fromView:nil];
|
||||
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseDown], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
- (void)touchesBegan {
|
||||
//printf("touchesBegan()\n");
|
||||
}
|
||||
|
||||
- (void)mouseUp:(struct __GSEvent *)event {
|
||||
//printf("mouseUp()\n");
|
||||
CGPoint point = GSEventGetLocationInWindow(event);
|
||||
point = [self convertPoint:point fromView:nil];
|
||||
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseUp], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(struct __GSEvent *)event {
|
||||
//printf("mouseDragged()\n");
|
||||
CGPoint point = GSEventGetLocationInWindow(event);
|
||||
point = [self convertPoint:point fromView:nil];
|
||||
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseDragged], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(struct __GSEvent *)event {
|
||||
//printf("mouseEntered()\n");
|
||||
CGPoint point = GSEventGetLocationInWindow(event);
|
||||
point = [self convertPoint:point fromView:nil];
|
||||
|
||||
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseSecondToggled], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
- (void)mouseExited:(struct __GSEvent *)event {
|
||||
//printf("mouseExited().\n");
|
||||
// [self addEvent:
|
||||
// [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
// @"mouseExited", @"type",
|
||||
// nil
|
||||
// ]
|
||||
// ];
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(struct __GSEvent *)event
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
//printf("mouseMoved()\n");
|
||||
// struct CGPoint point = GSEventGetLocationInWindow(event);
|
||||
//
|
||||
// if (!getLocalMouseCoords(&point))
|
||||
// return;
|
||||
//
|
||||
// [self addEvent:
|
||||
// [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
// [NSNumber numberWithInt:kInputMouseSecondToggled], @"type",
|
||||
// [NSNumber numberWithFloat:point.x], @"x",
|
||||
// [NSNumber numberWithFloat:point.y], @"y",
|
||||
// nil
|
||||
// ]
|
||||
// ];
|
||||
NSSet *allTouches = [event allTouches];
|
||||
|
||||
switch ([allTouches count]) {
|
||||
case 1:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseDown], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseSecondDown], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSSet *allTouches = [event allTouches];
|
||||
|
||||
switch ([allTouches count]) {
|
||||
case 1:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseDragged], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseSecondDragged], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
NSSet *allTouches = [event allTouches];
|
||||
|
||||
switch ([allTouches count]) {
|
||||
case 1:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseUp], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
UITouch *touch = [[allTouches allObjects] objectAtIndex:1];
|
||||
CGPoint point = [touch locationInView:self];
|
||||
//point = [self convertPoint:point fromView:nil];
|
||||
if (!getLocalMouseCoords(&point))
|
||||
return;
|
||||
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:kInputMouseSecondUp], @"type",
|
||||
[NSNumber numberWithFloat:point.x], @"x",
|
||||
[NSNumber numberWithFloat:point.y], @"y",
|
||||
nil
|
||||
]
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)handleKeyPress:(unichar)c {
|
||||
@ -412,10 +445,6 @@ bool getLocalMouseCoords(CGPoint *point) {
|
||||
];
|
||||
}
|
||||
|
||||
- (void)view:(UIView *)view handleTapWithCount:(int)count event:(struct __GSEvent *)event fingerCount:(int)fingerCount{
|
||||
//printf("handleTapWithCount(%i, %i)\n", count, fingerCount);
|
||||
}
|
||||
|
||||
- (void)applicationSuspend {
|
||||
[self addEvent:
|
||||
[[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
|
@ -731,20 +731,21 @@ bool OSystem_IPHONE::pollEvent(Common::Event &event) {
|
||||
case kInputMouseDragged:
|
||||
if (!handleEvent_mouseDragged(event, x, y))
|
||||
return false;
|
||||
break;
|
||||
case kInputMouseSecondDragged:
|
||||
if (!handleEvent_mouseSecondDragged(event, x, y))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputMouseSecondToggled:
|
||||
_secondaryTapped = !_secondaryTapped;
|
||||
//printf("Mouse second at (%u, %u). State now %s.\n", x, y, _secondaryTapped ? "on" : "off");
|
||||
if (_secondaryTapped) {
|
||||
if (!handleEvent_secondMouseDown(event, x, y))
|
||||
return false;
|
||||
} else {
|
||||
if (!handleEvent_secondMouseUp(event, x, y))
|
||||
return false;
|
||||
}
|
||||
case kInputMouseSecondDown:
|
||||
_secondaryTapped = true;
|
||||
if (!handleEvent_secondMouseDown(event, x, y))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case kInputMouseSecondUp:
|
||||
_secondaryTapped = false;
|
||||
if (!handleEvent_secondMouseUp(event, x, y))
|
||||
return false;
|
||||
break;
|
||||
case kInputOrientationChanged:
|
||||
handleEvent_orientationChanged((int)xUnit);
|
||||
return false;
|
||||
@ -894,101 +895,102 @@ bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y
|
||||
_lastDragPosY = y;
|
||||
|
||||
//printf("Mouse dragged at (%u, %u)\n", x, y);
|
||||
if (_secondaryTapped) {
|
||||
if (_gestureStartX == -1 || _gestureStartY == -1) {
|
||||
return false;
|
||||
}
|
||||
int mouseNewPosX;
|
||||
int mouseNewPosY;
|
||||
if (_touchpadModeEnabled ) {
|
||||
int deltaX = _lastPadX - x;
|
||||
int deltaY = _lastPadY - y;
|
||||
_lastPadX = x;
|
||||
_lastPadY = y;
|
||||
|
||||
mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
|
||||
mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
|
||||
|
||||
if (mouseNewPosX < 0)
|
||||
mouseNewPosX = 0;
|
||||
else if (mouseNewPosX > _screenWidth)
|
||||
mouseNewPosX = _screenWidth;
|
||||
|
||||
if (mouseNewPosY < 0)
|
||||
mouseNewPosY = 0;
|
||||
else if (mouseNewPosY > _screenHeight)
|
||||
mouseNewPosY = _screenHeight;
|
||||
|
||||
} else {
|
||||
mouseNewPosX = x;
|
||||
mouseNewPosY = y;
|
||||
}
|
||||
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
event.mouse.x = mouseNewPosX;
|
||||
event.mouse.y = mouseNewPosY;
|
||||
warpMouse(mouseNewPosX, mouseNewPosY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int vecX = (x - _gestureStartX);
|
||||
int vecY = (y - _gestureStartY);
|
||||
int lengthSq = vecX * vecX + vecY * vecY;
|
||||
//printf("Lengthsq: %u\n", lengthSq);
|
||||
|
||||
if (lengthSq > 15000) { // Long enough gesture to react upon.
|
||||
_gestureStartX = -1;
|
||||
_gestureStartY = -1;
|
||||
|
||||
float vecLength = sqrt(lengthSq);
|
||||
float vecXNorm = vecX / vecLength;
|
||||
float vecYNorm = vecY / vecLength;
|
||||
|
||||
//printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
|
||||
|
||||
if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
|
||||
// Swipe down
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
_queuedInputEvent.type = Common::EVENT_KEYUP;
|
||||
|
||||
event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
|
||||
event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
|
||||
_needEventRestPeriod = true;
|
||||
} else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
|
||||
// Swipe up
|
||||
_mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
|
||||
const char *dialogMsg;
|
||||
if (_mouseClickAndDragEnabled) {
|
||||
_touchpadModeEnabled = false;
|
||||
dialogMsg = "Mouse-click-and-drag mode enabled.";
|
||||
} else
|
||||
dialogMsg = "Mouse-click-and-drag mode disabled.";
|
||||
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
|
||||
} else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
|
||||
// Swipe right
|
||||
_touchpadModeEnabled = !_touchpadModeEnabled;
|
||||
const char *dialogMsg;
|
||||
if (_touchpadModeEnabled)
|
||||
dialogMsg = "Touchpad mode enabled.";
|
||||
else
|
||||
dialogMsg = "Touchpad mode disabled.";
|
||||
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
|
||||
} else if (vecXNorm < -0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
|
||||
// Swipe left
|
||||
return false;
|
||||
bool OSystem_IPHONE::handleEvent_mouseSecondDragged(Common::Event &event, int x, int y) {
|
||||
if (_gestureStartX == -1 || _gestureStartY == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int vecX = (x - _gestureStartX);
|
||||
int vecY = (y - _gestureStartY);
|
||||
int lengthSq = vecX * vecX + vecY * vecY;
|
||||
//printf("Lengthsq: %u\n", lengthSq);
|
||||
|
||||
if (lengthSq > 15000) { // Long enough gesture to react upon.
|
||||
_gestureStartX = -1;
|
||||
_gestureStartY = -1;
|
||||
|
||||
float vecLength = sqrt(lengthSq);
|
||||
float vecXNorm = vecX / vecLength;
|
||||
float vecYNorm = vecY / vecLength;
|
||||
|
||||
//printf("Swipe vector: (%.2f, %.2f)\n", vecXNorm, vecYNorm);
|
||||
|
||||
if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm > 0.75) {
|
||||
// Swipe down
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
_queuedInputEvent.type = Common::EVENT_KEYUP;
|
||||
|
||||
event.kbd.flags = _queuedInputEvent.kbd.flags = 0;
|
||||
event.kbd.keycode = _queuedInputEvent.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = _queuedInputEvent.kbd.ascii = Common::ASCII_F5;
|
||||
_needEventRestPeriod = true;
|
||||
} else if (vecXNorm > -0.50 && vecXNorm < 0.50 && vecYNorm < -0.75) {
|
||||
// Swipe up
|
||||
_mouseClickAndDragEnabled = !_mouseClickAndDragEnabled;
|
||||
const char *dialogMsg;
|
||||
if (_mouseClickAndDragEnabled) {
|
||||
_touchpadModeEnabled = false;
|
||||
dialogMsg = "Mouse-click-and-drag mode enabled.";
|
||||
} else
|
||||
return false;
|
||||
dialogMsg = "Mouse-click-and-drag mode disabled.";
|
||||
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
|
||||
} else if (vecXNorm > 0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
|
||||
// Swipe right
|
||||
_touchpadModeEnabled = !_touchpadModeEnabled;
|
||||
const char *dialogMsg;
|
||||
if (_touchpadModeEnabled)
|
||||
dialogMsg = "Touchpad mode enabled.";
|
||||
else
|
||||
dialogMsg = "Touchpad mode disabled.";
|
||||
GUI::TimedMessageDialog dialog(dialogMsg, 1500);
|
||||
dialog.runModal();
|
||||
return false;
|
||||
|
||||
} else if (vecXNorm < -0.75 && vecYNorm > -0.5 && vecYNorm < 0.5) {
|
||||
// Swipe left
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
} else {
|
||||
int mouseNewPosX;
|
||||
int mouseNewPosY;
|
||||
if (_touchpadModeEnabled ) {
|
||||
int deltaX = _lastPadX - x;
|
||||
int deltaY = _lastPadY - y;
|
||||
_lastPadX = x;
|
||||
_lastPadY = y;
|
||||
|
||||
mouseNewPosX = (int)(_mouseX - deltaX / 0.5f);
|
||||
mouseNewPosY = (int)(_mouseY - deltaY / 0.5f);
|
||||
|
||||
if (mouseNewPosX < 0)
|
||||
mouseNewPosX = 0;
|
||||
else if (mouseNewPosX > _screenWidth)
|
||||
mouseNewPosX = _screenWidth;
|
||||
|
||||
if (mouseNewPosY < 0)
|
||||
mouseNewPosY = 0;
|
||||
else if (mouseNewPosY > _screenHeight)
|
||||
mouseNewPosY = _screenHeight;
|
||||
|
||||
} else {
|
||||
mouseNewPosX = x;
|
||||
mouseNewPosY = y;
|
||||
}
|
||||
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
event.mouse.x = mouseNewPosX;
|
||||
event.mouse.y = mouseNewPosY;
|
||||
warpMouse(mouseNewPosX, mouseNewPosY);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) {
|
||||
|
@ -207,4 +207,5 @@ protected:
|
||||
bool handleEvent_secondMouseUp(Common::Event &event, int x, int y);
|
||||
|
||||
bool handleEvent_mouseDragged(Common::Event &event, int x, int y);
|
||||
bool handleEvent_mouseSecondDragged(Common::Event &event, int x, int y);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user