Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * cocos2d for iPhone: http://www.cocos2d-iphone.org
- *
- * Copyright (c) 2010 Ricardo Quesada
- * Copyright (c) 2011 Zynga Inc.
- *
- * 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 "CCEventDispatcher.h"
- #import "ccConfig.h"
- #include "support/data_support/utlist.h"
- #include "CCDirector.h"
- //NS_CC_BEGIN;
- static CCEventDispatcher *sharedDispatcher = nil;
- enum {
- // mouse
- kCCImplementsMouseDown = 1 << 0,
- kCCImplementsMouseMoved = 1 << 1,
- kCCImplementsMouseDragged = 1 << 2,
- kCCImplementsMouseUp = 1 << 3,
- kCCImplementsRightMouseDown = 1 << 4,
- kCCImplementsRightMouseDragged = 1 << 5,
- kCCImplementsRightMouseUp = 1 << 6,
- kCCImplementsOtherMouseDown = 1 << 7,
- kCCImplementsOtherMouseDragged = 1 << 8,
- kCCImplementsOtherMouseUp = 1 << 9,
- kCCImplementsScrollWheel = 1 << 10,
- kCCImplementsMouseEntered = 1 << 11,
- kCCImplementsMouseExited = 1 << 12,
- kCCImplementsTouchesBegan = 1 << 13,
- kCCImplementsTouchesMoved = 1 << 14,
- kCCImplementsTouchesEnded = 1 << 15,
- kCCImplementsTouchesCancelled = 1 << 16,
- // keyboard
- kCCImplementsKeyUp = 1 << 0,
- kCCImplementsKeyDown = 1 << 1,
- kCCImplementsFlagsChanged = 1 << 2,
- };
- // MAC KEYS
- enum {
- kVK_ANSI_A = 0x00,
- kVK_ANSI_S = 0x01,
- kVK_ANSI_D = 0x02,
- kVK_ANSI_F = 0x03,
- kVK_ANSI_H = 0x04,
- kVK_ANSI_G = 0x05,
- kVK_ANSI_Z = 0x06,
- kVK_ANSI_X = 0x07,
- kVK_ANSI_C = 0x08,
- kVK_ANSI_V = 0x09,
- kVK_ANSI_B = 0x0B,
- kVK_ANSI_Q = 0x0C,
- kVK_ANSI_W = 0x0D,
- kVK_ANSI_E = 0x0E,
- kVK_ANSI_R = 0x0F,
- kVK_ANSI_Y = 0x10,
- kVK_ANSI_T = 0x11,
- kVK_ANSI_1 = 0x12,
- kVK_ANSI_2 = 0x13,
- kVK_ANSI_3 = 0x14,
- kVK_ANSI_4 = 0x15,
- kVK_ANSI_6 = 0x16,
- kVK_ANSI_5 = 0x17,
- kVK_ANSI_Equal = 0x18,
- kVK_ANSI_9 = 0x19,
- kVK_ANSI_7 = 0x1A,
- kVK_ANSI_Minus = 0x1B,
- kVK_ANSI_8 = 0x1C,
- kVK_ANSI_0 = 0x1D,
- kVK_ANSI_RightBracket = 0x1E,
- kVK_ANSI_O = 0x1F,
- kVK_ANSI_U = 0x20,
- kVK_ANSI_LeftBracket = 0x21,
- kVK_ANSI_I = 0x22,
- kVK_ANSI_P = 0x23,
- kVK_ANSI_L = 0x25,
- kVK_ANSI_J = 0x26,
- kVK_ANSI_Quote = 0x27,
- kVK_ANSI_K = 0x28,
- kVK_ANSI_Semicolon = 0x29,
- kVK_ANSI_Backslash = 0x2A,
- kVK_ANSI_Comma = 0x2B,
- kVK_ANSI_Slash = 0x2C,
- kVK_ANSI_N = 0x2D,
- kVK_ANSI_M = 0x2E,
- kVK_ANSI_Period = 0x2F,
- kVK_ANSI_Grave = 0x32,
- kVK_ANSI_KeypadDecimal = 0x41,
- kVK_ANSI_KeypadMultiply = 0x43,
- kVK_ANSI_KeypadPlus = 0x45,
- kVK_ANSI_KeypadClear = 0x47,
- kVK_ANSI_KeypadDivide = 0x4B,
- kVK_ANSI_KeypadEnter = 0x4C,
- kVK_ANSI_KeypadMinus = 0x4E,
- kVK_ANSI_KeypadEquals = 0x51,
- kVK_ANSI_Keypad0 = 0x52,
- kVK_ANSI_Keypad1 = 0x53,
- kVK_ANSI_Keypad2 = 0x54,
- kVK_ANSI_Keypad3 = 0x55,
- kVK_ANSI_Keypad4 = 0x56,
- kVK_ANSI_Keypad5 = 0x57,
- kVK_ANSI_Keypad6 = 0x58,
- kVK_ANSI_Keypad7 = 0x59,
- kVK_ANSI_Keypad8 = 0x5B,
- kVK_ANSI_Keypad9 = 0x5C
- };
- /* keycodes for keys that are independent of keyboard layout*/
- enum {
- kVK_Return = 0x24,
- kVK_Tab = 0x30,
- kVK_Space = 0x31,
- kVK_Delete = 0x33,
- kVK_Escape = 0x35,
- kVK_Command = 0x37,
- kVK_Shift = 0x38,
- kVK_CapsLock = 0x39,
- kVK_Option = 0x3A,
- kVK_Control = 0x3B,
- kVK_RightShift = 0x3C,
- kVK_RightOption = 0x3D,
- kVK_RightControl = 0x3E,
- kVK_Function = 0x3F,
- kVK_F17 = 0x40,
- kVK_VolumeUp = 0x48,
- kVK_VolumeDown = 0x49,
- kVK_Mute = 0x4A,
- kVK_F18 = 0x4F,
- kVK_F19 = 0x50,
- kVK_F20 = 0x5A,
- kVK_F5 = 0x60,
- kVK_F6 = 0x61,
- kVK_F7 = 0x62,
- kVK_F3 = 0x63,
- kVK_F8 = 0x64,
- kVK_F9 = 0x65,
- kVK_F11 = 0x67,
- kVK_F13 = 0x69,
- kVK_F16 = 0x6A,
- kVK_F14 = 0x6B,
- kVK_F10 = 0x6D,
- kVK_F12 = 0x6F,
- kVK_F15 = 0x71,
- kVK_Help = 0x72,
- kVK_Home = 0x73,
- kVK_PageUp = 0x74,
- kVK_ForwardDelete = 0x75,
- kVK_F4 = 0x76,
- kVK_End = 0x77,
- kVK_F2 = 0x78,
- kVK_PageDown = 0x79,
- kVK_F1 = 0x7A,
- kVK_LeftArrow = 0x7B,
- kVK_RightArrow = 0x7C,
- kVK_DownArrow = 0x7D,
- kVK_UpArrow = 0x7E
- };
- // MAC KEYS
- 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_ = NULL;
- mouseDelegates_ = NULL;
- touchDelegates_ = NULL;
- #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
- eventQueueCount = 0;
- #endif
- }
- return self;
- }
- - (void) dealloc
- {
- [super dealloc];
- }
- #pragma mark CCEventDispatcher - 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 = NULL;
- // 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:)] ? kCCImplementsMouseDown : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccMouseDragged:)] ? kCCImplementsMouseDragged : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccMouseMoved:)] ? kCCImplementsMouseMoved : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccMouseUp:)] ? kCCImplementsMouseUp : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDown:)] ? kCCImplementsRightMouseDown : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDragged:)] ? kCCImplementsRightMouseDragged : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccRightMouseUp:)] ? kCCImplementsRightMouseUp : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDown:)] ? kCCImplementsOtherMouseDown : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDragged:)] ? kCCImplementsOtherMouseDragged : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseUp:)] ? kCCImplementsOtherMouseUp : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccMouseEntered:)] ? kCCImplementsMouseEntered : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccMouseExited:)] ? kCCImplementsMouseExited : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccScrollWheel:)] ? kCCImplementsScrollWheel : 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:)] ? kCCImplementsKeyUp : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccKeyDown:)] ? kCCImplementsKeyDown : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccFlagsChanged:)] ? kCCImplementsFlagsChanged : 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:)] ? kCCImplementsTouchesBegan : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccTouchesMovedWithEvent:)] ? kCCImplementsTouchesMoved : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccTouchesEndedWithEvent:)] ? kCCImplementsTouchesEnded : 0 );
- flags |= ( [delegate respondsToSelector:@selector(ccTouchesCancelledWithEvent:)] ? kCCImplementsTouchesCancelled : 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 CCEventDispatcher - Mouse events
- //
- // Mouse events
- //
- //
- // Left
- //
- - (void)mouseDown:(NSEvent *)event
- {
- if( dispatchEvents_ ) {
- tListEntry *entry, *tmp;
- DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
- if ( entry->flags & kCCImplementsMouseDown ) {
- 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 & kCCImplementsMouseMoved ) {
- 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 & kCCImplementsMouseDragged ) {
- 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 & kCCImplementsMouseUp ) {
- 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 & kCCImplementsRightMouseDown ) {
- 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 & kCCImplementsRightMouseDragged ) {
- 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 & kCCImplementsRightMouseUp ) {
- 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 & kCCImplementsOtherMouseDown ) {
- 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 & kCCImplementsOtherMouseDragged ) {
- 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 & kCCImplementsOtherMouseUp ) {
- 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 & kCCImplementsScrollWheel ) {
- 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 & kCCImplementsMouseEntered ) {
- 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 & kCCImplementsMouseExited) {
- void *swallows = [entry->delegate performSelector:@selector(ccMouseExited:) withObject:event];
- if( swallows )
- break;
- }
- }
- }
- }
- #pragma mark CCEventDispatcher - Keyboard events
- // Keyboard events
- - (void)keyDown:(NSEvent *)event
- {
- // HACK STARTS
- switch ([event keyCode]) {
- case kVK_UpArrow: cocos2d::CCDirector::sharedDirector()->upArrowKeyDown = true; break;
- case kVK_DownArrow: cocos2d::CCDirector::sharedDirector()->downArrowKeyDown = true; break;
- case kVK_LeftArrow: cocos2d::CCDirector::sharedDirector()->leftArrowKeyDown = true; break;
- case kVK_RightArrow: cocos2d::CCDirector::sharedDirector()->rightArrowKeyDown = true; break;
- case kVK_Space: cocos2d::CCDirector::sharedDirector()->spaceBarDown = true; break;
- case kVK_ANSI_B: cocos2d::CCDirector::sharedDirector()->bKeyDown = true; break;
- case kVK_ANSI_1:
- cocos2d::CCDirector::sharedDirector()->numberOneDown = true;
- break;
- case kVK_ANSI_2:
- cocos2d::CCDirector::sharedDirector()->numberTwoDown = true;
- break;
- case kVK_ANSI_3:
- cocos2d::CCDirector::sharedDirector()->numberThreeDown = true;
- break;
- case kVK_ANSI_4:
- cocos2d::CCDirector::sharedDirector()->numberFourDown = true;
- break;
- case kVK_ANSI_5:
- cocos2d::CCDirector::sharedDirector()->numberFiveDown = true;
- break;
- case kVK_ANSI_6:
- cocos2d::CCDirector::sharedDirector()->numberSixDown = true;
- break;
- }
- // HACK ENDS
- if( dispatchEvents_ ) {
- tListEntry *entry, *tmp;
- DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
- if ( entry->flags & kCCImplementsKeyDown ) {
- void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event];
- if( swallows )
- break;
- }
- }
- }
- }
- - (void)keyUp:(NSEvent *)event
- {
- // HACK STARTS
- switch ([event keyCode]) {
- case kVK_UpArrow: cocos2d::CCDirector::sharedDirector()->upArrowKeyDown = false; break;
- case kVK_DownArrow: cocos2d::CCDirector::sharedDirector()->downArrowKeyDown = false; break;
- case kVK_LeftArrow: cocos2d::CCDirector::sharedDirector()->leftArrowKeyDown = false; break;
- case kVK_RightArrow: cocos2d::CCDirector::sharedDirector()->rightArrowKeyDown = false; break;
- case kVK_Space: cocos2d::CCDirector::sharedDirector()->spaceBarDown = false; break;
- case kVK_ANSI_B: cocos2d::CCDirector::sharedDirector()->bKeyDown = false; break;
- case kVK_ANSI_1:
- cocos2d::CCDirector::sharedDirector()->numberOneDown = false;
- cocos2d::CCDirector::sharedDirector()->numberOnePressed = true;
- break;
- case kVK_ANSI_2:
- cocos2d::CCDirector::sharedDirector()->numberTwoDown = false;
- cocos2d::CCDirector::sharedDirector()->numberTwoPressed = true;
- break;
- case kVK_ANSI_3:
- cocos2d::CCDirector::sharedDirector()->numberThreeDown = false;
- cocos2d::CCDirector::sharedDirector()->numberThreePressed = true;
- break;
- case kVK_ANSI_4:
- cocos2d::CCDirector::sharedDirector()->numberFourDown = false;
- cocos2d::CCDirector::sharedDirector()->numberFourPressed = true;
- break;
- case kVK_ANSI_5:
- cocos2d::CCDirector::sharedDirector()->numberFiveDown = false;
- cocos2d::CCDirector::sharedDirector()->numberFivePressed = true;
- break;
- case kVK_ANSI_6:
- cocos2d::CCDirector::sharedDirector()->numberSixDown = false;
- cocos2d::CCDirector::sharedDirector()->numberSixPressed = true;
- break;
- }
- // HACK ENDS
- if( dispatchEvents_ ) {
- tListEntry *entry, *tmp;
- DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
- if ( entry->flags & kCCImplementsKeyUp ) {
- 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 & kCCImplementsFlagsChanged ) {
- void *swallows = [entry->delegate performSelector:@selector(ccFlagsChanged:) withObject:event];
- if( swallows )
- break;
- }
- }
- }
- }
- #pragma mark CCEventDispatcher - Touch events
- - (void)touchesBeganWithEvent:(NSEvent *)event
- {
- if( dispatchEvents_ ) {
- tListEntry *entry, *tmp;
- DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
- if ( entry->flags & kCCImplementsTouchesBegan) {
- 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 & kCCImplementsTouchesMoved) {
- 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 & kCCImplementsTouchesEnded) {
- 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 & kCCImplementsTouchesCancelled) {
- void *swallows = [entry->delegate performSelector:@selector(ccTouchesCancelledWithEvent:) withObject:event];
- if( swallows )
- break;
- }
- }
- }
- }
- #pragma mark CCEventDispatcher - 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement