Skip to content
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

#issue-680 and #issue-681 #682

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cocos2d/CCDirector.m
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ -(void) setView:(CCGLView*)view
#ifdef __CC_PLATFORM_IOS
CGFloat scale = __view.layer.contentsScale ?: 1.0;
#else
//self.view.wantsBestResolutionOpenGLSurface = YES;
self.view.wantsBestResolutionOpenGLSurface = YES;
CGFloat scale = self.view.window.backingScaleFactor;
#endif

Expand Down
14 changes: 14 additions & 0 deletions cocos2d/CCResponder.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@
*/
- (void)scrollWheel:(NSEvent *)theEvent;

/**
* Called whan a key down.
*
* @param theEvent Current event information.
*/
- (void)keyDown:(NSEvent *)theEvent;

/**
* Called whan a key up.
*
* @param theEvent Current event information.
*/
- (void)keyUp:(NSEvent *)theEvent;

#endif

@end
10 changes: 10 additions & 0 deletions cocos2d/CCResponder.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ - (void)scrollWheel:(NSEvent *)theEvent
[[CCDirector sharedDirector].responderManager discardCurrentEvent];
}

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

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

#endif

// -----------------------------------------------------------------
Expand Down
35 changes: 35 additions & 0 deletions cocos2d/CCResponderManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,41 @@ - (void)mouseExited:(NSEvent *)theEvent

}

// -----------------------------------------------------------------
#pragma mark - Mac keyboard handling -
// -----------------------------------------------------------------

- (void)keyDown:(NSEvent *)theEvent
{
if (!_enabled) return;
[[CCDirector sharedDirector].view.window makeFirstResponder:[CCDirector sharedDirector].view];

if (_dirty) [self buildResponderList];

// scan backwards through mouse responders
for (int index = _responderListCount - 1; index >= 0; index --)
{
CCNode *node = _responderList[index];
[node keyDown:theEvent];
}
}

- (void)keyUp:(NSEvent *)theEvent
{
if (!_enabled) return;
[[CCDirector sharedDirector].view.window makeFirstResponder:[CCDirector sharedDirector].view];

if (_dirty) [self buildResponderList];

// scan backwards through mouse responders
for (int index = _responderListCount - 1; index >= 0; index --)
{
CCNode *node = _responderList[index];
[node keyUp:theEvent];
}
}


// -----------------------------------------------------------------
#pragma mark - Mac helper functions
// -----------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions cocos2d/Platforms/Mac/CCDirectorMac.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ - (void) setFullScreen:(BOOL)fullscreen
self.view.wantsBestResolutionOpenGLSurface = YES;

}
// issue #681
[openGLview keyDown:nil];

// issue #1189
[_windowGLView makeFirstResponder:openGLview];
Expand Down
10 changes: 10 additions & 0 deletions cocos2d/Platforms/Mac/CCGLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ - (void)scrollWheel:(NSEvent *)theEvent
[[CCDirector sharedDirector].responderManager scrollWheel:theEvent];
}

- (void) keyDown:(NSEvent *)theEvent {
// dispatch keyboard to responder manager
[[CCDirector sharedDirector].responderManager keyDown:theEvent];
}

- (void) keyUp:(NSEvent *)theEvent {
// dispatch keyboard to responder manager
[[CCDirector sharedDirector].responderManager keyUp:theEvent];
}

@end

#endif // __CC_PLATFORM_MAC