diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
commit | 9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch) | |
tree | 5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h | |
download | cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2 cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip |
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h')
-rwxr-xr-x | libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h b/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h new file mode 100755 index 0000000..9931189 --- /dev/null +++ b/libs/cocos2d/Platforms/iOS/CCTouchDispatcher.h | |||
@@ -0,0 +1,123 @@ | |||
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 | // Only compile this code on iOS. These files should NOT be included on your Mac project. | ||
27 | // But in case they are included, it won't be compiled. | ||
28 | #import <Availability.h> | ||
29 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED | ||
30 | |||
31 | #import "CCTouchDelegateProtocol.h" | ||
32 | #import "EAGLView.h" | ||
33 | |||
34 | |||
35 | typedef enum | ||
36 | { | ||
37 | kCCTouchSelectorBeganBit = 1 << 0, | ||
38 | kCCTouchSelectorMovedBit = 1 << 1, | ||
39 | kCCTouchSelectorEndedBit = 1 << 2, | ||
40 | kCCTouchSelectorCancelledBit = 1 << 3, | ||
41 | kCCTouchSelectorAllBits = ( kCCTouchSelectorBeganBit | kCCTouchSelectorMovedBit | kCCTouchSelectorEndedBit | kCCTouchSelectorCancelledBit), | ||
42 | } ccTouchSelectorFlag; | ||
43 | |||
44 | |||
45 | enum { | ||
46 | kCCTouchBegan, | ||
47 | kCCTouchMoved, | ||
48 | kCCTouchEnded, | ||
49 | kCCTouchCancelled, | ||
50 | |||
51 | kCCTouchMax, | ||
52 | }; | ||
53 | |||
54 | struct ccTouchHandlerHelperData { | ||
55 | SEL touchesSel; | ||
56 | SEL touchSel; | ||
57 | ccTouchSelectorFlag type; | ||
58 | }; | ||
59 | |||
60 | /** CCTouchDispatcher. | ||
61 | Singleton that handles all the touch events. | ||
62 | The dispatcher dispatches events to the registered TouchHandlers. | ||
63 | There are 2 different type of touch handlers: | ||
64 | - Standard Touch Handlers | ||
65 | - Targeted Touch Handlers | ||
66 | |||
67 | The Standard Touch Handlers work like the CocoaTouch touch handler: a set of touches is passed to the delegate. | ||
68 | 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). | ||
69 | |||
70 | Firstly, the dispatcher sends the received touches to the targeted touches. | ||
71 | These touches can be swallowed by the Targeted Touch Handlers. If there are still remaining touches, then the remaining touches will be sent | ||
72 | to the Standard Touch Handlers. | ||
73 | |||
74 | @since v0.8.0 | ||
75 | */ | ||
76 | @interface CCTouchDispatcher : NSObject <EAGLTouchDelegate> | ||
77 | { | ||
78 | NSMutableArray *targetedHandlers; | ||
79 | NSMutableArray *standardHandlers; | ||
80 | |||
81 | BOOL locked; | ||
82 | BOOL toAdd; | ||
83 | BOOL toRemove; | ||
84 | NSMutableArray *handlersToAdd; | ||
85 | NSMutableArray *handlersToRemove; | ||
86 | BOOL toQuit; | ||
87 | |||
88 | BOOL dispatchEvents; | ||
89 | |||
90 | // 4, 1 for each type of event | ||
91 | struct ccTouchHandlerHelperData handlerHelperData[kCCTouchMax]; | ||
92 | } | ||
93 | |||
94 | /** singleton of the CCTouchDispatcher */ | ||
95 | + (CCTouchDispatcher*)sharedDispatcher; | ||
96 | |||
97 | /** Whether or not the events are going to be dispatched. Default: YES */ | ||
98 | @property (nonatomic,readwrite, assign) BOOL dispatchEvents; | ||
99 | |||
100 | /** Adds a standard touch delegate to the dispatcher's list. | ||
101 | See StandardTouchDelegate description. | ||
102 | IMPORTANT: The delegate will be retained. | ||
103 | */ | ||
104 | -(void) addStandardDelegate:(id<CCStandardTouchDelegate>) delegate priority:(int)priority; | ||
105 | /** Adds a targeted touch delegate to the dispatcher's list. | ||
106 | See TargetedTouchDelegate description. | ||
107 | IMPORTANT: The delegate will be retained. | ||
108 | */ | ||
109 | -(void) addTargetedDelegate:(id<CCTargetedTouchDelegate>) delegate priority:(int)priority swallowsTouches:(BOOL)swallowsTouches; | ||
110 | /** Removes a touch delegate. | ||
111 | The delegate will be released | ||
112 | */ | ||
113 | -(void) removeDelegate:(id) delegate; | ||
114 | /** Removes all touch delegates, releasing all the delegates */ | ||
115 | -(void) removeAllDelegates; | ||
116 | /** Changes the priority of a previously added delegate. The lower the number, | ||
117 | the higher the priority */ | ||
118 | -(void) setPriority:(int) priority forDelegate:(id) delegate; | ||
119 | |||
120 | NSComparisonResult sortByPriority(id first, id second, void *context); | ||
121 | @end | ||
122 | |||
123 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED | ||