now use custom edge swipe detection

This commit is contained in:
Diego Waxemberg
2015-05-29 00:46:43 -07:00
parent f90becb2f6
commit 5a976764c3
6 changed files with 37 additions and 16 deletions
+2 -1
View File
@@ -7,6 +7,7 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "StreamView.h"
@class ControllerSupport; @class ControllerSupport;
@@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
OnScreenControlsLevelAutoGCExtendedGamepad, OnScreenControlsLevelAutoGCExtendedGamepad,
}; };
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport; - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)edgeDelegate;
- (BOOL) handleTouchDownEvent:(NSSet*)touches; - (BOOL) handleTouchDownEvent:(NSSet*)touches;
- (BOOL) handleTouchUpEvent:(NSSet*)touches; - (BOOL) handleTouchUpEvent:(NSSet*)touches;
- (BOOL) handleTouchMovedEvent:(NSSet*)touches; - (BOOL) handleTouchMovedEvent:(NSSet*)touches;
+22 -1
View File
@@ -35,6 +35,7 @@
CALayer* _l1Button; CALayer* _l1Button;
CALayer* _l2Button; CALayer* _l2Button;
CALayer* _l3Button; CALayer* _l3Button;
CALayer* _edge;
UITouch* _aTouch; UITouch* _aTouch;
UITouch* _bTouch; UITouch* _bTouch;
@@ -54,6 +55,7 @@
UITouch* _l1Touch; UITouch* _l1Touch;
UITouch* _l2Touch; UITouch* _l2Touch;
UITouch* _l3Touch; UITouch* _l3Touch;
UITouch* _edgeTouch;
NSDate* l3TouchStart; NSDate* l3TouchStart;
NSDate* r3TouchStart; NSDate* r3TouchStart;
@@ -66,8 +68,11 @@
ControllerSupport *_controllerSupport; ControllerSupport *_controllerSupport;
Controller *_controller; Controller *_controller;
id<EdgeDetectionDelegate> _edgeDelegate;
} }
static const float EDGE_WIDTH = .1;
static const float BUTTON_SIZE = 50; static const float BUTTON_SIZE = 50;
static const float BUTTON_DIST = 20; static const float BUTTON_DIST = 20;
static float BUTTON_CENTER_X; static float BUTTON_CENTER_X;
@@ -115,12 +120,13 @@ static float L2_Y;
static float L3_X; static float L3_X;
static float L3_Y; static float L3_Y;
- (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport { - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
self = [self init]; self = [self init];
_view = view; _view = view;
_controllerSupport = controllerSupport; _controllerSupport = controllerSupport;
_controller = [[Controller alloc] init]; _controller = [[Controller alloc] init];
_controller.playerIndex = 0; _controller.playerIndex = 0;
_edgeDelegate = swipeDelegate;
_aButton = [CALayer layer]; _aButton = [CALayer layer];
_bButton = [CALayer layer]; _bButton = [CALayer layer];
@@ -142,6 +148,9 @@ static float L3_Y;
_rightStickBackground = [CALayer layer]; _rightStickBackground = [CALayer layer];
_leftStick = [CALayer layer]; _leftStick = [CALayer layer];
_rightStick = [CALayer layer]; _rightStick = [CALayer layer];
_edge = [CALayer layer];
[self setupEdgeDetection];
return self; return self;
} }
@@ -210,6 +219,11 @@ static float L3_Y;
} }
} }
- (void) setupEdgeDetection {
_edge.frame = CGRectMake(0, 0, _view.frame.size.width * EDGE_WIDTH, _view.frame.size.height);
[_view.layer addSublayer:_edge];
}
// For GCExtendedGamepad controls we move start, select, L3, and R3 to the button // For GCExtendedGamepad controls we move start, select, L3, and R3 to the button
- (void) setupExtendedGamepadControls { - (void) setupExtendedGamepadControls {
// Start with the default complex layout // Start with the default complex layout
@@ -621,6 +635,8 @@ static float L3_Y;
} }
_rsTouch = touch; _rsTouch = touch;
stickTouch = true; stickTouch = true;
} else if ([_edge.presentationLayer hitTest:touchLocation]) {
_edgeTouch = touch;
} }
} }
if (updated) { if (updated) {
@@ -711,6 +727,11 @@ static float L3_Y;
else if (touch == _r3Touch) { else if (touch == _r3Touch) {
_r3Touch = nil; _r3Touch = nil;
touched = true; touched = true;
} else if (touch == _edgeTouch) {
_edgeTouch = nil;
if (![_edge.presentationLayer hitTest:[touch locationInView:_view]]) {
[_edgeDelegate edgeSwiped];
}
} }
} }
if (updated) { if (updated) {
+7 -1
View File
@@ -9,9 +9,15 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ControllerSupport.h" #import "ControllerSupport.h"
@protocol EdgeDetectionDelegate <NSObject>
- (void) edgeSwiped;
@end
@interface StreamView : UIView @interface StreamView : UIView
- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport; - (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate;
- (void) setMouseDeltaFactors:(float)x y:(float)y; - (void) setMouseDeltaFactors:(float)x y:(float)y;
@end @end
+2 -2
View File
@@ -29,8 +29,8 @@
screenFactor = [[UIScreen mainScreen] scale]; screenFactor = [[UIScreen mainScreen] scale];
} }
- (void) setupOnScreenControls:(ControllerSupport*)controllerSupport { - (void) setupOnScreenControls:(ControllerSupport*)controllerSupport swipeDelegate:(id<EdgeDetectionDelegate>)swipeDelegate {
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport]; onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport swipeDelegate:swipeDelegate];
DataManager* dataMan = [[DataManager alloc] init]; DataManager* dataMan = [[DataManager alloc] init];
OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan retrieveSettings].onscreenControls integerValue]; OnScreenControlsLevel level = (OnScreenControlsLevel)[[dataMan retrieveSettings].onscreenControls integerValue];
@@ -8,10 +8,11 @@
#import "Connection.h" #import "Connection.h"
#import "StreamConfiguration.h" #import "StreamConfiguration.h"
#import "StreamView.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface StreamFrameViewController : UIViewController <ConnectionCallbacks> @interface StreamFrameViewController : UIViewController <ConnectionCallbacks, EdgeDetectionDelegate>
@property (strong, nonatomic) IBOutlet UILabel *stageLabel; @property (strong, nonatomic) IBOutlet UILabel *stageLabel;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner; @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner;
@property (nonatomic) StreamConfiguration* streamConfig; @property (nonatomic) StreamConfiguration* streamConfig;
@@ -11,7 +11,6 @@
#import "VideoDecoderRenderer.h" #import "VideoDecoderRenderer.h"
#import "StreamManager.h" #import "StreamManager.h"
#import "ControllerSupport.h" #import "ControllerSupport.h"
#import "StreamView.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -70,14 +69,7 @@
[self.spinner stopAnimating]; [self.spinner stopAnimating];
[self.stageLabel setText:@"Waiting for first frame..."]; [self.stageLabel setText:@"Waiting for first frame..."];
[self.stageLabel sizeToFit]; [self.stageLabel sizeToFit];
[(StreamView*)self.view setupOnScreenControls: _controllerSupport]; [(StreamView*)self.view setupOnScreenControls: _controllerSupport swipeDelegate:self];
UIScreenEdgePanGestureRecognizer* swipeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)];
swipeGesture.edges = UIRectEdgeLeft;
if (swipeGesture == nil) {
Log(LOG_E, @"An error occured trying to create UIScreenEdgePanGestureRecognizer");
} else {
[self.view addGestureRecognizer:swipeGesture];
}
}); });
} }