-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Due to the strangeness of iPadOS mouse support, this is not perfect solution. - No right click - Unable to capture mouse inside the screen After all this years, I totally can't and don't want to understand the original trackpad implementation, so I rewrote it completely, hopefully more clearly, to support external mouse.
- Loading branch information
Chaoji Li
committed
Aug 22, 2020
1 parent
ba70ab5
commit 1fd56ef
Showing
6 changed files
with
333 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,81 +20,64 @@ | |
[email protected] | ||
*/ | ||
|
||
// | ||
// This is a total rewrite of original implementation. | ||
// | ||
// We only support 1 mouse. | ||
// | ||
// The trackpad behavior: | ||
// - pan around is translated to mouse move | ||
// - tap is left click | ||
// - tap while another finger is down is right click | ||
// | ||
// Also: convert pointer move events (bluetooth mouse) to mouse events. | ||
// | ||
// By Chaoji Li, Aug 22, 2020 | ||
// | ||
#import <UIKit/UIKit.h> | ||
#include "SDL_stdinc.h" | ||
#include "SDL_mouse.h" | ||
#include "SDL_mouse_c.h" | ||
#include "SDL_events.h" | ||
|
||
#ifdef IPHONEOS | ||
#define MAX_SIMULTANEOUS_TOUCHES 2 /* Two fingers are enough */ | ||
|
||
/* Mouse hold status */ | ||
#define MOUSE_HOLD_NO 0 | ||
#define MOUSE_HOLD_WAIT 1 | ||
#define MOUSE_HOLD_YES 2 | ||
|
||
#define POSITION_CHANGE_THRESHOLD 15 /* Cancel hold If finger pos move beyond this */ | ||
#define MOUSE_HOLD_INTERVAL 1.5f /* mouse hold happens after 1s */ | ||
#define TAP_THRESHOLD 0.3f /* Tap interval should be less than 0.3s */ | ||
|
||
typedef enum { | ||
MouseRightClickDefault, | ||
MouseRightClickWithDoubleTap | ||
} MouseRightClickMode; | ||
|
||
typedef struct { | ||
CGPoint ptOrig; | ||
int leftHold; | ||
int mouseHold; | ||
NSTimeInterval timestamp; | ||
} ExtMice; | ||
|
||
@protocol MouseHoldDelegate | ||
|
||
-(void)onHold:(CGPoint)pt; | ||
-(void)cancelHold:(CGPoint)pt; | ||
-(void)onHoldMoved:(CGPoint)pt; | ||
- (MouseRightClickMode)currentRightClickMode; | ||
|
||
@end | ||
|
||
|
||
#else | ||
#if SDL_IPHONE_MULTIPLE_MICE | ||
#define MAX_SIMULTANEOUS_TOUCHES 5 | ||
#else | ||
#define MAX_SIMULTANEOUS_TOUCHES 1 | ||
#endif | ||
#endif | ||
|
||
/* *INDENT-OFF* */ | ||
#if SDL_IPHONE_KEYBOARD | ||
@interface SDL_uikitview : UIView<UITextFieldDelegate> { | ||
#else | ||
@interface SDL_uikitview : UIView { | ||
#endif | ||
|
||
SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES]; | ||
SDL_Mouse mice; | ||
|
||
#ifdef IPHONEOS | ||
ExtMice extmice[MAX_SIMULTANEOUS_TOUCHES]; | ||
id<MouseHoldDelegate> mouseHoldDelegate; | ||
#endif | ||
|
||
#if SDL_IPHONE_KEYBOARD | ||
UITextField *textField; | ||
BOOL keyboardVisible; | ||
#endif | ||
|
||
} | ||
#ifdef IPHONEOS | ||
@property (nonatomic,assign) id<MouseHoldDelegate> mouseHoldDelegate; | ||
|
||
- (void)sendMouseEvent:(int)index left:(BOOL)isLeft down:(BOOL)isDown; | ||
|
||
#endif | ||
|
||
|
||
- (void)sendMouseMotion:(int)index x:(CGFloat)x y:(CGFloat)y; | ||
|
||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; | ||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; | ||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; | ||
|
Oops, something went wrong.