mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-27 06:32:59 +00:00
touches to the on screen controls are no longer sent as mouse clicks/movement
This commit is contained in:
parent
cb93486bb0
commit
ece113787d
@ -17,9 +17,9 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
|
||||
};
|
||||
|
||||
- (id) initWithView:(UIView*)view;
|
||||
- (void) handleTouchDownEvent:(UIEvent*)event;
|
||||
- (void) handleTouchUpEvent:(UIEvent*) event;
|
||||
- (void) handleTouchMovedEvent:(UIEvent*)event;
|
||||
- (BOOL) handleTouchDownEvent:(UIEvent*)event;
|
||||
- (BOOL) handleTouchUpEvent:(UIEvent*) event;
|
||||
- (BOOL) handleTouchMovedEvent:(UIEvent*)event;
|
||||
- (void) setLevel:(OnScreenControlsLevel)level;
|
||||
|
||||
@end
|
||||
|
@ -37,8 +37,22 @@
|
||||
short rightStickX, rightStickY;
|
||||
char leftTrigger, rightTrigger;
|
||||
|
||||
UITouch* _aTouch;
|
||||
UITouch* _bTouch;
|
||||
UITouch* _xTouch;
|
||||
UITouch* _yTouch;
|
||||
UITouch* _upTouch;
|
||||
UITouch* _downTouch;
|
||||
UITouch* _leftTouch;
|
||||
UITouch* _rightTouch;
|
||||
UITouch* _lsTouch;
|
||||
UITouch* _rsTouch;
|
||||
UITouch* _startTouch;
|
||||
UITouch* _selectTouch;
|
||||
UITouch* _r1Touch;
|
||||
UITouch* _r2Touch;
|
||||
UITouch* _l1Touch;
|
||||
UITouch* _l2Touch;
|
||||
|
||||
UIView* _view;
|
||||
OnScreenControlsLevel _level;
|
||||
@ -299,7 +313,9 @@ static float L2_Y;
|
||||
[_rightStick removeFromSuperlayer];
|
||||
}
|
||||
|
||||
- (void) handleTouchMovedEvent:(UIEvent*)event {
|
||||
- (BOOL) handleTouchMovedEvent:(UIEvent*)event {
|
||||
BOOL shouldSendPacket = false;
|
||||
BOOL buttonTouch = false;
|
||||
float rsMaxX = RS_CENTER_X + STICK_OUTER_SIZE / 2;
|
||||
float rsMaxY = RS_CENTER_Y + STICK_OUTER_SIZE / 2;
|
||||
float rsMinX = RS_CENTER_X - STICK_OUTER_SIZE / 2;
|
||||
@ -331,6 +347,7 @@ static float L2_Y;
|
||||
leftStickX = 0x7FFE * xStickVal;
|
||||
leftStickY = 0x7FFE * -yStickVal;
|
||||
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _rsTouch) {
|
||||
if (xLoc > rsMaxX) xLoc = rsMaxX;
|
||||
if (xLoc < rsMinX) xLoc = rsMinX;
|
||||
@ -348,101 +365,199 @@ static float L2_Y;
|
||||
|
||||
rightStickX = 0x7FFE * xStickVal;
|
||||
rightStickY = 0x7FFE * -yStickVal;
|
||||
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _aTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _bTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _xTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _yTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _upTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _downTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _leftTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _rightTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _startTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _selectTouch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _l1Touch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _r1Touch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _l2Touch) {
|
||||
buttonTouch = true;
|
||||
} else if (touch == _r2Touch) {
|
||||
buttonTouch = true;
|
||||
}
|
||||
}
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
if (shouldSendPacket) {
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
}
|
||||
return shouldSendPacket || buttonTouch;
|
||||
}
|
||||
|
||||
- (void)handleTouchDownEvent:(UIEvent*)event {
|
||||
- (BOOL)handleTouchDownEvent:(UIEvent*)event {
|
||||
BOOL shouldSendPacket = false;
|
||||
for (UITouch* touch in [event allTouches]) {
|
||||
CGPoint touchLocation = [touch locationInView:_view];
|
||||
|
||||
if ([_aButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(A_FLAG, 1);
|
||||
_aTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_bButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(B_FLAG, 1);
|
||||
_bTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_xButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(X_FLAG, 1);
|
||||
_xTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_yButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(Y_FLAG, 1);
|
||||
_yTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_upButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(UP_FLAG, 1);
|
||||
_upTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_downButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(DOWN_FLAG, 1);
|
||||
_downTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_leftButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(LEFT_FLAG, 1);
|
||||
_leftTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_rightButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(RIGHT_FLAG, 1);
|
||||
_rightTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_startButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(PLAY_FLAG, 1);
|
||||
_startTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_selectButton.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(BACK_FLAG, 1);
|
||||
_selectTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_l1Button.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(LB_FLAG, 1);
|
||||
_l1Touch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_r1Button.presentationLayer hitTest:touchLocation]) {
|
||||
UPDATE_BUTTON(RB_FLAG, 1);
|
||||
_r1Touch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_l2Button.presentationLayer hitTest:touchLocation]) {
|
||||
leftTrigger = 1 * 0xFF;
|
||||
_l2Touch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_r2Button.presentationLayer hitTest:touchLocation]) {
|
||||
rightTrigger = 1 * 0xFF;
|
||||
_r2Touch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_leftStick.presentationLayer hitTest:touchLocation]) {
|
||||
_lsTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
} else if ([_rightStick.presentationLayer hitTest:touchLocation]) {
|
||||
_rsTouch = touch;
|
||||
shouldSendPacket = true;
|
||||
}
|
||||
}
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
if (shouldSendPacket) {
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
}
|
||||
return shouldSendPacket;
|
||||
}
|
||||
|
||||
- (void)handleTouchUpEvent:(UIEvent*)event {
|
||||
|
||||
- (BOOL)handleTouchUpEvent:(UIEvent*)event {
|
||||
BOOL shouldSendPacket = false;
|
||||
for (UITouch* touch in [event allTouches]) {
|
||||
CGPoint touchLocation = [touch locationInView:_view];
|
||||
|
||||
if ([_aButton.presentationLayer hitTest:touchLocation]) {
|
||||
if (touch == _aTouch) {
|
||||
UPDATE_BUTTON(A_FLAG, 0);
|
||||
} else if ([_bButton.presentationLayer hitTest:touchLocation]) {
|
||||
_aTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _bTouch) {
|
||||
UPDATE_BUTTON(B_FLAG, 0);
|
||||
} else if ([_xButton.presentationLayer hitTest:touchLocation]) {
|
||||
_bTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _xTouch) {
|
||||
UPDATE_BUTTON(X_FLAG, 0);
|
||||
} else if ([_yButton.presentationLayer hitTest:touchLocation]) {
|
||||
_xTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _yTouch) {
|
||||
UPDATE_BUTTON(Y_FLAG, 0);
|
||||
} else if ([_upButton.presentationLayer hitTest:touchLocation]) {
|
||||
_yTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _upTouch) {
|
||||
UPDATE_BUTTON(UP_FLAG, 0);
|
||||
} else if ([_downButton.presentationLayer hitTest:touchLocation]) {
|
||||
_upTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _downTouch) {
|
||||
UPDATE_BUTTON(DOWN_FLAG, 0);
|
||||
} else if ([_leftButton.presentationLayer hitTest:touchLocation]) {
|
||||
_downTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _leftTouch) {
|
||||
UPDATE_BUTTON(LEFT_FLAG, 0);
|
||||
} else if ([_rightButton.presentationLayer hitTest:touchLocation]) {
|
||||
_leftTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _rightTouch) {
|
||||
UPDATE_BUTTON(RIGHT_FLAG, 0);
|
||||
} else if ([_startButton.presentationLayer hitTest:touchLocation]) {
|
||||
_rightTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _startTouch) {
|
||||
UPDATE_BUTTON(PLAY_FLAG, 0);
|
||||
} else if ([_selectButton.presentationLayer hitTest:touchLocation]) {
|
||||
_startTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _selectTouch) {
|
||||
UPDATE_BUTTON(BACK_FLAG, 0);
|
||||
} else if ([_l1Button.presentationLayer hitTest:touchLocation]) {
|
||||
_selectTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _l1Touch) {
|
||||
UPDATE_BUTTON(LB_FLAG, 0);
|
||||
} else if ([_r1Button.presentationLayer hitTest:touchLocation]) {
|
||||
_l1Touch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _r1Touch) {
|
||||
UPDATE_BUTTON(RB_FLAG, 0);
|
||||
} else if ([_l2Button.presentationLayer hitTest:touchLocation]) {
|
||||
_r1Touch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _l2Touch) {
|
||||
leftTrigger = 0 * 0xFF;
|
||||
} else if ([_r2Button.presentationLayer hitTest:touchLocation]) {
|
||||
_l2Touch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _r2Touch) {
|
||||
rightTrigger = 0 * 0xFF;
|
||||
}
|
||||
if (touch == _lsTouch) {
|
||||
_r2Touch = nil;
|
||||
shouldSendPacket = true;
|
||||
} else if (touch == _lsTouch) {
|
||||
_leftStick.frame = CGRectMake(LS_CENTER_X - STICK_INNER_SIZE / 2, LS_CENTER_Y - STICK_INNER_SIZE / 2, STICK_INNER_SIZE, STICK_INNER_SIZE);
|
||||
leftStickX = 0 * 0x7FFE;
|
||||
leftStickY = 0 * 0x7FFE;
|
||||
shouldSendPacket = true;
|
||||
_lsTouch = nil;
|
||||
} else if (touch == _rsTouch) {
|
||||
_rightStick.frame = CGRectMake(RS_CENTER_X - STICK_INNER_SIZE / 2, RS_CENTER_Y - STICK_INNER_SIZE / 2, STICK_INNER_SIZE, STICK_INNER_SIZE);
|
||||
rightStickX = 0 * 0x7FFE;
|
||||
rightStickY = 0 * 0x7FFE;
|
||||
_rsTouch = nil;
|
||||
shouldSendPacket = true;
|
||||
}
|
||||
}
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
if (shouldSendPacket) {
|
||||
LiSendControllerEvent(buttonFlags, leftTrigger, rightTrigger,
|
||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||
}
|
||||
return shouldSendPacket;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
@ -26,66 +26,69 @@
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
touchLocation = [touch locationInView:self];
|
||||
touchMoved = false;
|
||||
[onScreenControls handleTouchDownEvent:event];
|
||||
NSLog(@"Touch down");
|
||||
if (![onScreenControls handleTouchDownEvent:event]) {
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
touchLocation = [touch locationInView:self];
|
||||
touchMoved = false;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
[onScreenControls handleTouchMovedEvent:event];
|
||||
if ([[event allTouches] count] == 1) {
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
CGPoint currentLocation = [touch locationInView:self];
|
||||
|
||||
if (touchLocation.x != currentLocation.x ||
|
||||
touchLocation.y != currentLocation.y)
|
||||
{
|
||||
LiSendMouseMoveEvent(currentLocation.x - touchLocation.x,
|
||||
currentLocation.y - touchLocation.y );
|
||||
if (![onScreenControls handleTouchMovedEvent:event]) {
|
||||
if ([[event allTouches] count] == 1) {
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
CGPoint currentLocation = [touch locationInView:self];
|
||||
|
||||
if (touchLocation.x != currentLocation.x ||
|
||||
touchLocation.y != currentLocation.y)
|
||||
{
|
||||
LiSendMouseMoveEvent(currentLocation.x - touchLocation.x,
|
||||
currentLocation.y - touchLocation.y );
|
||||
|
||||
touchMoved = true;
|
||||
touchLocation = currentLocation;
|
||||
}
|
||||
} else if ([[event allTouches] count] == 2) {
|
||||
CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
|
||||
CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
|
||||
|
||||
CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2);
|
||||
if (touchLocation.y != avgLocation.y) {
|
||||
LiSendScrollEvent(avgLocation.y - touchLocation.y);
|
||||
}
|
||||
touchMoved = true;
|
||||
touchLocation = currentLocation;
|
||||
touchLocation = avgLocation;
|
||||
}
|
||||
} else if ([[event allTouches] count] == 2) {
|
||||
CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:self];
|
||||
CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:self];
|
||||
|
||||
CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2);
|
||||
if (touchLocation.y != avgLocation.y) {
|
||||
LiSendScrollEvent(avgLocation.y - touchLocation.y);
|
||||
}
|
||||
touchMoved = true;
|
||||
touchLocation = avgLocation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
NSLog(@"Touch up");
|
||||
[onScreenControls handleTouchUpEvent:event];
|
||||
if (!touchMoved) {
|
||||
if ([[event allTouches] count] == 2) {
|
||||
NSLog(@"Sending right mouse button press");
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
|
||||
|
||||
// Wait 100 ms to simulate a real button press
|
||||
usleep(100 * 1000);
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
|
||||
|
||||
|
||||
} else {
|
||||
NSLog(@"Sending left mouse button press");
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
|
||||
|
||||
// Wait 100 ms to simulate a real button press
|
||||
usleep(100 * 1000);
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
|
||||
if (![onScreenControls handleTouchUpEvent:event]) {
|
||||
if (!touchMoved) {
|
||||
if ([[event allTouches] count] == 2) {
|
||||
NSLog(@"Sending right mouse button press");
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
|
||||
|
||||
// Wait 100 ms to simulate a real button press
|
||||
usleep(100 * 1000);
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
|
||||
|
||||
|
||||
} else {
|
||||
NSLog(@"Sending left mouse button press");
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
|
||||
|
||||
// Wait 100 ms to simulate a real button press
|
||||
usleep(100 * 1000);
|
||||
|
||||
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user