mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5152 from dumganhar/iss3808-glfw-remove-unused
closed #3808: Removes unused files for MAC platform after using glfw3 to create opengl context
This commit is contained in:
commit
5b91b9ea2e
|
@ -1 +1 @@
|
|||
98eebd5b205bbcad3d5c6b70ee9db766ab284e06
|
||||
db31f01b55bf1ae19e57e71bae6f58a037bfe5b9
|
|
@ -22,14 +22,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include "platform/CCCommon.h"
|
||||
#include "CCEGLView.h"
|
||||
#define GLFW_EXPOSE_NATIVE_NSGL
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#include "glfw3native.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#import "EAGLView.h"
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
@ -50,7 +51,7 @@ void MessageBox(const char * msg, const char * title)
|
|||
[alert setInformativeText:tmpTitle];
|
||||
[alert setAlertStyle:NSWarningAlertStyle];
|
||||
|
||||
NSWindow *window = [[CCEAGLView sharedEGLView] window];
|
||||
id window = glfwGetCocoaWindow(EGLView::getInstance()->getWindow());
|
||||
[alert beginSheetModalForWindow:window
|
||||
modalDelegate:[window delegate]
|
||||
didEndSelector:nil
|
||||
|
|
|
@ -22,13 +22,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "CCDirectorCaller.h"
|
||||
#import "CCDirector.h"
|
||||
#import "EAGLView.h"
|
||||
#import "CCEventDispatcherMac.h"
|
||||
#include "CCDirector.h"
|
||||
#include "CCAutoreleasePool.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
static id s_sharedDirectorCaller;
|
||||
|
||||
@interface NSObject(CADisplayLink)
|
||||
|
@ -82,7 +83,6 @@ static id s_sharedDirectorCaller;
|
|||
|
||||
cocos2d::Director::getInstance()->drawScene();
|
||||
cocos2d::PoolManager::getInstance()->getCurrentPool()->clear();
|
||||
[[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents];
|
||||
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:nil];
|
||||
|
||||
|
@ -115,21 +115,9 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|||
// All we do here is tell the display it needs a refresh
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// get the opengl view
|
||||
CCEAGLView *openGLView = [CCEAGLView sharedEGLView];
|
||||
[openGLView lockOpenGLContext];
|
||||
|
||||
// run the main cocos2d loop
|
||||
cocos2d::Director::getInstance()->mainLoop();
|
||||
|
||||
// flush buffer (this line is very important!)
|
||||
[[openGLView openGLContext] flushBuffer];
|
||||
|
||||
[openGLView unlockOpenGLContext];
|
||||
|
||||
// send any queued events
|
||||
[[CCEventDispatcher sharedDispatcher] dispatchQueuedEvents];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,277 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// Only compile this code on Mac. These files should not be included on your iOS project.
|
||||
// But in case they are included, it won't be compiled.
|
||||
#import <Availability.h>
|
||||
#ifndef __CC_EVENT_DISPATCHER_MAC_H__
|
||||
#define __CC_EVENT_DISPATCHER_MAC_H__
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "EAGLView.h"
|
||||
//#import "../../Support/uthash.h" // hack: uthash needs to be imported before utlist to prevent warning
|
||||
//#import "../../Support/utlist.h"
|
||||
#import "ccConfig.h"
|
||||
|
||||
//NS_CC_BEGIN;
|
||||
#pragma mark - MouseEventDelegate
|
||||
|
||||
/** MouseEventDelegate protocol.
|
||||
Implement it in your node to receive any of mouse events
|
||||
*/
|
||||
@protocol CCMouseEventDelegate <NSObject>
|
||||
@optional
|
||||
|
||||
//
|
||||
// left
|
||||
//
|
||||
/** called when the "mouseDown" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccMouseDown:(NSEvent*)event;
|
||||
|
||||
/** called when the "mouseDragged" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccMouseDragged:(NSEvent*)event;
|
||||
|
||||
/** called when the "mouseMoved" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
By default, "mouseMoved" is disabled. To enable it, send the "setAcceptsMouseMovedEvents:YES" message to the main window.
|
||||
*/
|
||||
-(BOOL) ccMouseMoved:(NSEvent*)event;
|
||||
|
||||
/** called when the "mouseUp" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccMouseUp:(NSEvent*)event;
|
||||
|
||||
|
||||
//
|
||||
// right
|
||||
//
|
||||
|
||||
/** called when the "rightMouseDown" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccRightMouseDown:(NSEvent*)event;
|
||||
|
||||
/** called when the "rightMouseDragged" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccRightMouseDragged:(NSEvent*)event;
|
||||
|
||||
/** called when the "rightMouseUp" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccRightMouseUp:(NSEvent*)event;
|
||||
|
||||
//
|
||||
// other
|
||||
//
|
||||
|
||||
/** called when the "otherMouseDown" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccOtherMouseDown:(NSEvent*)event;
|
||||
|
||||
/** called when the "otherMouseDragged" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccOtherMouseDragged:(NSEvent*)event;
|
||||
|
||||
/** called when the "otherMouseUp" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccOtherMouseUp:(NSEvent*)event;
|
||||
|
||||
//
|
||||
// scroll wheel
|
||||
//
|
||||
|
||||
/** called when the "scrollWheel" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (BOOL)ccScrollWheel:(NSEvent *)theEvent;
|
||||
|
||||
|
||||
//
|
||||
// enter / exit
|
||||
//
|
||||
|
||||
/** called when the "mouseEntered" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (void)ccMouseEntered:(NSEvent *)theEvent;
|
||||
|
||||
/** called when the "mouseExited" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (void)ccMouseExited:(NSEvent *)theEvent;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - KeyboardEventDelegate
|
||||
|
||||
/** KeyboardEventDelegate protocol.
|
||||
Implement it in your node to receive any of keyboard events
|
||||
*/
|
||||
@protocol CCKeyboardEventDelegate <NSObject>
|
||||
@optional
|
||||
/** called when the "keyUp" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccKeyUp:(NSEvent*)event;
|
||||
|
||||
/** called when the "keyDown" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccKeyDown:(NSEvent*)event;
|
||||
/** called when the "flagsChanged" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
-(BOOL) ccFlagsChanged:(NSEvent*)event;
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark TouchEventDelegate
|
||||
|
||||
/** TouchEventDelegate protocol.
|
||||
Implement it in your node to receive any of touch events
|
||||
*/
|
||||
@protocol CCTouchEventDelegate <NSObject>
|
||||
@optional
|
||||
/** called when the "touchesBegan" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (BOOL)ccTouchesBeganWithEvent:(NSEvent *)event;
|
||||
|
||||
/** called when the "touchesMoved" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (BOOL)ccTouchesMovedWithEvent:(NSEvent *)event;
|
||||
|
||||
/** called when the "touchesEnded" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (BOOL)ccTouchesEndedWithEvent:(NSEvent *)event;
|
||||
|
||||
/** called when the "touchesCancelled" event is received.
|
||||
Return YES to avoid propagating the event to other delegates.
|
||||
*/
|
||||
- (BOOL)ccTouchesCancelledWithEvent:(NSEvent *)event;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - EventDispatcher
|
||||
|
||||
struct _listEntry;
|
||||
|
||||
/** EventDispatcher
|
||||
|
||||
This is object is responsible for dispatching the events:
|
||||
- Mouse events
|
||||
- Keyboard events
|
||||
- Touch events
|
||||
|
||||
Only available on Mac
|
||||
*/
|
||||
@interface CCEventDispatcher : NSObject <CCMacEventDelegate> {
|
||||
|
||||
BOOL dispatchEvents_;
|
||||
|
||||
struct _listEntry *keyboardDelegates_;
|
||||
struct _listEntry *mouseDelegates_;
|
||||
struct _listEntry *touchDelegates_;
|
||||
}
|
||||
|
||||
@property (nonatomic, readwrite) BOOL dispatchEvents;
|
||||
|
||||
|
||||
/** EventDispatcher singleton */
|
||||
+(CCEventDispatcher*) sharedDispatcher;
|
||||
|
||||
#pragma mark EventDispatcher - Mouse
|
||||
|
||||
/** Adds a mouse delegate to the dispatcher's list.
|
||||
Delegates with a lower priority value will be called before higher priority values.
|
||||
All the events will be propgated to all the delegates, unless the one delegate returns YES.
|
||||
|
||||
IMPORTANT: The delegate will be retained.
|
||||
*/
|
||||
-(void) addMouseDelegate:(id<CCMouseEventDelegate>) delegate priority:(NSInteger)priority;
|
||||
|
||||
/** removes a mouse delegate */
|
||||
-(void) removeMouseDelegate:(id) delegate;
|
||||
|
||||
/** Removes all mouse delegates, releasing all the delegates */
|
||||
-(void) removeAllMouseDelegates;
|
||||
|
||||
#pragma mark EventDispatcher - Keyboard
|
||||
|
||||
/** Adds a Keyboard delegate to the dispatcher's list.
|
||||
Delegates with a lower priority value will be called before higher priority values.
|
||||
All the events will be propgated to all the delegates, unless the one delegate returns YES.
|
||||
|
||||
IMPORTANT: The delegate will be retained.
|
||||
*/
|
||||
-(void) addKeyboardDelegate:(id<CCKeyboardEventDelegate>) delegate priority:(NSInteger)priority;
|
||||
|
||||
/** removes a mouse delegate */
|
||||
-(void) removeKeyboardDelegate:(id) delegate;
|
||||
|
||||
/** Removes all mouse delegates, releasing all the delegates */
|
||||
-(void) removeAllKeyboardDelegates;
|
||||
|
||||
#pragma mark EventDispatcher - Touches
|
||||
|
||||
/** Adds a Touch delegate to the dispatcher's list.
|
||||
Delegates with a lower priority value will be called before higher priority values.
|
||||
All the events will be propgated to all the delegates, unless the one delegate returns YES.
|
||||
|
||||
IMPORTANT: The delegate will be retained.
|
||||
*/
|
||||
- (void)addTouchDelegate:(id<CCTouchEventDelegate>)delegate priority:(NSInteger)priority;
|
||||
|
||||
/** Removes a touch delegate */
|
||||
- (void)removeTouchDelegate:(id) delegate;
|
||||
|
||||
/** Removes all touch delegates, releasing all the delegates */
|
||||
- (void)removeAllTouchDelegates;
|
||||
|
||||
#pragma mark EventDispatcher - Dispatch Events
|
||||
|
||||
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
-(void) dispatchQueuedEvents;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
//NS_CC_END;
|
||||
#endif // __CC_EVENT_DISPATCHER_MAC_H__
|
|
@ -1,649 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 Ricardo Quesada
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2011 Zynga Inc.
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
// Only compile this code on Mac. These files should not be included on your iOS project.
|
||||
// But in case they are included, it won't be compiled.
|
||||
#import <Availability.h>
|
||||
|
||||
#import "CCEventDispatcherMac.h"
|
||||
#import "ccConfig.h"
|
||||
#include "utlist.h"
|
||||
|
||||
#include "CCDirector.h"
|
||||
|
||||
//NS_CC_BEGIN;
|
||||
static CCEventDispatcher *sharedDispatcher = nil;
|
||||
|
||||
enum {
|
||||
// mouse
|
||||
kImplementsMouseDown = 1 << 0,
|
||||
kImplementsMouseMoved = 1 << 1,
|
||||
kImplementsMouseDragged = 1 << 2,
|
||||
kImplementsMouseUp = 1 << 3,
|
||||
kImplementsRightMouseDown = 1 << 4,
|
||||
kImplementsRightMouseDragged = 1 << 5,
|
||||
kImplementsRightMouseUp = 1 << 6,
|
||||
kImplementsOtherMouseDown = 1 << 7,
|
||||
kImplementsOtherMouseDragged = 1 << 8,
|
||||
kImplementsOtherMouseUp = 1 << 9,
|
||||
kImplementsScrollWheel = 1 << 10,
|
||||
kImplementsMouseEntered = 1 << 11,
|
||||
kImplementsMouseExited = 1 << 12,
|
||||
|
||||
kImplementsTouchesBegan = 1 << 13,
|
||||
kImplementsTouchesMoved = 1 << 14,
|
||||
kImplementsTouchesEnded = 1 << 15,
|
||||
kImplementsTouchesCancelled = 1 << 16,
|
||||
|
||||
// keyboard
|
||||
kImplementsKeyUp = 1 << 0,
|
||||
kImplementsKeyDown = 1 << 1,
|
||||
kImplementsFlagsChanged = 1 << 2,
|
||||
};
|
||||
|
||||
|
||||
typedef struct _listEntry
|
||||
{
|
||||
struct _listEntry *prev, *next;
|
||||
id delegate;
|
||||
NSInteger priority;
|
||||
NSUInteger flags;
|
||||
} tListEntry;
|
||||
|
||||
|
||||
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
|
||||
#define QUEUE_EVENT_MAX 128
|
||||
struct _eventQueue {
|
||||
SEL selector;
|
||||
NSEvent *event;
|
||||
};
|
||||
|
||||
static struct _eventQueue eventQueue[QUEUE_EVENT_MAX];
|
||||
static int eventQueueCount;
|
||||
|
||||
#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
|
||||
|
||||
@implementation CCEventDispatcher
|
||||
|
||||
@synthesize dispatchEvents=dispatchEvents_;
|
||||
|
||||
|
||||
+(CCEventDispatcher*) sharedDispatcher
|
||||
{
|
||||
@synchronized(self) {
|
||||
if (sharedDispatcher == nil)
|
||||
sharedDispatcher = [[self alloc] init]; // assignment not done here
|
||||
}
|
||||
return sharedDispatcher;
|
||||
}
|
||||
|
||||
+(id) allocWithZone:(NSZone *)zone
|
||||
{
|
||||
@synchronized(self) {
|
||||
NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
|
||||
return [super allocWithZone:zone];
|
||||
}
|
||||
return nil; // on subsequent allocation attempts return nil
|
||||
}
|
||||
|
||||
-(id) init
|
||||
{
|
||||
if( (self = [super init]) )
|
||||
{
|
||||
// events enabled by default
|
||||
dispatchEvents_ = YES;
|
||||
|
||||
// delegates
|
||||
keyboardDelegates_ = nullptr;
|
||||
mouseDelegates_ = nullptr;
|
||||
touchDelegates_ = nullptr;
|
||||
|
||||
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
eventQueueCount = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
#pragma mark EventDispatcher - add / remove delegates
|
||||
|
||||
-(void) addDelegate:(id)delegate priority:(NSInteger)priority flags:(NSUInteger)flags list:(tListEntry**)list
|
||||
{
|
||||
tListEntry *listElement = (tListEntry *)malloc( sizeof(*listElement) );
|
||||
|
||||
listElement->delegate = [delegate retain];
|
||||
listElement->priority = priority;
|
||||
listElement->flags = flags;
|
||||
listElement->next = listElement->prev = nullptr;
|
||||
|
||||
// empty list ?
|
||||
if( ! *list ) {
|
||||
DL_APPEND( *list, listElement );
|
||||
|
||||
} else {
|
||||
BOOL added = NO;
|
||||
|
||||
for( tListEntry *elem = *list; elem ; elem = elem->next ) {
|
||||
if( priority < elem->priority ) {
|
||||
|
||||
if( elem == *list )
|
||||
DL_PREPEND(*list, listElement);
|
||||
else {
|
||||
listElement->next = elem;
|
||||
listElement->prev = elem->prev;
|
||||
|
||||
elem->prev->next = listElement;
|
||||
elem->prev = listElement;
|
||||
}
|
||||
|
||||
added = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Not added? priority has the higher value. Append it.
|
||||
if( !added )
|
||||
DL_APPEND(*list, listElement);
|
||||
}
|
||||
}
|
||||
|
||||
-(void) removeDelegate:(id)delegate fromList:(tListEntry**)list
|
||||
{
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
// updates with priority < 0
|
||||
DL_FOREACH_SAFE( *list, entry, tmp ) {
|
||||
if( entry->delegate == delegate ) {
|
||||
DL_DELETE( *list, entry );
|
||||
[delegate release];
|
||||
free(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void) removeAllDelegatesFromList:(tListEntry**)list
|
||||
{
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( *list, entry, tmp ) {
|
||||
DL_DELETE( *list, entry );
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void) addMouseDelegate:(id<CCMouseEventDelegate>) delegate priority:(NSInteger)priority
|
||||
{
|
||||
NSUInteger flags = 0;
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseDown:)] ? kImplementsMouseDown : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseDragged:)] ? kImplementsMouseDragged : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseMoved:)] ? kImplementsMouseMoved : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseUp:)] ? kImplementsMouseUp : 0 );
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDown:)] ? kImplementsRightMouseDown : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDragged:)] ? kImplementsRightMouseDragged : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccRightMouseUp:)] ? kImplementsRightMouseUp : 0 );
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDown:)] ? kImplementsOtherMouseDown : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDragged:)] ? kImplementsOtherMouseDragged : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseUp:)] ? kImplementsOtherMouseUp : 0 );
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseEntered:)] ? kImplementsMouseEntered : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccMouseExited:)] ? kImplementsMouseExited : 0 );
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccScrollWheel:)] ? kImplementsScrollWheel : 0 );
|
||||
|
||||
[self addDelegate:delegate priority:priority flags:flags list:&mouseDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeMouseDelegate:(id) delegate
|
||||
{
|
||||
[self removeDelegate:delegate fromList:&mouseDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeAllMouseDelegates
|
||||
{
|
||||
[self removeAllDelegatesFromList:&mouseDelegates_];
|
||||
}
|
||||
|
||||
-(void) addKeyboardDelegate:(id<CCKeyboardEventDelegate>) delegate priority:(NSInteger)priority
|
||||
{
|
||||
NSUInteger flags = 0;
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccKeyUp:)] ? kImplementsKeyUp : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccKeyDown:)] ? kImplementsKeyDown : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccFlagsChanged:)] ? kImplementsFlagsChanged : 0 );
|
||||
|
||||
[self addDelegate:delegate priority:priority flags:flags list:&keyboardDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeKeyboardDelegate:(id) delegate
|
||||
{
|
||||
[self removeDelegate:delegate fromList:&keyboardDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeAllKeyboardDelegates
|
||||
{
|
||||
[self removeAllDelegatesFromList:&keyboardDelegates_];
|
||||
}
|
||||
|
||||
-(void) addTouchDelegate:(id<CCTouchEventDelegate>) delegate priority:(NSInteger)priority
|
||||
{
|
||||
NSUInteger flags = 0;
|
||||
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccTouchesBeganWithEvent:)] ? kImplementsTouchesBegan : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccTouchesMovedWithEvent:)] ? kImplementsTouchesMoved : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccTouchesEndedWithEvent:)] ? kImplementsTouchesEnded : 0 );
|
||||
flags |= ( [delegate respondsToSelector:@selector(ccTouchesCancelledWithEvent:)] ? kImplementsTouchesCancelled : 0 );
|
||||
|
||||
[self addDelegate:delegate priority:priority flags:flags list:&touchDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeTouchDelegate:(id) delegate
|
||||
{
|
||||
[self removeDelegate:delegate fromList:&touchDelegates_];
|
||||
}
|
||||
|
||||
-(void) removeAllTouchDelegates
|
||||
{
|
||||
[self removeAllDelegatesFromList:&touchDelegates_];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark EventDispatcher - Mouse events
|
||||
//
|
||||
// Mouse events
|
||||
//
|
||||
|
||||
//
|
||||
// Left
|
||||
//
|
||||
- (void)mouseDown:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseDown ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseDown:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseMoved:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseMoved ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseMoved:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseDragged ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseDragged:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseUp:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseUp ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseUp:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Mouse Right
|
||||
//
|
||||
- (void)rightMouseDown:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsRightMouseDown ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDown:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rightMouseDragged:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsRightMouseDragged ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDragged:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)rightMouseUp:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsRightMouseUp ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccRightMouseUp:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Mouse Other
|
||||
//
|
||||
- (void)otherMouseDown:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsOtherMouseDown ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDown:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)otherMouseDragged:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsOtherMouseDragged ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDragged:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)otherMouseUp:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsOtherMouseUp ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseUp:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Scroll Wheel
|
||||
//
|
||||
- (void)scrollWheel:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsScrollWheel ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccScrollWheel:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Mouse enter / exit
|
||||
- (void)mouseExited:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseEntered ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseEntered:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)mouseEntered:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsMouseExited) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccMouseExited:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark EventDispatcher - Keyboard events
|
||||
|
||||
// Keyboard events
|
||||
- (void)keyDown:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
// cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, true);
|
||||
|
||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsKeyDown ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)keyUp:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
// cocos2d::Director::getInstance()->getKeyboardDispatcher()->dispatchKeyboardEvent(event.keyCode, false);
|
||||
|
||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsKeyUp ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)flagsChanged:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsFlagsChanged ) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccFlagsChanged:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark EventDispatcher - Touch events
|
||||
|
||||
- (void)touchesBeganWithEvent:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsTouchesBegan) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccTouchesBeganWithEvent:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMovedWithEvent:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsTouchesMoved) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccTouchesMovedWithEvent:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEndedWithEvent:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsTouchesEnded) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccTouchesEndedWithEvent:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesCancelledWithEvent:(NSEvent *)event
|
||||
{
|
||||
if( dispatchEvents_ ) {
|
||||
tListEntry *entry, *tmp;
|
||||
|
||||
DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
|
||||
if ( entry->flags & kImplementsTouchesCancelled) {
|
||||
void *swallows = [entry->delegate performSelector:@selector(ccTouchesCancelledWithEvent:) withObject:event];
|
||||
if( swallows )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark EventDispatcher - queue events
|
||||
|
||||
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
-(void) queueEvent:(NSEvent*)event selector:(SEL)selector
|
||||
{
|
||||
NSAssert( eventQueueCount < QUEUE_EVENT_MAX, @"CCEventDispatcher: recompile. Increment QUEUE_EVENT_MAX value");
|
||||
|
||||
@synchronized (self) {
|
||||
eventQueue[eventQueueCount].selector = selector;
|
||||
eventQueue[eventQueueCount].event = [event copy];
|
||||
|
||||
eventQueueCount++;
|
||||
}
|
||||
}
|
||||
|
||||
-(void) dispatchQueuedEvents
|
||||
{
|
||||
@synchronized (self) {
|
||||
for( int i=0; i < eventQueueCount; i++ ) {
|
||||
SEL sel = eventQueue[i].selector;
|
||||
NSEvent *event = eventQueue[i].event;
|
||||
|
||||
[self performSelector:sel withObject:event];
|
||||
|
||||
[event release];
|
||||
}
|
||||
|
||||
eventQueueCount = 0;
|
||||
}
|
||||
}
|
||||
#endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
|
||||
//NS_CC_END;
|
||||
@end
|
|
@ -1,112 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __EAGLVIEW_MAC_H__
|
||||
#define __EAGLVIEW_MAC_H__
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "ccConfig.h"
|
||||
|
||||
//PROTOCOLS:
|
||||
|
||||
@protocol CCMacEventDelegate <NSObject>
|
||||
// Mouse
|
||||
- (void)mouseDown:(NSEvent *)theEvent;
|
||||
- (void)mouseUp:(NSEvent *)theEvent;
|
||||
- (void)mouseMoved:(NSEvent *)theEvent;
|
||||
- (void)mouseDragged:(NSEvent *)theEvent;
|
||||
- (void)rightMouseDown:(NSEvent*)event;
|
||||
- (void)rightMouseDragged:(NSEvent*)event;
|
||||
- (void)rightMouseUp:(NSEvent*)event;
|
||||
- (void)otherMouseDown:(NSEvent*)event;
|
||||
- (void)otherMouseDragged:(NSEvent*)event;
|
||||
- (void)otherMouseUp:(NSEvent*)event;
|
||||
- (void)scrollWheel:(NSEvent *)theEvent;
|
||||
- (void)mouseEntered:(NSEvent *)theEvent;
|
||||
- (void)mouseExited:(NSEvent *)theEvent;
|
||||
|
||||
|
||||
// Keyboard
|
||||
- (void)keyDown:(NSEvent *)theEvent;
|
||||
- (void)keyUp:(NSEvent *)theEvent;
|
||||
- (void)flagsChanged:(NSEvent *)theEvent;
|
||||
|
||||
// Touches
|
||||
- (void)touchesBeganWithEvent:(NSEvent *)event;
|
||||
- (void)touchesMovedWithEvent:(NSEvent *)event;
|
||||
- (void)touchesEndedWithEvent:(NSEvent *)event;
|
||||
- (void)touchesCancelledWithEvent:(NSEvent *)event;
|
||||
|
||||
#if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
|
||||
- (void)queueEvent:(NSEvent*)event selector:(SEL)selector;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
/** MacGLView
|
||||
|
||||
Only available for Mac OS X
|
||||
*/
|
||||
@interface CCEAGLView : NSOpenGLView {
|
||||
id<CCMacEventDelegate> eventDelegate_;
|
||||
|
||||
BOOL isFullScreen_;
|
||||
NSWindow *fullScreenWindow_;
|
||||
|
||||
// cache
|
||||
NSWindow *windowGLView_;
|
||||
NSView *superViewGLView_;
|
||||
NSRect originalWinRect_; // Original size and position
|
||||
|
||||
float frameZoomFactor_;
|
||||
}
|
||||
|
||||
@property (nonatomic, readwrite, assign) id<CCMacEventDelegate> eventDelegate;
|
||||
|
||||
// whether or not the view is in fullscreen mode
|
||||
@property (nonatomic, readonly) BOOL isFullScreen;
|
||||
|
||||
@property (nonatomic, readwrite) float frameZoomFactor;
|
||||
|
||||
/** uses and locks the OpenGL context */
|
||||
-(void) lockOpenGLContext;
|
||||
|
||||
/** unlocks the openGL context */
|
||||
-(void) unlockOpenGLContext;
|
||||
|
||||
/** returns the depth format of the view in BPP */
|
||||
- (NSUInteger) depthFormat;
|
||||
|
||||
- (void) setFrameZoomFactor:(float)frameZoomFactor;
|
||||
|
||||
// get the view object
|
||||
+(id) sharedEGLView;
|
||||
|
||||
-(int) getWidth;
|
||||
-(int) getHeight;
|
||||
|
||||
@end
|
||||
#endif // __EAGLVIEW_MAC_H__
|
||||
|
|
@ -1,166 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2012 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Idea of subclassing NSOpenGLView was taken from "TextureUpload" Apple's sample
|
||||
*/
|
||||
|
||||
#import <Availability.h>
|
||||
|
||||
#import "EAGLView.h"
|
||||
#import "CCEGLView.h"
|
||||
#import <OpenGL/gl.h>
|
||||
#import "CCDirector.h"
|
||||
#import "ccConfig.h"
|
||||
#import "CCSet.h"
|
||||
#import "CCTouch.h"
|
||||
#import "CCIMEDispatcher.h"
|
||||
#import "CCEventDispatcherMac.h"
|
||||
#import "CCEGLView.h"
|
||||
|
||||
|
||||
//USING_NS_CC;
|
||||
static CCEAGLView *view;
|
||||
|
||||
@implementation CCEAGLView
|
||||
|
||||
@synthesize eventDelegate = eventDelegate_, isFullScreen = isFullScreen_, frameZoomFactor=frameZoomFactor_;
|
||||
|
||||
+(id) sharedEGLView
|
||||
{
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
- (void) update
|
||||
{
|
||||
// XXX: Should I do something here ?
|
||||
[super update];
|
||||
}
|
||||
|
||||
- (void) prepareOpenGL
|
||||
{
|
||||
// XXX: Initialize OpenGL context
|
||||
|
||||
[super prepareOpenGL];
|
||||
|
||||
// Make this openGL context current to the thread
|
||||
// (i.e. all openGL on this thread calls will go to this context)
|
||||
[[self openGLContext] makeCurrentContext];
|
||||
|
||||
// Synchronize buffer swaps with vertical refresh rate
|
||||
GLint swapInt = 1;
|
||||
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
|
||||
|
||||
// GLint order = -1;
|
||||
// [[self openGLContext] setValues:&order forParameter:NSOpenGLCPSurfaceOrder];
|
||||
}
|
||||
|
||||
- (NSUInteger) depthFormat
|
||||
{
|
||||
return 24;
|
||||
}
|
||||
|
||||
- (void) setFrameZoomFactor:(float)frameZoomFactor
|
||||
{
|
||||
frameZoomFactor_ = frameZoomFactor;
|
||||
|
||||
NSRect winRect = [[self window] frame];
|
||||
NSRect viewRect = [self frame];
|
||||
|
||||
// compute the margin width and margin height
|
||||
float diffX = winRect.size.width - viewRect.size.width;
|
||||
float diffY = winRect.size.height - viewRect.size.height;
|
||||
|
||||
// new window width and height
|
||||
float newWindowWidth = (int)(viewRect.size.width * frameZoomFactor + diffX);
|
||||
float newWindowHeight = (int)(viewRect.size.height * frameZoomFactor + diffY);
|
||||
|
||||
// display window in the center of the screen
|
||||
NSRect screenRect = [[NSScreen mainScreen] frame];
|
||||
float originX = (screenRect.size.width - newWindowWidth) / 2;
|
||||
float originY = (screenRect.size.height - newWindowHeight) / 2;
|
||||
|
||||
[[self window] setFrame:NSMakeRect(originX, originY, newWindowWidth, newWindowHeight) display:true];
|
||||
}
|
||||
|
||||
- (void) reshape
|
||||
{
|
||||
// We draw on a secondary thread through the display link
|
||||
// When resizing the view, -reshape is called automatically on the main thread
|
||||
// Add a mutex around to avoid the threads accessing the context simultaneously when resizing
|
||||
|
||||
[self lockOpenGLContext];
|
||||
|
||||
// NSRect rect = [self bounds];
|
||||
|
||||
cocos2d::Director *director = cocos2d::Director::getInstance();
|
||||
// CGSize size = NSSizeToCGSize(rect.size);
|
||||
// cocos2d::Size ccsize = cocos2d::Size(size.width, size.height);
|
||||
//director->reshapeProjection(ccsize);
|
||||
|
||||
// avoid flicker
|
||||
director->drawScene();
|
||||
// [self setNeedsDisplay:YES];
|
||||
|
||||
[self unlockOpenGLContext];
|
||||
}
|
||||
|
||||
-(void) lockOpenGLContext
|
||||
{
|
||||
NSOpenGLContext *glContext = [self openGLContext];
|
||||
NSAssert( glContext, @"FATAL: could not get openGL context");
|
||||
|
||||
[glContext makeCurrentContext];
|
||||
CGLLockContext((CGLContextObj)[glContext CGLContextObj]);
|
||||
}
|
||||
|
||||
-(void) unlockOpenGLContext
|
||||
{
|
||||
NSOpenGLContext *glContext = [self openGLContext];
|
||||
NSAssert( glContext, @"FATAL: could not get openGL context");
|
||||
|
||||
CGLUnlockContext((CGLContextObj)[glContext CGLContextObj]);
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
CCLOGINFO("deallocing CCEAGLView: %p", self);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(int) getWidth
|
||||
{
|
||||
NSSize bound = [self bounds].size;
|
||||
return bound.width;
|
||||
}
|
||||
|
||||
-(int) getHeight
|
||||
{
|
||||
NSSize bound = [self bounds].size;
|
||||
return bound.height;
|
||||
}
|
||||
|
||||
@end
|
|
@ -28,10 +28,15 @@
|
|||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
|
||||
#include "CCEditBox.h"
|
||||
#import "EAGLView.h"
|
||||
#define GLFW_EXPOSE_NATIVE_NSGL
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#include "glfw3native.h"
|
||||
|
||||
|
||||
#define getEditBoxImplMac() ((cocos2d::extension::EditBoxImplMac*)editBox_)
|
||||
|
||||
|
||||
|
||||
@implementation CCCustomNSTextField
|
||||
|
||||
- (CGRect)textRectForBounds:(CGRect)bounds {
|
||||
|
@ -58,6 +63,10 @@
|
|||
@synthesize editState = editState_;
|
||||
@synthesize editBox = editBox_;
|
||||
|
||||
- (id) getNSWindow {
|
||||
return glfwGetCocoaWindow(cocos2d::EGLView::getInstance()->getWindow());
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[textField_ resignFirstResponder];
|
||||
|
@ -84,7 +93,7 @@
|
|||
[textField_ setDelegate:self];
|
||||
self.editBox = editBox;
|
||||
|
||||
[[CCEAGLView sharedEGLView] addSubview:textField_];
|
||||
[[[self getNSWindow] contentView] addSubview:textField_];
|
||||
|
||||
return self;
|
||||
}while(0);
|
||||
|
@ -94,8 +103,7 @@
|
|||
|
||||
-(void) doAnimationWhenKeyboardMoveWithDuration:(float)duration distance:(float)distance
|
||||
{
|
||||
id eglView = [CCEAGLView sharedEGLView];
|
||||
[eglView doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
|
||||
[[[self getNSWindow] contentView] doAnimationWhenKeyboardMoveWithDuration:duration distance:distance];
|
||||
}
|
||||
|
||||
-(void) setPosition:(NSPoint) pos
|
||||
|
|
Loading…
Reference in New Issue