|
20 | 20 | slouken@libsdl.org |
21 | 21 | */ |
22 | 22 |
|
| 23 | +// |
| 24 | +// This is a total rewrite of original implementation. |
| 25 | +// |
| 26 | +// We only support 1 mouse. |
| 27 | +// |
| 28 | +// The trackpad behavior: |
| 29 | +// - pan around is translated to mouse move |
| 30 | +// - tap is left click |
| 31 | +// - tap while another finger is down is right click |
| 32 | +// |
| 33 | +// Also: convert pointer move events (bluetooth mouse) to mouse events. |
| 34 | +// |
| 35 | +// By Chaoji Li, Aug 22, 2020 |
| 36 | +// |
23 | 37 | #import <UIKit/UIKit.h> |
24 | 38 | #include "SDL_stdinc.h" |
25 | 39 | #include "SDL_mouse.h" |
26 | 40 | #include "SDL_mouse_c.h" |
27 | 41 | #include "SDL_events.h" |
28 | 42 |
|
29 | | -#ifdef IPHONEOS |
30 | | -#define MAX_SIMULTANEOUS_TOUCHES 2 /* Two fingers are enough */ |
31 | | - |
32 | | -/* Mouse hold status */ |
33 | | -#define MOUSE_HOLD_NO 0 |
34 | | -#define MOUSE_HOLD_WAIT 1 |
35 | | -#define MOUSE_HOLD_YES 2 |
36 | | - |
37 | | -#define POSITION_CHANGE_THRESHOLD 15 /* Cancel hold If finger pos move beyond this */ |
38 | | -#define MOUSE_HOLD_INTERVAL 1.5f /* mouse hold happens after 1s */ |
39 | | -#define TAP_THRESHOLD 0.3f /* Tap interval should be less than 0.3s */ |
40 | 43 |
|
41 | 44 | typedef enum { |
42 | 45 | MouseRightClickDefault, |
43 | 46 | MouseRightClickWithDoubleTap |
44 | 47 | } MouseRightClickMode; |
45 | 48 |
|
46 | | -typedef struct { |
47 | | - CGPoint ptOrig; |
48 | | - int leftHold; |
49 | | - int mouseHold; |
50 | | - NSTimeInterval timestamp; |
51 | | -} ExtMice; |
52 | 49 |
|
53 | 50 | @protocol MouseHoldDelegate |
54 | 51 |
|
55 | 52 | -(void)onHold:(CGPoint)pt; |
56 | 53 | -(void)cancelHold:(CGPoint)pt; |
| 54 | +-(void)onHoldMoved:(CGPoint)pt; |
57 | 55 | - (MouseRightClickMode)currentRightClickMode; |
58 | 56 |
|
59 | 57 | @end |
60 | 58 |
|
61 | | - |
62 | | -#else |
63 | | -#if SDL_IPHONE_MULTIPLE_MICE |
64 | | -#define MAX_SIMULTANEOUS_TOUCHES 5 |
65 | | -#else |
66 | | -#define MAX_SIMULTANEOUS_TOUCHES 1 |
67 | | -#endif |
68 | | -#endif |
69 | | - |
70 | 59 | /* *INDENT-OFF* */ |
71 | 60 | #if SDL_IPHONE_KEYBOARD |
72 | 61 | @interface SDL_uikitview : UIView<UITextFieldDelegate> { |
73 | 62 | #else |
74 | 63 | @interface SDL_uikitview : UIView { |
75 | 64 | #endif |
76 | 65 |
|
77 | | - SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES]; |
| 66 | + SDL_Mouse mice; |
78 | 67 |
|
79 | | -#ifdef IPHONEOS |
80 | | - ExtMice extmice[MAX_SIMULTANEOUS_TOUCHES]; |
81 | 68 | id<MouseHoldDelegate> mouseHoldDelegate; |
82 | | -#endif |
83 | 69 |
|
84 | 70 | #if SDL_IPHONE_KEYBOARD |
85 | 71 | UITextField *textField; |
86 | 72 | BOOL keyboardVisible; |
87 | 73 | #endif |
88 | 74 |
|
89 | 75 | } |
90 | | -#ifdef IPHONEOS |
91 | 76 | @property (nonatomic,assign) id<MouseHoldDelegate> mouseHoldDelegate; |
92 | 77 |
|
93 | 78 | - (void)sendMouseEvent:(int)index left:(BOOL)isLeft down:(BOOL)isDown; |
94 | | - |
95 | | -#endif |
96 | | - |
97 | | - |
| 79 | +- (void)sendMouseMotion:(int)index x:(CGFloat)x y:(CGFloat)y; |
| 80 | + |
98 | 81 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; |
99 | 82 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; |
100 | 83 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; |
|
0 commit comments