RSS

(root)/iphone/tappity : 46 : tappity/source/Tappity.m

To get this branch, use:
bzr branch /browse/iphone/tappity

« back to all changes in this revision

Viewing changes to tappity/source/Tappity.m

Dömötör Gulyás
2009-10-27 01:03:19
Revision ID: dognotdog@gmail.com-20091027000319-1vrkixkgf9lkud6g
adds tappity project

Show diffs side-by-side

added added

removed removed

 
1
//
 
2
//  Tappity.m
 
3
//  tappity
 
4
//
 
5
//  Created by döme on 25.10.2009.
 
6
//  Copyright 2009 __MyCompanyName__. All rights reserved.
 
7
//
 
8
 
 
9
#import "Tappity.h"
 
10
 
 
11
#import "GraphicsServices.h"
 
12
 
 
13
NSString* TapIdKey              = @"tapId";
 
14
NSString* TapTouchesKey = @"tapTouches";
 
15
NSString* TapGSEventKey = @"tapGSEvent";
 
16
NSString* TapTouchPhaseKey = @"tapTouchPhase";
 
17
NSString* TapRecordedEventKey = @"tapRecordedEvent";
 
18
 
 
19
@implementation Tappity
 
20
 
 
21
@end
 
22
 
 
23
@implementation UITouch (Synthesize)
 
24
 
 
25
- (id)initInView:(UIView *)view
 
26
{
 
27
    self = [super init];
 
28
    if (self != nil)
 
29
    {
 
30
        CGRect frameInWindow;
 
31
        if ([view isKindOfClass:[UIWindow class]])
 
32
        {
 
33
            frameInWindow = view.frame;
 
34
        }
 
35
        else
 
36
        {
 
37
            frameInWindow =
 
38
                [view.window convertRect:view.frame fromView:view.superview];
 
39
        }
 
40
         
 
41
        _tapCount = 1;
 
42
        _locationInWindow =
 
43
            CGPointMake(
 
44
                frameInWindow.origin.x + 0.5 * frameInWindow.size.width,
 
45
                frameInWindow.origin.y + 0.5 * frameInWindow.size.height);
 
46
        _previousLocationInWindow = _locationInWindow;
 
47
 
 
48
        UIView *target = [view.window hitTest:_locationInWindow withEvent:nil];
 
49
        _view = [target retain];
 
50
        _window = [view.window retain];
 
51
        _phase = UITouchPhaseBegan;
 
52
        _touchFlags._firstTouchForView = 1;
 
53
        _touchFlags._isTap = 1;
 
54
        _timestamp = [NSDate timeIntervalSinceReferenceDate];
 
55
    }
 
56
    return self;
 
57
}
 
58
 
 
59
- (void)changeToPhase:(UITouchPhase)phase
 
60
{
 
61
    _phase = phase;
 
62
    _timestamp = [NSDate timeIntervalSinceReferenceDate];
 
63
}
 
64
 
 
65
@end
 
66
 
 
67
@interface GSEventProxy : NSObject
 
68
{
 
69
@public
 
70
    unsigned int flags;
 
71
    unsigned int type;
 
72
    unsigned int ignored1;
 
73
    float x1;
 
74
    float y1;
 
75
    float x2;
 
76
    float y2;
 
77
    unsigned int ignored2[10];
 
78
    unsigned int ignored3[7];
 
79
    float sizeX;
 
80
    float sizeY;
 
81
    float x3;
 
82
    float y3;
 
83
    unsigned int ignored4[3];
 
84
}
 
85
@end
 
86
@implementation GSEventProxy
 
87
@end
 
88
 
 
89
@implementation UIEvent (Synthesize)
 
90
 
 
91
- (id)initWithTouches:(NSSet *) touches
 
92
{
 
93
        UITouch* touch = [touches anyObject];
 
94
    CGPoint location = [touch locationInView: touch.window];
 
95
    GSEventProxy *gsEventProxy = [[GSEventProxy alloc] init];
 
96
    gsEventProxy->x1 = location.x;
 
97
    gsEventProxy->y1 = location.y;
 
98
    gsEventProxy->x2 = location.x;
 
99
    gsEventProxy->y2 = location.y;
 
100
    gsEventProxy->x3 = location.x;
 
101
    gsEventProxy->y3 = location.y;
 
102
    gsEventProxy->sizeX = 1.0;
 
103
    gsEventProxy->sizeY = 1.0;
 
104
    gsEventProxy->flags = ([touch phase] == UITouchPhaseEnded) ? 0x1010180 : 0x3010180;
 
105
    gsEventProxy->type = 3001;    
 
106
    
 
107
    //
 
108
    // On SDK versions 3.0 and greater, we need to reallocate as a
 
109
    // UITouchesEvent.
 
110
    //
 
111
    Class touchesEventClass = objc_getClass("UITouchesEvent");
 
112
    if (touchesEventClass && ![[self class] isEqual: touchesEventClass])
 
113
    {
 
114
        [self release];
 
115
        self = [touchesEventClass alloc];
 
116
    }
 
117
    
 
118
    self = [self _initWithEvent:gsEventProxy touches:touches];
 
119
    if (self != nil)
 
120
    {
 
121
    }
 
122
    return self;
 
123
}
 
124
 
 
125
void _printGSPathPoint(GSTouchPointRef p)
 
126
{
 
127
//      printf("P: 0x%08X 0x%08X 0x%08X 0x%08X (%G, %G)\n", p->unk0, p->unk1, p->unk2, p->unk5, p->x, p->y);
 
128
        printf("P: 0x%08X %7G %7G (%G, %G)\n", p->unk0, p->unk1, p->touchSize, p->x, p->y);
 
129
}
 
130
 
 
131
void _printGSEvent(UIEvent* event)
 
132
{
 
133
        GSEvent* e = [event _gsEvent];
 
134
//      printf("%p, %p\n", event, e);
 
135
//      printf("0x%08X  0x%08X  0x%08X\n", e->unk1, e->unk2, e->unk3);
 
136
 
 
137
//      printf("type0 0x%08X  type1 0x%08X  r3 0x%08X\n", e->type0, e->type1, e->r3);
 
138
//      printf("type10 0x%08X  r11 0x%08X  type12 0x%08X\n", e->type10, e->r11, e->type12);
 
139
//      printf("gesture12 0x%08X  gesture14 0x%08X\n", e->gesture13, e->gesture14);
 
140
 
 
141
//      printf("avg0 (%5G, %5G),  avg1 (%5G, %5G)\n", e->avgX0, e->avgY0, e->avgX1, e->avgY1);
 
142
//      printf("(%d) %d\n", e->numInitialTouches, e->numCurrentTouches);
 
143
//      printf("unk16 0x%08X  unk17 0x%08X  unk18 0x%08X  unk19 0x%08X\n", e->unk16, e->unk17, e->unk18, e->unk19);
 
144
//      printf("r20 0x%08X  r21 0x%08X\n", e->r20, e->r21);
 
145
        printf("points %d\n", e->numPoints);
 
146
 
 
147
//      printf("unk9 0x%08X  unk10 0x%08X unk11 0x%08X unk12 0x%08X\n", e->unk9, e->unk10, e->unk11, e->unk12);
 
148
//      printf("%u.%u\n", e->timestamp_s, e->timestamp_ns);
 
149
//      printf("%G\n", (double)e->timestamp*1e-9);
 
150
//      printf("unk12 0x%08X  unk13 0x%08X  unk14 0x%08X  unk15 0x%08X\n", e->unk12, e->unk13, e->unk14, e->unk15);
 
151
        for(size_t i = 0; i < e->numPoints; ++i)
 
152
                _printGSPathPoint(e->points+i);
 
153
        printf("\n");
 
154
}
 
155
 
 
156
@end
 
157
 
 
158
@implementation GSEvent
 
159
@end
 
160
 

Loggerhead 1.17 is a web-based interface for Bazaar branches