Skip to content

Commit 749d1e4

Browse files
committed
Merge pull request #1191 from andykorth/CCDirector/ResponderRefactoring
Mac CCResponder refactoring
2 parents 9f79223 + 4e41b1d commit 749d1e4

File tree

7 files changed

+101
-226
lines changed

7 files changed

+101
-226
lines changed

cocos2d-tests.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
0E28FE1A197FCE4500F78989 /* CCCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E28FE19197FCE4500F78989 /* CCCacheTest.m */; };
11+
750B0BF01A7A936C00DC7048 /* CCActionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 75F4EA241A69847C000E637B /* CCActionsTest.m */; };
1112
75556A04185636F100ED1B0F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75556A03185636F100ED1B0F /* XCTest.framework */; };
1213
75556A05185636F100ED1B0F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E2605717E7D278007067F0 /* Foundation.framework */; };
1314
75556A15185636FB00ED1B0F /* powered.png in Resources */ = {isa = PBXBuildFile; fileRef = 755569E71856361100ED1B0F /* powered.png */; };
@@ -1404,14 +1405,15 @@
14041405
D3763D3819E734C5006C050D /* MainMenu.m in Sources */,
14051406
D3763D3919E734C5006C050D /* TestBase.m in Sources */,
14061407
D3763D3A19E734C5006C050D /* CCCacheTest.m in Sources */,
1408+
750B0BF01A7A936C00DC7048 /* CCActionsTest.m in Sources */,
14071409
D3763D3B19E734C5006C050D /* CCEffectsTest.m in Sources */,
14081410
D3763D3C19E734C5006C050D /* CCRendererTest.m in Sources */,
1411+
D3763D4019E734C5006C050D /* CCTableViewTest.m in Sources */,
14091412
75C72C091A82AD7900814F60 /* main.m in Sources */,
14101413
D3763D3D19E734C5006C050D /* SpritePerformanceTest.m in Sources */,
14111414
D35C2D281A1BC83F00FF96B0 /* CCViewportNodeTest.m in Sources */,
14121415
D3763D3E19E734C5006C050D /* CCScrollViewTest.m in Sources */,
14131416
D3763D3F19E734C5006C050D /* CCSchedulerTest.m in Sources */,
1414-
D3763D4019E734C5006C050D /* CCTableViewTest.m in Sources */,
14151417
D3763D4119E734C5006C050D /* CCTransitionTest.m in Sources */,
14161418
D3763D4219E734C5006C050D /* CCResponderTest.m in Sources */,
14171419
D3763D4319E734C5006C050D /* CCSprite9SliceTest.m in Sources */,

cocos2d-ui/CCControl.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,20 @@ - (void) touchUpOutside:(CCTouch*) touch withEvent:(CCTouchEvent*) event
150150

151151
#elif __CC_PLATFORM_MAC
152152

153-
- (void) mouseDown:(NSEvent *)event
153+
- (void) mouseDown:(NSEvent *)event button:(CCMouseButton)button
154154
{
155+
if(button != CCMouseButtonLeft) return;
156+
155157
_tracking = YES;
156158
_touchInside = YES;
157159

158160
[self mouseDownEntered:event];
159161
}
160162

161-
- (void) mouseDragged:(NSEvent *)event
163+
- (void) mouseDragged:(NSEvent *)event button:(CCMouseButton)button
162164
{
165+
if(button != CCMouseButtonLeft) return;
166+
163167
if ([self clippedHitTestWithWorldPos:[event locationInWorld]])
164168
{
165169
if (!_touchInside)
@@ -178,14 +182,13 @@ - (void) mouseDragged:(NSEvent *)event
178182
}
179183
}
180184

181-
- (void) mouseUp:(NSEvent *)event
185+
- (void) mouseUp:(NSEvent *)event button:(CCMouseButton)button
182186
{
183-
if (_touchInside)
184-
{
187+
if(button != CCMouseButtonLeft) return;
188+
189+
if (_touchInside) {
185190
[self mouseUpInside:event];
186-
}
187-
else
188-
{
191+
} else {
189192
[self mouseUpOutside:event];
190193
}
191194

cocos2d-ui/CCSlider.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ - (void) mouseUpOutside:(NSEvent*)event
133133
[self inputUpOutside];
134134
}
135135

136-
- (void) mouseDragged:(NSEvent*)event
136+
- (void) mouseDragged:(NSEvent*)event button:(CCMouseButton) button
137137
{
138+
if(button != CCMouseButtonLeft){
139+
return;
140+
}
141+
138142
CGPoint dragPos = [event locationInNode:self];
139143

140144
[self inputDraggedWithPos:dragPos];
141145

142-
[super mouseDragged:event];
146+
[super mouseDragged:event button: button];
143147
}
144148

145149
#endif

cocos2d/CCResponder.h

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -181,84 +181,59 @@
181181
/// -----------------------------------------------------------------------
182182

183183
/**
184-
* Called when left mouse button is pressed inside a node with userInteractionEnabled set to YES.
185-
*
186-
* @param theEvent The event created.
187-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
188-
*/
189-
- (void)mouseDown:(NSEvent *)theEvent;
190-
191-
/**
192-
* Called when left mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
193-
*
194-
* @param theEvent The event created.
195-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
184+
* Defines the various mouse buttons.
196185
*/
197-
- (void)mouseDragged:(NSEvent *)theEvent;
186+
typedef NS_ENUM(NSInteger, CCMouseButton)
187+
{
188+
/** Defines left mouse button, in mouse events on OSX. */
189+
CCMouseButtonLeft,
190+
191+
/** Defines right mouse button, in mouse events on OSX. */
192+
CCMouseButtonRight,
193+
194+
/** Defines other (middle) mouse button, in mouse events on OSX. */
195+
CCMouseButtonOther,
196+
};
198197

199198
/**
200-
* Called when left mouse button is released for a node with userInteractionEnabled set to YES.
199+
* Called when any mouse button is pressed inside a node with userInteractionEnabled set to YES.
201200
*
202201
* @param theEvent The event created.
203202
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
204203
*/
205-
- (void)mouseUp:(NSEvent *)theEvent;
204+
- (void)mouseDown:(NSEvent *)theEvent button:(CCMouseButton) button;
206205

207206
/**
208-
* Called when right mouse button is pressed inside a node with userInteractionEnabled set to YES.
207+
* Called when any mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
209208
*
210209
* @param theEvent The event created.
211210
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
212211
*/
213-
- (void)rightMouseDown:(NSEvent *)theEvent;
212+
- (void)mouseDragged:(NSEvent *)theEvent button:(CCMouseButton) button;
214213

215214
/**
216-
* Called when right mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
215+
* Called when any mouse button is released for a node with userInteractionEnabled set to YES.
217216
*
218217
* @param theEvent The event created.
219218
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
220219
*/
221-
- (void)rightMouseDragged:(NSEvent *)theEvent;
220+
- (void)mouseUp:(NSEvent *)theEvent button:(CCMouseButton) button;
222221

223222
/**
224-
* Called when right mouse button is released for a node with userInteractionEnabled set to YES.
225-
*
226-
* @param theEvent The event created.
227-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
228-
*/
229-
- (void)rightMouseUp:(NSEvent *)theEvent;
230-
231-
/**
232-
* Called when middle mouse button is pressed inside a node with userInteractionEnabled set to YES.
233-
*
234-
* @param theEvent The event created.
235-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
236-
*/
237-
- (void)otherMouseDown:(NSEvent *)theEvent;
238-
239-
/**
240-
* Called when middle mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
241-
*
242-
* @param theEvent The event created.
243-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
244-
*/
245-
- (void)otherMouseDragged:(NSEvent *)theEvent;
246-
247-
/**
248-
* Called when middle mouse button is released for a node with userInteractionEnabled set to YES.
223+
* Called when scroll wheel moved while mouse cursor is inside a node with userInteractionEnabled set to YES.
249224
*
250225
* @param theEvent The event created.
251226
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
252227
*/
253-
- (void)otherMouseUp:(NSEvent *)theEvent;
228+
- (void)scrollWheel:(NSEvent *)theEvent;
254229

255230
/**
256-
* Called when scroll wheel moved while mouse cursor is inside a node with userInteractionEnabled set to YES.
257-
*
258-
* @param theEvent The event created.
259-
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
231+
Called when the mouse is moved.
232+
233+
@see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
234+
@since v4.0
260235
*/
261-
- (void)scrollWheel:(NSEvent *)theEvent;
236+
- (void)mouseMoved:(NSEvent *)theEvent;
262237

263238
/**
264239
* Called whan a key down.

cocos2d/CCResponder.m

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,64 +109,39 @@ - (void)touchCancelled:(CCTouch *)touch withEvent:(CCTouchEvent *)event
109109
#pragma mark - OSX
110110
// -----------------------------------------------------------------
111111

112-
- (void)mouseDown:(NSEvent *)theEvent
112+
- (void)mouseDown:(NSEvent *)theEvent button:(CCMouseButton) button
113113
{
114114
[[CCDirector currentDirector].responderManager discardCurrentEvent];
115115
}
116116

117-
- (void)mouseDragged:(NSEvent *)theEvent
117+
- (void)mouseDragged:(NSEvent *)theEvent button:(CCMouseButton) button
118118
{
119119
[[CCDirector currentDirector].responderManager discardCurrentEvent];
120120
}
121121

122-
- (void)mouseUp:(NSEvent *)theEvent
122+
- (void)mouseUp:(NSEvent *)theEvent button:(CCMouseButton) button
123123
{
124124
[[CCDirector currentDirector].responderManager discardCurrentEvent];
125125
}
126126

127-
- (void)rightMouseDown:(NSEvent *)theEvent
128-
{
129-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
130-
}
131-
132-
- (void)rightMouseDragged:(NSEvent *)theEvent
133-
{
134-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
135-
}
136-
137-
- (void)rightMouseUp:(NSEvent *)theEvent
138-
{
139-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
140-
}
141-
142-
- (void)otherMouseDown:(NSEvent *)theEvent
143-
{
144-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
145-
}
146-
147-
- (void)otherMouseDragged:(NSEvent *)theEvent
148-
{
149-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
150-
}
151-
152-
- (void)otherMouseUp:(NSEvent *)theEvent
127+
- (void)scrollWheel:(NSEvent *)theEvent
153128
{
154129
[[CCDirector currentDirector].responderManager discardCurrentEvent];
155130
}
156131

157-
- (void)scrollWheel:(NSEvent *)theEvent
132+
- (void)mouseMoved:(NSEvent *)theEvent
158133
{
159134
[[CCDirector currentDirector].responderManager discardCurrentEvent];
160135
}
161136

162137
-(void)keyDown:(NSEvent *)theEvent
163138
{
164-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
139+
[[CCDirector currentDirector].responderManager discardCurrentEvent];
165140
}
166141

167142
-(void)keyUp:(NSEvent *)theEvent
168143
{
169-
[[CCDirector currentDirector].responderManager discardCurrentEvent];
144+
[[CCDirector currentDirector].responderManager discardCurrentEvent];
170145
}
171146

172147
#endif

cocos2d/CCResponderManager.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// TODO: Grab mouse and touch by implementing onPressed, onReleased, onClicked
3232

3333
#import "ccTypes.h"
34+
#import "CCResponder.h"
3435

3536
@class CCTouch;
3637
@class CCTouchEvent;
@@ -64,23 +65,6 @@
6465

6566
#elif __CC_PLATFORM_MAC
6667

67-
#pragma mark - OSX Running Responder
68-
69-
/**
70-
* Defines the various mouse buttons.
71-
*/
72-
typedef NS_ENUM(NSInteger, CCMouseButton)
73-
{
74-
/** Defines left mouse button, in mouse events on OSX. */
75-
CCMouseButtonLeft,
76-
77-
/** Defines right mouse button, in mouse events on OSX. */
78-
CCMouseButtonRight,
79-
80-
/** Defines other (middle) mouse button, in mouse events on OSX. */
81-
CCMouseButtonOther,
82-
};
83-
8468
#pragma mark - CCRunningResponder
8569

8670
/**

0 commit comments

Comments
 (0)