Advertisement
Guest User

CCEventDispatcher.mm

a guest
May 31st, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.16 KB | None | 0 0
  1. /*
  2.  * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3.  *
  4.  * Copyright (c) 2010 Ricardo Quesada
  5.  * Copyright (c) 2011 Zynga Inc.
  6.  *
  7.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  8.  * of this software and associated documentation files (the "Software"), to deal
  9.  * in the Software without restriction, including without limitation the rights
  10.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11.  * copies of the Software, and to permit persons to whom the Software is
  12.  * furnished to do so, subject to the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice shall be included in
  15.  * all copies or substantial portions of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23.  * THE SOFTWARE.
  24.  */
  25.  
  26. // Only compile this code on Mac. These files should not be included on your iOS project.
  27. // But in case they are included, it won't be compiled.
  28. #import <Availability.h>
  29.  
  30. #import "CCEventDispatcher.h"
  31. #import "ccConfig.h"
  32. #include "support/data_support/utlist.h"
  33. #include "CCDirector.h"
  34. #include "keyboard_dispatcher/CCKeyboardDispatcher.h"
  35.  
  36. //NS_CC_BEGIN;
  37. static CCEventDispatcher *sharedDispatcher = nil;
  38.  
  39. enum  {
  40.     // mouse
  41.     kCCImplementsMouseDown          = 1 << 0,
  42.     kCCImplementsMouseMoved         = 1 << 1,
  43.     kCCImplementsMouseDragged       = 1 << 2,  
  44.     kCCImplementsMouseUp            = 1 << 3,
  45.     kCCImplementsRightMouseDown     = 1 << 4,
  46.     kCCImplementsRightMouseDragged  = 1 << 5,
  47.     kCCImplementsRightMouseUp       = 1 << 6,
  48.     kCCImplementsOtherMouseDown     = 1 << 7,
  49.     kCCImplementsOtherMouseDragged  = 1 << 8,
  50.     kCCImplementsOtherMouseUp       = 1 << 9,
  51.     kCCImplementsScrollWheel        = 1 << 10,
  52.     kCCImplementsMouseEntered       = 1 << 11,
  53.     kCCImplementsMouseExited        = 1 << 12,
  54.  
  55.     kCCImplementsTouchesBegan       = 1 << 13,
  56.     kCCImplementsTouchesMoved       = 1 << 14,
  57.     kCCImplementsTouchesEnded       = 1 << 15,
  58.     kCCImplementsTouchesCancelled           = 1 << 16,
  59.  
  60.     // keyboard
  61.     kCCImplementsKeyUp              = 1 << 0,
  62.     kCCImplementsKeyDown            = 1 << 1,
  63.     kCCImplementsFlagsChanged       = 1 << 2,
  64. };
  65.  
  66.  
  67. typedef struct _listEntry
  68. {
  69.     struct  _listEntry  *prev, *next;
  70.     id                  delegate;
  71.     NSInteger           priority;
  72.     NSUInteger          flags;
  73. } tListEntry;
  74.  
  75.  
  76. #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
  77.  
  78. #define QUEUE_EVENT_MAX 128
  79. struct _eventQueue {
  80.     SEL     selector;
  81.     NSEvent *event;
  82. };
  83.  
  84. static struct   _eventQueue eventQueue[QUEUE_EVENT_MAX];
  85. static int      eventQueueCount;
  86.  
  87. #endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
  88.  
  89.  
  90. @implementation CCEventDispatcher
  91.  
  92. @synthesize dispatchEvents=dispatchEvents_;
  93.  
  94.  
  95. +(CCEventDispatcher*) sharedDispatcher
  96. {
  97.     @synchronized(self) {
  98.         if (sharedDispatcher == nil)
  99.             sharedDispatcher = [[self alloc] init]; // assignment not done here
  100.     }
  101.     return sharedDispatcher;
  102. }
  103.  
  104. +(id) allocWithZone:(NSZone *)zone
  105. {
  106.     @synchronized(self) {
  107.         NSAssert(sharedDispatcher == nil, @"Attempted to allocate a second instance of a singleton.");
  108.         return [super allocWithZone:zone];
  109.     }
  110.     return nil; // on subsequent allocation attempts return nil
  111. }
  112.  
  113. -(id) init
  114. {
  115.     if( (self = [super init]) )
  116.     {
  117.         // events enabled by default
  118.         dispatchEvents_ = YES;
  119.  
  120.         // delegates
  121.         keyboardDelegates_ = NULL;
  122.         mouseDelegates_ = NULL;
  123.                 touchDelegates_ = NULL;
  124.        
  125. #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
  126.         eventQueueCount = 0;
  127. #endif
  128.     }
  129.    
  130.     return self;
  131. }
  132.  
  133. - (void) dealloc
  134. {
  135.     [super dealloc];
  136. }
  137.  
  138. #pragma mark CCEventDispatcher - add / remove delegates
  139.  
  140. -(void) addDelegate:(id)delegate priority:(NSInteger)priority flags:(NSUInteger)flags list:(tListEntry**)list
  141. {
  142.     tListEntry *listElement = (tListEntry *)malloc( sizeof(*listElement) );
  143.    
  144.     listElement->delegate = [delegate retain];
  145.     listElement->priority = priority;
  146.     listElement->flags = flags;
  147.     listElement->next = listElement->prev = NULL;
  148.    
  149.     // empty list ?
  150.     if( ! *list ) {
  151.         DL_APPEND( *list, listElement );
  152.        
  153.     } else {
  154.         BOOL added = NO;       
  155.        
  156.         for( tListEntry *elem = *list; elem ; elem = elem->next ) {
  157.             if( priority < elem->priority ) {
  158.                
  159.                 if( elem == *list )
  160.                     DL_PREPEND(*list, listElement);
  161.                 else {
  162.                     listElement->next = elem;
  163.                     listElement->prev = elem->prev;
  164.                    
  165.                     elem->prev->next = listElement;
  166.                     elem->prev = listElement;
  167.                 }
  168.                
  169.                 added = YES;
  170.                 break;
  171.             }
  172.         }
  173.        
  174.         // Not added? priority has the higher value. Append it.
  175.         if( !added )
  176.             DL_APPEND(*list, listElement);
  177.     }
  178. }
  179.  
  180. -(void) removeDelegate:(id)delegate fromList:(tListEntry**)list
  181. {
  182.     tListEntry *entry, *tmp;
  183.    
  184.     // updates with priority < 0
  185.     DL_FOREACH_SAFE( *list, entry, tmp ) {
  186.         if( entry->delegate == delegate ) {
  187.             DL_DELETE( *list, entry );
  188.             [delegate release];
  189.             free(entry);
  190.             break;
  191.         }
  192.     }
  193. }
  194.  
  195. -(void) removeAllDelegatesFromList:(tListEntry**)list
  196. {
  197.     tListEntry *entry, *tmp;
  198.  
  199.     DL_FOREACH_SAFE( *list, entry, tmp ) {
  200.         DL_DELETE( *list, entry );
  201.         free(entry);
  202.     }
  203. }
  204.  
  205.  
  206. -(void) addMouseDelegate:(id<CCMouseEventDelegate>) delegate priority:(NSInteger)priority
  207. {
  208.     NSUInteger flags = 0;
  209.    
  210.     flags |= ( [delegate respondsToSelector:@selector(ccMouseDown:)] ? kCCImplementsMouseDown : 0 );
  211.     flags |= ( [delegate respondsToSelector:@selector(ccMouseDragged:)] ? kCCImplementsMouseDragged : 0 );
  212.     flags |= ( [delegate respondsToSelector:@selector(ccMouseMoved:)] ? kCCImplementsMouseMoved : 0 );
  213.     flags |= ( [delegate respondsToSelector:@selector(ccMouseUp:)] ? kCCImplementsMouseUp : 0 );
  214.  
  215.     flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDown:)] ? kCCImplementsRightMouseDown : 0 );
  216.     flags |= ( [delegate respondsToSelector:@selector(ccRightMouseDragged:)] ? kCCImplementsRightMouseDragged : 0 );
  217.     flags |= ( [delegate respondsToSelector:@selector(ccRightMouseUp:)] ? kCCImplementsRightMouseUp : 0 );
  218.  
  219.     flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDown:)] ? kCCImplementsOtherMouseDown : 0 );
  220.     flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseDragged:)] ? kCCImplementsOtherMouseDragged : 0 );
  221.     flags |= ( [delegate respondsToSelector:@selector(ccOtherMouseUp:)] ? kCCImplementsOtherMouseUp : 0 );
  222.  
  223.     flags |= ( [delegate respondsToSelector:@selector(ccMouseEntered:)] ? kCCImplementsMouseEntered : 0 );
  224.     flags |= ( [delegate respondsToSelector:@selector(ccMouseExited:)] ? kCCImplementsMouseExited : 0 );
  225.  
  226.     flags |= ( [delegate respondsToSelector:@selector(ccScrollWheel:)] ? kCCImplementsScrollWheel : 0 );
  227.  
  228.     [self addDelegate:delegate priority:priority flags:flags list:&mouseDelegates_];
  229. }
  230.  
  231. -(void) removeMouseDelegate:(id) delegate
  232. {
  233.     [self removeDelegate:delegate fromList:&mouseDelegates_];
  234. }
  235.  
  236. -(void) removeAllMouseDelegates
  237. {
  238.     [self removeAllDelegatesFromList:&mouseDelegates_];
  239. }
  240.  
  241. -(void) addKeyboardDelegate:(id<CCKeyboardEventDelegate>) delegate priority:(NSInteger)priority
  242. {
  243.     NSUInteger flags = 0;
  244.    
  245.     flags |= ( [delegate respondsToSelector:@selector(ccKeyUp:)] ? kCCImplementsKeyUp : 0 );
  246.     flags |= ( [delegate respondsToSelector:@selector(ccKeyDown:)] ? kCCImplementsKeyDown : 0 );
  247.     flags |= ( [delegate respondsToSelector:@selector(ccFlagsChanged:)] ? kCCImplementsFlagsChanged : 0 );
  248.    
  249.     [self addDelegate:delegate priority:priority flags:flags list:&keyboardDelegates_];
  250. }
  251.  
  252. -(void) removeKeyboardDelegate:(id) delegate
  253. {
  254.     [self removeDelegate:delegate fromList:&keyboardDelegates_];
  255. }
  256.  
  257. -(void) removeAllKeyboardDelegates
  258. {
  259.     [self removeAllDelegatesFromList:&keyboardDelegates_];
  260. }
  261.  
  262. -(void) addTouchDelegate:(id<CCTouchEventDelegate>) delegate priority:(NSInteger)priority
  263. {
  264.     NSUInteger flags = 0;
  265.    
  266.     flags |= ( [delegate respondsToSelector:@selector(ccTouchesBeganWithEvent:)] ? kCCImplementsTouchesBegan : 0 );
  267.     flags |= ( [delegate respondsToSelector:@selector(ccTouchesMovedWithEvent:)] ? kCCImplementsTouchesMoved : 0 );
  268.     flags |= ( [delegate respondsToSelector:@selector(ccTouchesEndedWithEvent:)] ? kCCImplementsTouchesEnded : 0 );
  269.     flags |= ( [delegate respondsToSelector:@selector(ccTouchesCancelledWithEvent:)] ? kCCImplementsTouchesCancelled : 0 );
  270.    
  271.     [self addDelegate:delegate priority:priority flags:flags list:&touchDelegates_];
  272. }
  273.  
  274. -(void) removeTouchDelegate:(id) delegate
  275. {
  276.     [self removeDelegate:delegate fromList:&touchDelegates_];
  277. }
  278.  
  279. -(void) removeAllTouchDelegates
  280. {
  281.     [self removeAllDelegatesFromList:&touchDelegates_];
  282. }
  283.  
  284.  
  285. #pragma mark CCEventDispatcher - Mouse events
  286. //
  287. // Mouse events
  288. //
  289.  
  290. //
  291. // Left
  292. //
  293. - (void)mouseDown:(NSEvent *)event
  294. {
  295.     if( dispatchEvents_ ) {
  296.         tListEntry *entry, *tmp;
  297.  
  298.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  299.             if ( entry->flags & kCCImplementsMouseDown ) {
  300.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseDown:) withObject:event];
  301.                 if( swallows )
  302.                     break;
  303.             }
  304.         }
  305.     }
  306. }
  307.  
  308. - (void)mouseMoved:(NSEvent *)event
  309. {
  310.     if( dispatchEvents_ ) {
  311.         tListEntry *entry, *tmp;
  312.        
  313.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  314.             if ( entry->flags & kCCImplementsMouseMoved ) {
  315.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseMoved:) withObject:event];
  316.                 if( swallows )
  317.                     break;
  318.             }
  319.         }
  320.     }
  321. }
  322.  
  323. - (void)mouseDragged:(NSEvent *)event
  324. {
  325.     if( dispatchEvents_ ) {
  326.         tListEntry *entry, *tmp;
  327.        
  328.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  329.             if ( entry->flags & kCCImplementsMouseDragged ) {
  330.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseDragged:) withObject:event];
  331.                 if( swallows )
  332.                     break;
  333.             }
  334.         }
  335.     }
  336. }
  337.  
  338. - (void)mouseUp:(NSEvent *)event
  339. {
  340.     if( dispatchEvents_ ) {
  341.         tListEntry *entry, *tmp;
  342.        
  343.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  344.             if ( entry->flags & kCCImplementsMouseUp ) {
  345.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseUp:) withObject:event];
  346.                 if( swallows )
  347.                     break;
  348.             }
  349.         }
  350.     }
  351. }
  352.  
  353. //
  354. // Mouse Right
  355. //
  356. - (void)rightMouseDown:(NSEvent *)event
  357. {
  358.     if( dispatchEvents_ ) {
  359.         tListEntry *entry, *tmp;
  360.        
  361.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  362.             if ( entry->flags & kCCImplementsRightMouseDown ) {
  363.                 void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDown:) withObject:event];
  364.                 if( swallows )
  365.                     break;
  366.             }
  367.         }
  368.     }
  369. }
  370.  
  371. - (void)rightMouseDragged:(NSEvent *)event
  372. {
  373.     if( dispatchEvents_ ) {
  374.         tListEntry *entry, *tmp;
  375.        
  376.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  377.             if ( entry->flags & kCCImplementsRightMouseDragged ) {
  378.                 void *swallows = [entry->delegate performSelector:@selector(ccRightMouseDragged:) withObject:event];
  379.                 if( swallows )
  380.                     break;
  381.             }
  382.         }
  383.     }
  384. }
  385.  
  386. - (void)rightMouseUp:(NSEvent *)event
  387. {
  388.     if( dispatchEvents_ ) {
  389.         tListEntry *entry, *tmp;
  390.        
  391.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  392.             if ( entry->flags & kCCImplementsRightMouseUp ) {
  393.                 void *swallows = [entry->delegate performSelector:@selector(ccRightMouseUp:) withObject:event];
  394.                 if( swallows )
  395.                     break;
  396.             }
  397.         }
  398.     }
  399. }
  400.  
  401. //
  402. // Mouse Other
  403. //
  404. - (void)otherMouseDown:(NSEvent *)event
  405. {
  406.     if( dispatchEvents_ ) {
  407.         tListEntry *entry, *tmp;
  408.        
  409.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  410.             if ( entry->flags & kCCImplementsOtherMouseDown ) {
  411.                 void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDown:) withObject:event];
  412.                 if( swallows )
  413.                     break;
  414.             }
  415.         }
  416.     }
  417. }
  418.  
  419. - (void)otherMouseDragged:(NSEvent *)event
  420. {
  421.     if( dispatchEvents_ ) {
  422.         tListEntry *entry, *tmp;
  423.        
  424.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  425.             if ( entry->flags & kCCImplementsOtherMouseDragged ) {
  426.                 void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseDragged:) withObject:event];
  427.                 if( swallows )
  428.                     break;
  429.             }
  430.         }
  431.     }
  432. }
  433.  
  434. - (void)otherMouseUp:(NSEvent *)event
  435. {
  436.     if( dispatchEvents_ ) {
  437.         tListEntry *entry, *tmp;
  438.        
  439.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  440.             if ( entry->flags & kCCImplementsOtherMouseUp ) {
  441.                 void *swallows = [entry->delegate performSelector:@selector(ccOtherMouseUp:) withObject:event];
  442.                 if( swallows )
  443.                     break;
  444.             }
  445.         }
  446.     }
  447. }
  448.  
  449. //
  450. // Scroll Wheel
  451. //
  452. - (void)scrollWheel:(NSEvent *)event
  453. {
  454.     if( dispatchEvents_ ) {
  455.         tListEntry *entry, *tmp;
  456.        
  457.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  458.             if ( entry->flags & kCCImplementsScrollWheel ) {
  459.                 void *swallows = [entry->delegate performSelector:@selector(ccScrollWheel:) withObject:event];
  460.                 if( swallows )
  461.                     break;
  462.             }
  463.         }
  464.     }
  465. }
  466.  
  467. //
  468. // Mouse enter / exit
  469. - (void)mouseExited:(NSEvent *)event
  470. {
  471.     if( dispatchEvents_ ) {
  472.         tListEntry *entry, *tmp;
  473.        
  474.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  475.             if ( entry->flags & kCCImplementsMouseEntered ) {
  476.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseEntered:) withObject:event];
  477.                 if( swallows )
  478.                     break;
  479.             }
  480.         }
  481.     }  
  482. }
  483.  
  484. - (void)mouseEntered:(NSEvent *)event
  485. {
  486.     if( dispatchEvents_ ) {
  487.         tListEntry *entry, *tmp;
  488.        
  489.         DL_FOREACH_SAFE( mouseDelegates_, entry, tmp ) {
  490.             if ( entry->flags & kCCImplementsMouseExited) {
  491.                 void *swallows = [entry->delegate performSelector:@selector(ccMouseExited:) withObject:event];
  492.                 if( swallows )
  493.                     break;
  494.             }
  495.         }
  496.     }  
  497. }
  498.  
  499.  
  500. #pragma mark CCEventDispatcher - Keyboard events
  501.  
  502. // Keyboard events
  503. - (void)keyDown:(NSEvent *)event
  504. {
  505.     if( dispatchEvents_ ) {
  506.         tListEntry *entry, *tmp;
  507.              
  508.         cocos2d::CCKeyboardDispatcher *kbDisp = cocos2d::CCDirector::sharedDirector()->getKeyboardDispatcher();
  509.         kbDisp->dispatchKeyboardEvent(event.keyCode, true);
  510.        
  511.         DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
  512.             if ( entry->flags & kCCImplementsKeyDown ) {
  513.                 void *swallows = [entry->delegate performSelector:@selector(ccKeyDown:) withObject:event];
  514.                 if( swallows )
  515.                     break;
  516.             }
  517.         }
  518.     }
  519. }
  520.  
  521. - (void)keyUp:(NSEvent *)event
  522. {
  523.     if( dispatchEvents_ ) {
  524.         tListEntry *entry, *tmp;
  525.        
  526.         cocos2d::CCKeyboardDispatcher *kbDisp = cocos2d::CCDirector::sharedDirector()->getKeyboardDispatcher();
  527.         kbDisp->dispatchKeyboardEvent(event.keyCode, false);
  528.        
  529.         DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
  530.             if ( entry->flags & kCCImplementsKeyUp ) {
  531.                 void *swallows = [entry->delegate performSelector:@selector(ccKeyUp:) withObject:event];
  532.                 if( swallows )
  533.                     break;
  534.             }
  535.         }
  536.     }
  537. }
  538.  
  539. - (void)flagsChanged:(NSEvent *)event
  540. {
  541.     if( dispatchEvents_ ) {
  542.         tListEntry *entry, *tmp;
  543.        
  544.         DL_FOREACH_SAFE( keyboardDelegates_, entry, tmp ) {
  545.             if ( entry->flags & kCCImplementsFlagsChanged ) {
  546.                 void *swallows = [entry->delegate performSelector:@selector(ccFlagsChanged:) withObject:event];
  547.                 if( swallows )
  548.                     break;
  549.             }
  550.         }
  551.     }
  552. }
  553.  
  554.  
  555. #pragma mark CCEventDispatcher - Touch events
  556.  
  557. - (void)touchesBeganWithEvent:(NSEvent *)event
  558. {
  559.     if( dispatchEvents_ ) {
  560.         tListEntry *entry, *tmp;
  561.        
  562.         DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
  563.             if ( entry->flags & kCCImplementsTouchesBegan) {
  564.                 void *swallows = [entry->delegate performSelector:@selector(ccTouchesBeganWithEvent:) withObject:event];
  565.                 if( swallows )
  566.                     break;
  567.             }
  568.         }
  569.     }  
  570. }
  571.  
  572. - (void)touchesMovedWithEvent:(NSEvent *)event
  573. {
  574.     if( dispatchEvents_ ) {
  575.         tListEntry *entry, *tmp;
  576.        
  577.         DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
  578.             if ( entry->flags & kCCImplementsTouchesMoved) {
  579.                 void *swallows = [entry->delegate performSelector:@selector(ccTouchesMovedWithEvent:) withObject:event];
  580.                 if( swallows )
  581.                     break;
  582.             }
  583.         }
  584.     }  
  585. }
  586.  
  587. - (void)touchesEndedWithEvent:(NSEvent *)event
  588. {
  589.     if( dispatchEvents_ ) {
  590.         tListEntry *entry, *tmp;
  591.        
  592.         DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
  593.             if ( entry->flags & kCCImplementsTouchesEnded) {
  594.                 void *swallows = [entry->delegate performSelector:@selector(ccTouchesEndedWithEvent:) withObject:event];
  595.                 if( swallows )
  596.                     break;
  597.             }
  598.         }
  599.     }  
  600. }
  601.  
  602. - (void)touchesCancelledWithEvent:(NSEvent *)event
  603. {
  604.     if( dispatchEvents_ ) {
  605.         tListEntry *entry, *tmp;
  606.        
  607.         DL_FOREACH_SAFE( touchDelegates_, entry, tmp ) {
  608.             if ( entry->flags & kCCImplementsTouchesCancelled) {
  609.                 void *swallows = [entry->delegate performSelector:@selector(ccTouchesCancelledWithEvent:) withObject:event];
  610.                 if( swallows )
  611.                     break;
  612.             }
  613.         }
  614.     }  
  615. }
  616.  
  617.  
  618. #pragma mark CCEventDispatcher - queue events
  619.  
  620. #if CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
  621. -(void) queueEvent:(NSEvent*)event selector:(SEL)selector
  622. {
  623.     NSAssert( eventQueueCount < QUEUE_EVENT_MAX, @"CCEventDispatcher: recompile. Increment QUEUE_EVENT_MAX value");
  624.  
  625.     @synchronized (self) {
  626.         eventQueue[eventQueueCount].selector = selector;
  627.         eventQueue[eventQueueCount].event = [event copy];
  628.        
  629.         eventQueueCount++;
  630.     }
  631. }
  632.  
  633. -(void) dispatchQueuedEvents
  634. {
  635.     @synchronized (self) {
  636.         for( int i=0; i < eventQueueCount; i++ ) {
  637.             SEL sel = eventQueue[i].selector;
  638.             NSEvent *event = eventQueue[i].event;
  639.            
  640.             [self performSelector:sel withObject:event];
  641.            
  642.             [event release];
  643.         }
  644.        
  645.         eventQueueCount = 0;
  646.     }
  647. }
  648. #endif // CC_DIRECTOR_MAC_USE_DISPLAY_LINK_THREAD
  649.  
  650. //NS_CC_END;
  651. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement