-
Notifications
You must be signed in to change notification settings - Fork 1
/
MBKeyboardView.m
121 lines (92 loc) · 3.05 KB
/
MBKeyboardView.m
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#import "MBKeyboardView.h"
struct CGRect GSEventGetLocationInWindow(struct __GSEvent *ev);
struct CGPoint GSEventGetInnerMostPathPosition(struct __GSEvent *ev);
struct CGPoint GSEventGetOuterMostPathPosition(struct __GSEvent *ev);
// struct CGRect GSEventGetLocationInWindow(GSEvent *ev);
@implementation MBKeyboardView
CGRect _currentRect;
- (id)initWithFrame:(struct CGRect)frame
{
if (!(self = [super initWithFrame:frame])) return nil;
_frame = frame;
left = CGPointMake(-100,-100);
right = CGPointMake(-100, -100);
float boxback[4] = {.85, .85, .85, 1};
[self setBackgroundColor: CGColorCreate( CGColorSpaceCreateDeviceRGB(), boxback)];
return self;
}
- (BOOL)ignoresMouseEvents {
return NO;
}
- (BOOL)canHandleGestures {
return YES;
}
- (void)drawRect:(struct CGRect)rect
{
[self _drawKeys];
[self _drawDownKeys];
}
- (void)setDelegate:(id)delegate
{
[_delegate release];
_delegate = [delegate retain];
}
- (id)delegate{
return _delegate;
}
- (void)_drawKeys
{
CGContextSetRGBFillColor(UICurrentContext(), .2353f, .6627f, 1.0f, 1.0f);
CGContextFillRect( UICurrentContext(), _currentRect);
}
- (void)_drawDownKeys
{
CGContextSetRGBFillColor(UICurrentContext(), 1., 0, 0, 1.0f);
CGContextFillRect( UICurrentContext(), CGRectMake(left.x-5, left.y-5, 10,10));
CGContextFillRect( UICurrentContext(), CGRectMake(right.x-5, right.y-5, 10,10));
}
- (void)gestureStarted:(struct __GSEvent *)event {
[ self gestureChanged: event ];
}
- (void)gestureEnded:(struct __GSEvent *)event {
NSLog(@"gestureEnded");
[self setNeedsDisplay];
//right = CGPointMake(-100,-100);
}
- (void)gestureChanged:(struct __GSEvent *)event {
left = [self convertPoint:GSEventGetInnerMostPathPosition(event) fromView:nil];
right = [self convertPoint:GSEventGetOuterMostPathPosition(event) fromView:nil];
NSLog(@"gestureChanged: mouseDown:%f, %f and %f, %f", left.x, left.y, right.x, right.y);
[self setNeedsDisplay];
}
- (void)mouseDown:(struct __GSEvent *)event
{
struct CGRect rect = GSEventGetLocationInWindow(event);
//NSLog(@"MBKeyboardView: mouseDown:%f, %f", rect.origin.x, rect.origin.y);
left = [self convertPoint:CGPointMake(rect.origin.x, rect.origin.y) fromView:nil];
right = CGPointMake(-100,-100);
//NSLog(@"MBKeyboardView: mouseDown:%f, %f and %f, %f", points.first.x, points.first.y, points.second.x, points.second.y);
[self setNeedsDisplay];
[super mouseDown:event];
}
- (void)mouseDragged:(struct __GSEvent *)event
{
struct CGRect rect = GSEventGetLocationInWindow(event);
left = [self convertPoint:CGPointMake(rect.origin.x, rect.origin.y) fromView:nil];
right = CGPointMake(-100,-100);
//NSLog(@"MBKeyboardView: mouseDragged:%f, %f and %f, %f", points.first.x, points.first.y, points.second.x, points.second.y);
[self setNeedsDisplay];
[super mouseDown:event];
}
- (void)mouseUp:(struct __GSEvent *)event
{
NSLog(@"MBKeyboardView: mouseUp:");
//right = CGPointMake(-100,-100);
//left = CGPointMake(-100, -100);
[super mouseUp:event];
}
- (void)dealloc{
[_delegate release];
[super dealloc];
}
@end