Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Gestures for iOS #242

Merged
merged 3 commits into from

2 participants

@Memphiz
Owner

I did this as pr only because i didn't want to fiddle that much with git in my ios tree ... davilla already waved this commit through so i'll hit the merge button immediately

[ios] - use gesture api of XBMC for ios touch devices
- hide mouse cursor
- double finger swipe left -> backspace
- double finger single tap -> mouse right click

[add] - HasCursor method to WinSystemBase - defaulting to true
- overwrite this for ios to false if not appletv2
- use HasCursor in GUIWindowPointer::UpdateVisibility

Memphiz added some commits
@Memphiz Memphiz [ios] - use gesture api of XBMC for ios touch devices
- hide mouse cursor
- double finger swipe left -> backspace
- double finger single tap -> mouse right click
b6a55cf
@Memphiz Memphiz [add] - HasCursor method to WinSystemBase - defaulting to true
- overwrite this for ios to false if not appletv2
- use HasCursor in GUIWindowPointer::UpdateVisibility
2aea49b
@Memphiz Memphiz [refactored] - moved IsAppleTV2 to DarwinUtils
- make IsAppleTV2 cache the result
119f1bd
@Memphiz Memphiz merged commit 43123dc into from
@jmarshallnz

This looks wrong. result is an integer, use it as such. Thus, result = 0 or result = 1 return (result == 1);

@dalehamel dalehamel referenced this pull request from a commit in RasPlex/plex-home-theatre
@gitSebastian gitSebastian Fix #242. An animation glitch in preferences. 820ee33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 1, 2011
  1. @Memphiz

    [ios] - use gesture api of XBMC for ios touch devices

    Memphiz authored
    - hide mouse cursor
    - double finger swipe left -> backspace
    - double finger single tap -> mouse right click
  2. @Memphiz

    [add] - HasCursor method to WinSystemBase - defaulting to true

    Memphiz authored
    - overwrite this for ios to false if not appletv2
    - use HasCursor in GUIWindowPointer::UpdateVisibility
  3. @Memphiz

    [refactored] - moved IsAppleTV2 to DarwinUtils

    Memphiz authored
    - make IsAppleTV2 cache the result
This page is out of date. Refresh to see the latest.
View
1  xbmc/osx/DarwinUtils.h
@@ -27,6 +27,7 @@
extern "C"
{
#endif
+ bool DarwinIsAppleTV2(void);
float GetIOSVersion(void);
int GetDarwinFrameworkPath(bool forPython, char* path, uint32_t *pathsize);
int GetDarwinExecutablePath(char* path, uint32_t *pathsize);
View
22 xbmc/osx/DarwinUtils.mm
@@ -38,6 +38,28 @@
#import "AutoPool.h"
#import "DarwinUtils.h"
+
+bool DarwinIsAppleTV2(void)
+{
+ static int result = -1;
+#if defined(__APPLE__) && defined(__arm__)
+ if( result == -1 )
+ {
+ char buffer[512];
+ size_t len = 512;
+ result = false;
+ std::string hw_machine = "unknown";
+
+ if (sysctlbyname("hw.machine", &buffer, &len, NULL, 0) == 0)
+ hw_machine = buffer;
+
+ if (hw_machine.find("AppleTV2,1") != std::string::npos)
+ result = true;
+ }
+#endif
+ return result;
+}
+
float GetIOSVersion(void)
{
CCocoaAutoPool pool;
View
10 xbmc/osx/ios/XBMCController.h
@@ -32,17 +32,19 @@
int m_screensaverTimeout;
/* Touch handling */
- CGPoint firstTouch;
- CGPoint lastTouch;
CGSize screensize;
+ CGPoint lastGesturePoint;
+ int lastAllowedGestures;
+ bool touchBeginSignaled;
UIInterfaceOrientation orientation;
XBMC_Event lastEvent;
}
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
-@property CGPoint firstTouch;
-@property CGPoint lastTouch;
+@property CGPoint lastGesturePoint;
+@property int lastAllowedGestures;
+@property bool touchBeginSignaled;
@property CGSize screensize;
@property XBMC_Event lastEvent;
View
223 xbmc/osx/ios/XBMCController.mm
@@ -31,6 +31,7 @@
#include "Application.h"
#include "MouseStat.h"
#include "WindowingFactory.h"
+#include "guilib/GUIWindowManager.h"
#include "VideoReferenceClock.h"
#include "utils/log.h"
#include "utils/TimeUtils.h"
@@ -62,9 +63,10 @@ -(void) terminateWithSuccess;
@end
@implementation XBMCController
-@synthesize firstTouch;
-@synthesize lastTouch;
+@synthesize lastGesturePoint;
@synthesize lastEvent;
+@synthesize lastAllowedGestures;
+@synthesize touchBeginSignaled;
@synthesize screensize;
//--------------------------------------------------------------
@@ -87,7 +89,7 @@ -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceO
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
orientation = toInterfaceOrientation;
-
+
CGRect rect;
CGRect srect = [[UIScreen mainScreen] bounds];
@@ -110,13 +112,13 @@ -(void)sendKey:(XBMCKey) key
{
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));
-
+
//newEvent.key.keysym.unicode = key;
newEvent.key.keysym.sym = key;
-
+
newEvent.type = XBMC_KEYDOWN;
CWinEventsIOS::MessagePush(&newEvent);
-
+
newEvent.type = XBMC_KEYUP;
CWinEventsIOS::MessagePush(&newEvent);
}
@@ -124,70 +126,35 @@ -(void)sendKey:(XBMCKey) key
- (void)createGestureRecognizers
{
- UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleSingleDoubleTap:)];
- singleFingerDTap.delaysTouchesBegan = YES;
- singleFingerDTap.numberOfTapsRequired = 2;
- [self.view addGestureRecognizer:singleFingerDTap];
- [singleFingerDTap release];
-
+ //2 finger double tab - right mouse
+ //single finger double tab delays single finger single tab - so we
+ //go for 2 fingers here - so single finger single tap is instant
+ UITapGestureRecognizer *doubleFingerDTap = [[UITapGestureRecognizer alloc]
+ initWithTarget:self action:@selector(handleDoubleFingerDoubleTap:)];
+ doubleFingerDTap.delaysTouchesBegan = YES;
+ doubleFingerDTap.numberOfTapsRequired = 2;
+ doubleFingerDTap.numberOfTouchesRequired = 2;
+ [self.view addGestureRecognizer:doubleFingerDTap];
+ [doubleFingerDTap release];
+
+ //double finger swipe left for backspace ... i like this fast backspace feature ;)
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleSwipeLeft:)];
- swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
+ initWithTarget:self action:@selector(handleSwipeLeft:)];
swipeLeft.delaysTouchesBegan = YES;
+ swipeLeft.numberOfTouchesRequired = 2;
+ swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];
-
- UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleSwipeRight:)];
- swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
- swipeRight.delaysTouchesBegan = YES;
- [self.view addGestureRecognizer:swipeRight];
- [swipeRight release];
-
- UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleSwipeUp:)];
- swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
- swipeUp.delaysTouchesBegan = YES;
- [self.view addGestureRecognizer:swipeUp];
- [swipeUp release];
-
- UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc]
- initWithTarget:self action:@selector(handleSwipeDown:)];
- swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
- swipeDown.delaysTouchesBegan = YES;
- [self.view addGestureRecognizer:swipeDown];
- [swipeDown release];
}
//--------------------------------------------------------------
- (IBAction)handleSwipeLeft:(UISwipeGestureRecognizer *)sender
{
- //NSLog(@"%s swipeLeft", __PRETTY_FUNCTION__);
[self sendKey:XBMCK_BACKSPACE];
}
//--------------------------------------------------------------
-- (IBAction)handleSwipeRight:(UISwipeGestureRecognizer *)sender
-{
- //NSLog(@"%s swipeRight", __PRETTY_FUNCTION__);
- [self sendKey:XBMCK_TAB];
-}
-//--------------------------------------------------------------
-- (IBAction)handleSwipeUp:(UISwipeGestureRecognizer *)sender
-{
- //NSLog(@"%s swipeUp", __PRETTY_FUNCTION__);
- [self sendKey:XBMCK_UP];
-}
-//--------------------------------------------------------------
-- (IBAction)handleSwipeDown:(UISwipeGestureRecognizer *)sender
-{
- //NSLog(@"%s swipeDown", __PRETTY_FUNCTION__);
- [self sendKey:XBMCK_DOWN];
-}
-//--------------------------------------------------------------
-- (IBAction)handleSingleDoubleTap:(UIGestureRecognizer *)sender
+- (IBAction)handleDoubleFingerDoubleTap:(UIGestureRecognizer *)sender
{
- firstTouch = [sender locationOfTouch:0 inView:m_glView];
- lastTouch = [sender locationOfTouch:0 inView:m_glView];
+ CGPoint point = [sender locationOfTouch:0 inView:m_glView];
//NSLog(@"%s toubleTap", __PRETTY_FUNCTION__);
@@ -197,11 +164,11 @@ - (IBAction)handleSingleDoubleTap:(UIGestureRecognizer *)sender
newEvent.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.type = XBMC_MOUSEBUTTONDOWN;
newEvent.button.button = XBMC_BUTTON_RIGHT;
- newEvent.button.x = lastTouch.x;
- newEvent.button.y = lastTouch.y;
+ newEvent.button.x = point.x;
+ newEvent.button.y = point.y;
CWinEventsIOS::MessagePush(&newEvent);
-
+
newEvent.type = XBMC_MOUSEBUTTONUP;
newEvent.button.type = XBMC_MOUSEBUTTONUP;
CWinEventsIOS::MessagePush(&newEvent);
@@ -213,82 +180,90 @@ - (IBAction)handleSingleDoubleTap:(UIGestureRecognizer *)sender
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
- firstTouch = [touch locationInView:m_glView];
- lastTouch = [touch locationInView:m_glView];
-
- //NSLog(@"%s touchesBegan x=%f, y=%f count=%d", __PRETTY_FUNCTION__, lastTouch.x, lastTouch.y, [touch tapCount]);
-
- XBMC_Event newEvent;
- memset(&newEvent, 0, sizeof(newEvent));
-
- newEvent.type = XBMC_MOUSEBUTTONDOWN;
- newEvent.button.type = XBMC_MOUSEBUTTONDOWN;
- newEvent.button.x = lastTouch.x;
- newEvent.button.y = lastTouch.y;
- newEvent.button.button = XBMC_BUTTON_LEFT;
- CWinEventsIOS::MessagePush(&newEvent);
-
- /* Store the tap action for later */
- memcpy(&lastEvent, &newEvent, sizeof(XBMC_Event));
+ CGPoint point = [touch locationInView:m_glView];
+ CGUIMessage message(GUI_MSG_GESTURE_NOTIFY, 0, 0, point.x, point.y);
+ if (g_windowManager.SendMessage(message))
+ {
+ lastAllowedGestures = message.GetParam1();
+ touchBeginSignaled = false;
+ lastGesturePoint = point;
+ }
}
//--------------------------------------------------------------
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
+ bool bNotify = false;
UITouch *touch = [touches anyObject];
- lastTouch = [touch locationInView:m_glView];
+ CGPoint point = [touch locationInView:m_glView];
+ CGFloat yMovement=point.y - lastGesturePoint.y;
+ CGFloat xMovement=point.x - lastGesturePoint.x;
+
+ if( xMovement && (lastAllowedGestures & EVENT_RESULT_PAN_HORIZONTAL) )
+ {
+ bNotify = true;
+ }
- //NSLog(@"%s touchesMoved x=%f, y=%f count=%d", __PRETTY_FUNCTION__, lastTouch.x, lastTouch.y, touch.tapCount);
+ if( yMovement && (lastAllowedGestures & EVENT_RESULT_PAN_VERTICAL) )
+ {
+ bNotify = true;
+ }
- static int nCount = 0;
+ if( bNotify )
+ {
+ if( !touchBeginSignaled )
+ {
+ g_application.getApplicationMessenger().SendAction(CAction(ACTION_GESTURE_BEGIN, 0, (float)point.x, (float)point.y,
+ 0, 0), WINDOW_INVALID);
+ touchBeginSignaled = true;
+ }
- /* Only process move when we are not in right click state */
- if(nCount == 4) {
-
- XBMC_Event newEvent;
- memcpy(&newEvent, &lastEvent, sizeof(XBMC_Event));
-
- newEvent.motion.x = lastTouch.x;
- newEvent.motion.y = lastTouch.y;
-
- CWinEventsIOS::MessagePush(&newEvent);
-
- nCount = 0;
-
- } else {
-
- nCount++;
-
+ g_application.getApplicationMessenger().SendAction(CAction(ACTION_GESTURE_PAN, 0, (float)point.x, (float)point.y,
+ xMovement, yMovement), WINDOW_INVALID);
+ lastGesturePoint = point;
}
}
//--------------------------------------------------------------
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
- lastTouch = [touch locationInView:m_glView];
-
- //NSLog(@"%s touchesEnded x=%f, y=%f count=%d", __PRETTY_FUNCTION__, lastTouch.x, lastTouch.y, [touch tapCount]);
-
- XBMC_Event newEvent;
- memcpy(&newEvent, &lastEvent, sizeof(XBMC_Event));
-
- newEvent.type = XBMC_MOUSEBUTTONUP;
- newEvent.button.type = XBMC_MOUSEBUTTONUP;
- newEvent.button.x = lastTouch.x;
- newEvent.button.y = lastTouch.y;
- CWinEventsIOS::MessagePush(&newEvent);
-
- memset(&lastEvent, 0x0, sizeof(XBMC_Event));
+ CGPoint point = [touch locationInView:m_glView];
+ if( [touch tapCount] == 1 )
+ {
+ XBMC_Event newEvent;
+ memset(&newEvent, 0, sizeof(newEvent));
+
+ newEvent.type = XBMC_MOUSEBUTTONDOWN;
+ newEvent.button.type = XBMC_MOUSEBUTTONDOWN;
+ newEvent.button.button = XBMC_BUTTON_LEFT;
+ newEvent.button.x = point.x;
+ newEvent.button.y = point.y;
+
+ CWinEventsIOS::MessagePush(&newEvent);
+
+ newEvent.type = XBMC_MOUSEBUTTONUP;
+ newEvent.button.type = XBMC_MOUSEBUTTONUP;
+ CWinEventsIOS::MessagePush(&newEvent);
+
+ memset(&lastEvent, 0x0, sizeof(XBMC_Event));
+ }
+ else
+ {
+ //TODO some inertial emulation here... threaded - should stop immediatly if touchesBegan is called
+ g_application.getApplicationMessenger().SendAction(CAction(ACTION_GESTURE_END),WINDOW_INVALID);
+ touchBeginSignaled = false;
+ lastAllowedGestures = 0;
+ }
}
//--------------------------------------------------------------
- (id)initWithFrame:(CGRect)frame
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
-
+
self = [super init];
if ( !self )
return ( nil );
-
+
NSNotificationCenter *center;
center = [NSNotificationCenter defaultCenter];
[center addObserver: self
@@ -303,13 +278,13 @@ - (id)initWithFrame:(CGRect)frame
m_glView = [[XBMCEAGLView alloc] initWithFrame: srect];
[m_glView setMultipleTouchEnabled:YES];
-
+
//[self setView: m_glView];
-
+
[self.view addSubview: m_glView];
[self createGestureRecognizers];
-
+
g_xbmcController = self;
return self;
@@ -324,24 +299,24 @@ - (void)dealloc
{
[m_glView stopAnimation];
[m_glView release];
-
+
NSNotificationCenter *center;
// take us off the default center for our app
center = [NSNotificationCenter defaultCenter];
[center removeObserver: self];
-
+
[super dealloc];
}
//--------------------------------------------------------------
- (void)viewWillAppear:(BOOL)animated
{
//NSLog(@"%s", __PRETTY_FUNCTION__);
-
+
// move this later into CocoaPowerSyscall
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
-
+
[self resumeAnimation];
-
+
[super viewWillAppear:animated];
}
//--------------------------------------------------------------
@@ -404,7 +379,7 @@ - (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
-
+
// Release any cached data, images, etc. that aren't in use.
}
//--------------------------------------------------------------
@@ -449,7 +424,7 @@ - (void)resumeAnimation
newEvent.appcommand.type = XBMC_APPCOMMAND;
newEvent.appcommand.action = ACTION_PLAYER_PLAY;
CWinEventsIOS::MessagePush(&newEvent);
-
+
[m_glView resumeAnimation];
}
//--------------------------------------------------------------
View
14 xbmc/utils/SystemInfo.cpp
@@ -711,19 +711,7 @@ bool CSysInfo::IsAppleTV()
bool CSysInfo::IsAppleTV2()
{
- bool result = false;
-#if defined(__APPLE__) && defined(__arm__)
- char buffer[512];
- size_t len = 512;
- std::string hw_machine = "unknown";
-
- if (sysctlbyname("hw.machine", &buffer, &len, NULL, 0) == 0)
- hw_machine = buffer;
-
- if (hw_machine.find("AppleTV2,1") != std::string::npos)
- result = true;
-#endif
- return result;
+ return DarwinIsAppleTV2();
}
bool CSysInfo::HasVideoToolBoxDecoder()
View
1  xbmc/windowing/WinSystem.h
@@ -70,6 +70,7 @@ class CWinSystemBase
virtual void NotifyAppFocusChange(bool bGaining) {}
virtual void NotifyAppActiveChange(bool bActivated) {}
virtual void ShowOSMouse(bool show) {};
+ virtual bool HasCursor(){ return true; }
virtual bool Minimize() { return false; }
virtual bool Restore() { return false; }
View
1  xbmc/windowing/osx/WinSystemIOS.h
@@ -44,6 +44,7 @@ class CWinSystemIOS : public CWinSystemBase, public CRenderSystemGLES
virtual void UpdateResolutions();
virtual void ShowOSMouse(bool show);
+ virtual bool HasCursor();
virtual void NotifyAppActiveChange(bool bActivated);
View
13 xbmc/windowing/osx/WinSystemIOS.mm
@@ -40,6 +40,7 @@
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import "XBMCController.h"
+#include "osx/DarwinUtils.h"
#import <dlfcn.h>
CWinSystemIOS::CWinSystemIOS() : CWinSystemBase()
@@ -200,6 +201,18 @@
{
}
+bool CWinSystemIOS::HasCursor()
+{
+ if( DarwinIsAppleTV2() )
+ {
+ return true;
+ }
+ else//apple touch devices
+ {
+ return false;
+ }
+}
+
void CWinSystemIOS::NotifyAppActiveChange(bool bActivated)
{
if (bActivated && m_bWasFullScreenBeforeMinimize && !g_graphicsContext.IsFullScreenRoot())
View
12 xbmc/windows/GUIWindowPointer.cpp
@@ -21,6 +21,7 @@
#include "GUIWindowPointer.h"
#include "input/MouseStat.h"
+#include "windowing/WindowingFactory.h"
#include <climits>
#define ID_POINTER 10
@@ -56,10 +57,13 @@ void CGUIWindowPointer::SetPointer(int pointer)
void CGUIWindowPointer::UpdateVisibility()
{
- if (g_Mouse.IsActive())
- Show();
- else
- Close();
+ if(g_Windowing.HasCursor())
+ {
+ if (g_Mouse.IsActive())
+ Show();
+ else
+ Close();
+ }
}
void CGUIWindowPointer::OnWindowLoaded()
Something went wrong with that request. Please try again.