Skip to content

Mac CCResponder refactoring #1191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cocos2d-tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
0E28FE1A197FCE4500F78989 /* CCCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E28FE19197FCE4500F78989 /* CCCacheTest.m */; };
750B0BF01A7A936C00DC7048 /* CCActionsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 75F4EA241A69847C000E637B /* CCActionsTest.m */; };
75556A04185636F100ED1B0F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75556A03185636F100ED1B0F /* XCTest.framework */; };
75556A05185636F100ED1B0F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B7E2605717E7D278007067F0 /* Foundation.framework */; };
75556A15185636FB00ED1B0F /* powered.png in Resources */ = {isa = PBXBuildFile; fileRef = 755569E71856361100ED1B0F /* powered.png */; };
Expand Down Expand Up @@ -1404,14 +1405,15 @@
D3763D3819E734C5006C050D /* MainMenu.m in Sources */,
D3763D3919E734C5006C050D /* TestBase.m in Sources */,
D3763D3A19E734C5006C050D /* CCCacheTest.m in Sources */,
750B0BF01A7A936C00DC7048 /* CCActionsTest.m in Sources */,
D3763D3B19E734C5006C050D /* CCEffectsTest.m in Sources */,
D3763D3C19E734C5006C050D /* CCRendererTest.m in Sources */,
D3763D4019E734C5006C050D /* CCTableViewTest.m in Sources */,
75C72C091A82AD7900814F60 /* main.m in Sources */,
D3763D3D19E734C5006C050D /* SpritePerformanceTest.m in Sources */,
D35C2D281A1BC83F00FF96B0 /* CCViewportNodeTest.m in Sources */,
D3763D3E19E734C5006C050D /* CCScrollViewTest.m in Sources */,
D3763D3F19E734C5006C050D /* CCSchedulerTest.m in Sources */,
D3763D4019E734C5006C050D /* CCTableViewTest.m in Sources */,
D3763D4119E734C5006C050D /* CCTransitionTest.m in Sources */,
D3763D4219E734C5006C050D /* CCResponderTest.m in Sources */,
D3763D4319E734C5006C050D /* CCSprite9SliceTest.m in Sources */,
Expand Down
19 changes: 11 additions & 8 deletions cocos2d-ui/CCControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,20 @@ - (void) touchUpOutside:(CCTouch*) touch withEvent:(CCTouchEvent*) event

#elif __CC_PLATFORM_MAC

- (void) mouseDown:(NSEvent *)event
- (void) mouseDown:(NSEvent *)event button:(CCMouseButton)button
{
if(button != CCMouseButtonLeft) return;

_tracking = YES;
_touchInside = YES;

[self mouseDownEntered:event];
}

- (void) mouseDragged:(NSEvent *)event
- (void) mouseDragged:(NSEvent *)event button:(CCMouseButton)button
{
if(button != CCMouseButtonLeft) return;

if ([self clippedHitTestWithWorldPos:[event locationInWorld]])
{
if (!_touchInside)
Expand All @@ -178,14 +182,13 @@ - (void) mouseDragged:(NSEvent *)event
}
}

- (void) mouseUp:(NSEvent *)event
- (void) mouseUp:(NSEvent *)event button:(CCMouseButton)button
{
if (_touchInside)
{
if(button != CCMouseButtonLeft) return;

if (_touchInside) {
[self mouseUpInside:event];
}
else
{
} else {
[self mouseUpOutside:event];
}

Expand Down
8 changes: 6 additions & 2 deletions cocos2d-ui/CCSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ - (void) mouseUpOutside:(NSEvent*)event
[self inputUpOutside];
}

- (void) mouseDragged:(NSEvent*)event
- (void) mouseDragged:(NSEvent*)event button:(CCMouseButton) button
{
if(button != CCMouseButtonLeft){
return;
}

CGPoint dragPos = [event locationInNode:self];

[self inputDraggedWithPos:dragPos];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an if(button == left) check.


[super mouseDragged:event];
[super mouseDragged:event button: button];
}

#endif
Expand Down
75 changes: 25 additions & 50 deletions cocos2d/CCResponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,84 +181,59 @@
/// -----------------------------------------------------------------------

/**
* Called when left mouse button is pressed inside a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
*/
- (void)mouseDown:(NSEvent *)theEvent;

/**
* Called when left mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
* Defines the various mouse buttons.
*/
- (void)mouseDragged:(NSEvent *)theEvent;
typedef NS_ENUM(NSInteger, CCMouseButton)
{
/** Defines left mouse button, in mouse events on OSX. */
CCMouseButtonLeft,

/** Defines right mouse button, in mouse events on OSX. */
CCMouseButtonRight,

/** Defines other (middle) mouse button, in mouse events on OSX. */
CCMouseButtonOther,
};

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

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

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

/**
* Called when right mouse button is released for a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
*/
- (void)rightMouseUp:(NSEvent *)theEvent;

/**
* Called when middle mouse button is pressed inside a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
*/
- (void)otherMouseDown:(NSEvent *)theEvent;

/**
* Called when middle mouse button is held and mouse dragged for a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
*/
- (void)otherMouseDragged:(NSEvent *)theEvent;

/**
* Called when middle mouse button is released for a node with userInteractionEnabled set to YES.
* Called when scroll wheel moved while mouse cursor is inside a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
*/
- (void)otherMouseUp:(NSEvent *)theEvent;
- (void)scrollWheel:(NSEvent *)theEvent;

/**
* Called when scroll wheel moved while mouse cursor is inside a node with userInteractionEnabled set to YES.
*
* @param theEvent The event created.
* @see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
Called when the mouse is moved.

@see [NSEvent](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/)
@since v4.0
*/
- (void)scrollWheel:(NSEvent *)theEvent;
- (void)mouseMoved:(NSEvent *)theEvent;

/**
* Called whan a key down.
Expand Down
39 changes: 7 additions & 32 deletions cocos2d/CCResponder.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,64 +109,39 @@ - (void)touchCancelled:(CCTouch *)touch withEvent:(CCTouchEvent *)event
#pragma mark - OSX
// -----------------------------------------------------------------

- (void)mouseDown:(NSEvent *)theEvent
- (void)mouseDown:(NSEvent *)theEvent button:(CCMouseButton) button
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)mouseDragged:(NSEvent *)theEvent
- (void)mouseDragged:(NSEvent *)theEvent button:(CCMouseButton) button
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)mouseUp:(NSEvent *)theEvent
- (void)mouseUp:(NSEvent *)theEvent button:(CCMouseButton) button
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)rightMouseDown:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)rightMouseDragged:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)rightMouseUp:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)otherMouseDown:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)otherMouseDragged:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)otherMouseUp:(NSEvent *)theEvent
- (void)scrollWheel:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

- (void)scrollWheel:(NSEvent *)theEvent
- (void)mouseMoved:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

-(void)keyDown:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

-(void)keyUp:(NSEvent *)theEvent
{
[[CCDirector currentDirector].responderManager discardCurrentEvent];
[[CCDirector currentDirector].responderManager discardCurrentEvent];
}

#endif
Expand Down
18 changes: 1 addition & 17 deletions cocos2d/CCResponderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// TODO: Grab mouse and touch by implementing onPressed, onReleased, onClicked

#import "ccTypes.h"
#import "CCResponder.h"

@class CCTouch;
@class CCTouchEvent;
Expand Down Expand Up @@ -64,23 +65,6 @@

#elif __CC_PLATFORM_MAC

#pragma mark - OSX Running Responder

/**
* Defines the various mouse buttons.
*/
typedef NS_ENUM(NSInteger, CCMouseButton)
{
/** Defines left mouse button, in mouse events on OSX. */
CCMouseButtonLeft,

/** Defines right mouse button, in mouse events on OSX. */
CCMouseButtonRight,

/** Defines other (middle) mouse button, in mouse events on OSX. */
CCMouseButtonOther,
};

#pragma mark - CCRunningResponder

/**
Expand Down
Loading