summary refs log tree commit diff stats
path: root/libs/cocos2d/Platforms/iOS/CCTouchHandler.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/Platforms/iOS/CCTouchHandler.m
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/Platforms/iOS/CCTouchHandler.m')
-rwxr-xr-xlibs/cocos2d/Platforms/iOS/CCTouchHandler.m135
1 files changed, 135 insertions, 0 deletions
diff --git a/libs/cocos2d/Platforms/iOS/CCTouchHandler.m b/libs/cocos2d/Platforms/iOS/CCTouchHandler.m new file mode 100755 index 0000000..a52103b --- /dev/null +++ b/libs/cocos2d/Platforms/iOS/CCTouchHandler.m
@@ -0,0 +1,135 @@
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// Only compile this code on iOS. These files should NOT be included on your Mac project.
28// But in case they are included, it won't be compiled.
29#import <Availability.h>
30#ifdef __IPHONE_OS_VERSION_MAX_ALLOWED
31
32/*
33 * This file contains the delegates of the touches
34 * There are 2 possible delegates:
35 * - CCStandardTouchHandler: propagates all the events at once
36 * - CCTargetedTouchHandler: propagates 1 event at the time
37 */
38
39#import "CCTouchHandler.h"
40#import "../../ccMacros.h"
41
42#pragma mark -
43#pragma mark TouchHandler
44@implementation CCTouchHandler
45
46@synthesize delegate, priority;
47@synthesize enabledSelectors=enabledSelectors_;
48
49+ (id)handlerWithDelegate:(id) aDelegate priority:(int)aPriority
50{
51 return [[[self alloc] initWithDelegate:aDelegate priority:aPriority] autorelease];
52}
53
54- (id)initWithDelegate:(id) aDelegate priority:(int)aPriority
55{
56 NSAssert(aDelegate != nil, @"Touch delegate may not be nil");
57
58 if ((self = [super init])) {
59 self.delegate = aDelegate;
60 priority = aPriority;
61 enabledSelectors_ = 0;
62 }
63
64 return self;
65}
66
67- (void)dealloc {
68 CCLOGINFO(@"cocos2d: deallocing %@", self);
69 [delegate release];
70 [super dealloc];
71}
72@end
73
74#pragma mark -
75#pragma mark StandardTouchHandler
76@implementation CCStandardTouchHandler
77-(id) initWithDelegate:(id)del priority:(int)pri
78{
79 if( (self=[super initWithDelegate:del priority:pri]) ) {
80 if( [del respondsToSelector:@selector(ccTouchesBegan:withEvent:)] )
81 enabledSelectors_ |= kCCTouchSelectorBeganBit;
82 if( [del respondsToSelector:@selector(ccTouchesMoved:withEvent:)] )
83 enabledSelectors_ |= kCCTouchSelectorMovedBit;
84 if( [del respondsToSelector:@selector(ccTouchesEnded:withEvent:)] )
85 enabledSelectors_ |= kCCTouchSelectorEndedBit;
86 if( [del respondsToSelector:@selector(ccTouchesCancelled:withEvent:)] )
87 enabledSelectors_ |= kCCTouchSelectorCancelledBit;
88 }
89 return self;
90}
91@end
92
93#pragma mark -
94#pragma mark TargetedTouchHandler
95
96@interface CCTargetedTouchHandler (private)
97-(void) updateKnownTouches:(NSMutableSet *)touches withEvent:(UIEvent *)event selector:(SEL)selector unclaim:(BOOL)doUnclaim;
98@end
99
100@implementation CCTargetedTouchHandler
101
102@synthesize swallowsTouches, claimedTouches;
103
104+ (id)handlerWithDelegate:(id)aDelegate priority:(int)priority swallowsTouches:(BOOL)swallow
105{
106 return [[[self alloc] initWithDelegate:aDelegate priority:priority swallowsTouches:swallow] autorelease];
107}
108
109- (id)initWithDelegate:(id)aDelegate priority:(int)aPriority swallowsTouches:(BOOL)swallow
110{
111 if ((self = [super initWithDelegate:aDelegate priority:aPriority])) {
112 claimedTouches = [[NSMutableSet alloc] initWithCapacity:2];
113 swallowsTouches = swallow;
114
115 if( [aDelegate respondsToSelector:@selector(ccTouchBegan:withEvent:)] )
116 enabledSelectors_ |= kCCTouchSelectorBeganBit;
117 if( [aDelegate respondsToSelector:@selector(ccTouchMoved:withEvent:)] )
118 enabledSelectors_ |= kCCTouchSelectorMovedBit;
119 if( [aDelegate respondsToSelector:@selector(ccTouchEnded:withEvent:)] )
120 enabledSelectors_ |= kCCTouchSelectorEndedBit;
121 if( [aDelegate respondsToSelector:@selector(ccTouchCancelled:withEvent:)] )
122 enabledSelectors_ |= kCCTouchSelectorCancelledBit;
123 }
124
125 return self;
126}
127
128- (void)dealloc {
129 [claimedTouches release];
130 [super dealloc];
131}
132@end
133
134
135#endif // __IPHONE_OS_VERSION_MAX_ALLOWED \ No newline at end of file