forked from amari/UIKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITouch.j
100 lines (84 loc) · 2.93 KB
/
UITouch.j
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* UITouch.j
* UIKit
*
* Created by Amari Robinson.
* Copyright 2011, Amari Robinson.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* http://developer.apple.com/library/ios/#documentation/uikit/reference/UITouch_Class/Reference/Reference.html%23//apple_ref/occ/cl/UITouch */
@import <Foundation/CPObject.j>
/* UITouchPhase */
var UITouchPhaseBegan = 0
UITouchPhaseMoved = 1,
UITouchPhaseStationary = 2,
UITouchPhaseEnded = 3,
UITouchPhaseCancelled = 4;
@implementation UITouch : CPObject
{
UIView _view @accessors(property=view);
UIWindow _window @accessors(property=window);
int _tapCount @accessors(getter=tapCount);
CPTimeInterval _timestamp @accessors(getter=timestamp);
UITouchPhase _phase @accessors(getter=phase);
CPArray _gestureRecognizers @accessors(getter=gestureRecognizers);
CGPoint _location @accessors(property=location);
CGPoint _previousLocation @accessors(property=previousLocation);
CGPoint _previousLocation @accessors(property=previousLocation);
CPString _identifier @accessors(property=identifier);
}
- (id)init {
if (self = [super init]) {
_view = nil;
_window = nil;
_tapCount = 0;
_timestamp = 0;
_phase = -1;
_gestureRecognizers = [CPArray array];
}
return self;
}
+ (UITouch)touchWithJSTouch:(id)anEvent {
var touch = [[UITouch alloc] init];
var location = CGPointMake(anEvent.screenX,anEvent.screenY);
var view = [[UIApp platformWindow] hitTest:location];
//var element = anEvent.target;
[touch setPreviousLocation:[touch location]];
[touch setLocation:location];
[touch setView:view];
[touch setWindow:[view window]];
[touch setPhase:UITouchPhaseBegan];
[touch setTimestamp:[CPDate date]];
[touch setIdentifier:anEvent.identifier];
return touch;
}
/* Getting the Location of Touches */
// _location and _previousLocation are relative to a UIWindow,
// so we need to convert the coordinates.
- (CGPoint)locationInView:(UIView)view {
return [[UIApp platformWindow] convertPoint:_location toView:view];
}
- (CGPoint)previousLocationInView:(UIView)view {
return [[UIApp platformWindow] convertPoint:_previousLocation toView:view];
}
/*
@ignore
*/
- (void)addGestureRecognizer:(UIGestureRecognizer)gestureRecognizer
{
[_gestureRecognizers addObject:gestureRecognizer];
}
@end