PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/cocos2d/CCTouchDispatcher.h

http://github.com/kstenerud/ObjectAL-for-iPhone
C Header | 116 lines | 43 code | 16 blank | 57 comment | 0 complexity | 11463393fd5879ce2428cd93eecbd682 MD5 | raw file
Possible License(s): Apache-2.0
  1/*
  2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3 *
  4 * Copyright (c) 2009 Valentin Milea
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a copy
  7 * of this software and associated documentation files (the "Software"), to deal
  8 * in the Software without restriction, including without limitation the rights
  9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10 * copies of the Software, and to permit persons to whom the Software is
 11 * furnished to do so, subject to the following conditions:
 12 * 
 13 * The above copyright notice and this permission notice shall be included in
 14 * all copies or substantial portions of the Software.
 15 * 
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22 * THE SOFTWARE.
 23 *
 24 */
 25
 26
 27#import "CCTouchDelegateProtocol.h"
 28#import "Support/EAGLView.h"
 29
 30
 31typedef enum
 32{
 33	ccTouchSelectorBeganBit = 1 << 0,
 34	ccTouchSelectorMovedBit = 1 << 1,
 35	ccTouchSelectorEndedBit = 1 << 2,
 36	ccTouchSelectorCancelledBit = 1 << 3,
 37	ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
 38} ccTouchSelectorFlag;
 39
 40
 41enum {
 42	ccTouchBegan,
 43	ccTouchMoved,
 44	ccTouchEnded,
 45	ccTouchCancelled,
 46	
 47	ccTouchMax,
 48};
 49
 50struct ccTouchHandlerHelperData {
 51	SEL				touchesSel;
 52	SEL				touchSel;
 53	ccTouchSelectorFlag  type;
 54};
 55
 56/** CCTouchDispatcher.
 57 Singleton that handles all the touch events.
 58 The dispatcher dispatches events to the registered TouchHandlers.
 59 There are 2 different type of touch handlers:
 60   - Standard Touch Handlers
 61   - Targeted Touch Handlers
 62 
 63 The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate.
 64 On the other hand, the Targeted Touch Handlers only receive 1 touch at the time, and they can "swallow" touches (avoid the propagation of the event).
 65 
 66 Firstly, the dispatcher sends the received touches to the targeted touches.
 67 These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent
 68 to the Standard Touch Handlers.
 69
 70 @since v0.8.0
 71 */
 72@interface CCTouchDispatcher : NSObject <EAGLTouchDelegate>
 73{
 74	NSMutableArray	*targetedHandlers;
 75	NSMutableArray	*standardHandlers;
 76
 77	BOOL			locked;
 78	BOOL			toAdd;
 79	BOOL			toRemove;
 80	NSMutableArray	*handlersToAdd;
 81	NSMutableArray	*handlersToRemove;
 82	BOOL			toQuit;
 83
 84	BOOL	dispatchEvents;
 85	
 86	// 4, 1 for each type of event
 87	struct ccTouchHandlerHelperData handlerHelperData[ccTouchMax];
 88}
 89
 90/** singleton of the CCTouchDispatcher */
 91+ (CCTouchDispatcher*)sharedDispatcher;
 92
 93/** Whether or not the events are going to be dispatched. Default: YES */
 94@property (nonatomic,readwrite, assign) BOOL dispatchEvents;
 95
 96/** Adds a standard touch delegate to the dispatcher's list.
 97 See StandardTouchDelegate description.
 98 IMPORTANT: The delegate will be retained.
 99 */
100-(void) addStandardDelegate:(id<CCStandardTouchDelegate>) delegate priority:(int)priority;
101/** Adds a targeted touch delegate to the dispatcher's list.
102 See TargetedTouchDelegate description.
103 IMPORTANT: The delegate will be retained.
104 */
105-(void) addTargetedDelegate:(id<CCTargetedTouchDelegate>) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches;
106/** Removes a touch delegate.
107 The delegate will be released
108 */
109-(void) removeDelegate:(id) delegate;
110/** Removes all touch delegates, releasing all the delegates */
111-(void) removeAllDelegates;
112/** Changes the priority of a previously added delegate. The lower the number,
113 the higher the priority */
114-(void) setPriority:(int) priority forDelegate:(id) delegate;
115
116@end