-
Notifications
You must be signed in to change notification settings - Fork 54
/
TouchDelegateProtocol.h
65 lines (59 loc) · 2.31 KB
/
TouchDelegateProtocol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* cocos2d for iPhone
*
* http://www.cocos2d-iphone.org
*
* Copyright (C) 2009 Valentin Milea
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
*
* You will find a copy of this license within the cocos2d for iPhone
* distribution inside the "LICENSE" file.
*
*/
#import <UIKit/UIKit.h>
/**
TargetedTouchDelegate.
Using this type of delegate results in two benefits:
1. You don't need to deal with NSSets, the dispatcher does the job of splitting
them. You get exactly one UITouch per call.
2. You can *claim* a UITouch by returning YES in ccTouchBegan. Updates of claimed
touches are sent only to the delegate(s) that claimed them. So if you get a move/
ended/cancelled update you're sure it's your touch. This frees you from doing a
lot of checks when doing multi-touch.
(The name TargetedTouchDelegate relates to updates "targeting" their specific
handler, without bothering the other handlers.)
@since v0.8
*/
@protocol TargetedTouchDelegate <NSObject>
/** Return YES to claim the touch.
@since v0.8
*/
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event;
@optional
// touch updates:
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event;
- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event;
@end
/**
StandardTouchDelegate.
Each event that is received will be propagated to the delegate,
unless a previous delegate consumes the event.
To consume the event (prevent propagation) the delegate should return kEventHandled.
To ignore the event (the event will be forwarded to the next delegate in the chain) the delegate should return kEventIgnored.
@since v0.8
*/
@protocol StandardTouchDelegate <NSObject>
@optional
- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (BOOL)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
@end
enum {
/// return kEventHandled if the event should NOT be forwarded to the next handler in the chain
kEventHandled = YES,
/// return kEventIgnored if the event should be forwarded to the next handler in the chain
kEventIgnored = NO,
};