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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*Copyright (C) 2012 Aaron Skomra and Ben Huddle
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#import "XtoqView.h"
#define RECTLOG(rect) (NSLog(@"" #rect @" x:%f y:%f w:%f h:%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height ));
@implementation XtoqView
/**
* This is the initializer.
*/
- (id)
initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
notificationCenter = [NSNotificationCenter defaultCenter];
[[self window] flushWindow];
[self setNeedsDisplay:YES];
trackingArea = [[NSTrackingArea alloc] initWithRect:frame
options: (NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved
| NSTrackingActiveInKeyWindow)
owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
return self;
}
-(void) setContext: (xtoq_context_t *)context {
viewContext = context;
}
// Overridden by subclasses to draw the receiver’s image within the passed-in rectangle.
-(void)
drawRect:(NSRect)dirtyRect {
xtoq_image_t *imageT;
float y_transformed;
XtoqImageRep *imageNew;
xtoq_get_event_thread_lock();
imageT = test_xtoq_get_image(viewContext);
if (imageT->image) {
y_transformed =( viewContext->height
- viewContext->damaged_y
- viewContext->damaged_height)/1.0;
imageNew = [[XtoqImageRep alloc]
initWithData:imageT
x:((viewContext->damaged_x))
y:y_transformed];
[imageNew draw];
[imageNew destroy];
}
// Set the damage for the context back to 0
viewContext->damaged_x = 0;
viewContext->damaged_y = 0;
viewContext->damaged_width = 0;
viewContext->damaged_height = 0;
xtoq_release_event_thread_lock();
}
//This is necessary for accepting input.
- (BOOL)
acceptsFirstResponder {
return YES;
}
- (BOOL)acceptsMouseMovedEvents {
return YES;
}
/*- (void)mouseEntered:(NSEvent *)theEvent {
}
- (void)mouseExited:(NSEvent *)theEvent {
}
- (void)rightMouseDown:(NSEvent *)theEvent
}*/
/**
* Capture keyboard events
*/
- (void)
keyDown:(NSEvent *)theEvent {
NSDictionary * dictionary = [NSDictionary dictionaryWithObject:theEvent
forKey:@"1"];
[notificationCenter postNotificationName:@"XTOQviewKeyDownEvent"
object:self
userInfo:dictionary];
}
-(void)
mouseDown:(NSEvent *)mouseEvent {
CGFloat f = [self bounds].size.height;
NSNumber *n = [[NSNumber alloc] initWithFloat:f];
//NSLog(@"mouseevent %i", [mouseEvent mouseLocation]->x);
// NSLog(@"mouse event bound %f location %f", CGRectGetHeight(bnd), [mouseEvent locationInWindow].y );
NSMutableDictionary *twoInfoDict = [[NSMutableDictionary alloc] initWithCapacity:2];
[twoInfoDict setObject:mouseEvent forKey:@"1"];
[twoInfoDict setObject:n forKey:@"2"];
//NSLog(@"bound %f location %f", CGRectGetHeight(bnd), [mouseEvent locationInWindow].y );
[notificationCenter postNotificationName:@"XTOQmouseButtonDownEvent"
object:self
userInfo:twoInfoDict];
}
- (void)mouseUp:(NSEvent *)theEvent {
CGFloat f = [self bounds].size.height;
NSNumber *n = [[NSNumber alloc] initWithFloat:f];
NSMutableDictionary *twoInfoDict = [[NSMutableDictionary alloc] initWithCapacity:2];
[twoInfoDict setObject:theEvent forKey:@"1"];
[twoInfoDict setObject:n forKey:@"2"];
[notificationCenter postNotificationName:@"XTOQmouseButtonReleaseEvent"
object:self
userInfo:twoInfoDict];
}
- (void)setPartialImage:(NSRect)newDamageRect {
[self setNeedsDisplayInRect:newDamageRect];
//[[self window] flushWindow];
}
- (BOOL)isOpaque{
return YES;
}
@end
|