15 "title" :
"VuoGraphicsView",
26@property(retain) NSImage *circleImage;
44 if (
self = [super init])
46 self.wantsLayer =
true;
48 self.allowedTouchTypes = NSTouchTypeMaskIndirect;
49 self.wantsRestingTouches = YES;
50 _touchTriggers = [NSMutableSet new];
51 _zoomedTriggers = [NSMutableSet new];
52 _swipedLeftTriggers = [NSMutableSet new];
53 _swipedRightTriggers = [NSMutableSet new];
57 _circleRect = NSMakeRect(0,0,48,48);
58 _circleImage = [[NSImage alloc] initWithSize:_circleRect.size];
59 [_circleImage lockFocus];
61 [[NSColor colorWithDeviceWhite:1 alpha:0.75] setFill];
62 [[NSColor colorWithDeviceWhite:0 alpha:0.15] setStroke];
63 NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(_circleRect, 1, 1)];
67 [_circleImage unlockFocus];
79- (void)viewDidMoveToWindow
84 _viewport =
self.frame;
93- (void)viewDidChangeBackingProperties
104- (void)resetCursorRects
108 NSCursor *nsCursor = nil;
110 if (cursor == VuoCursor_None)
112 NSImage *im = [[NSImage alloc] initWithSize:NSMakeSize(1,1)];
113 nsCursor = [[[NSCursor alloc] initWithImage:im hotSpot:NSMakePoint(0,0)] autorelease];
116 else if (cursor == VuoCursor_Pointer)
117 nsCursor = [NSCursor arrowCursor];
118 else if (cursor == VuoCursor_Crosshair)
119 nsCursor = [NSCursor crosshairCursor];
120 else if (cursor == VuoCursor_HandOpen)
121 nsCursor = [NSCursor openHandCursor];
122 else if (cursor == VuoCursor_HandClosed)
123 nsCursor = [NSCursor closedHandCursor];
124 else if (cursor == VuoCursor_IBeam)
125 nsCursor = [NSCursor IBeamCursor];
126 else if (cursor == VuoCursor_Circle)
127 nsCursor = [[[NSCursor alloc] initWithImage:_circleImage hotSpot:NSMakePoint(NSMidX(_circleRect),NSMidY(_circleRect))] autorelease];
130 [
self addCursorRect:[
self visibleRect] cursor:nsCursor];
139- (
BOOL)acceptsFirstResponder
155- (
BOOL)mouseDownCanMoveWindow
165 [_circleImage release];
169static NSInteger VuoGraphicsView_touchComparator(NSTouch *a, NSTouch *b,
void *p)
171 float ax = a.normalizedPosition.x;
172 float bx = b.normalizedPosition.x;
181- (void)fireTouches:(NSEvent *)e
183 NSSet *touchesSet = [e touchesMatchingPhase:NSTouchPhaseAny inView:nil];
184 NSArray *orderedTouches = [touchesSet.allObjects sortedArrayUsingFunction:VuoGraphicsView_touchComparator context:nil];
189 for (NSTouch *t in orderedTouches)
190 touchPoints[i++] = (VuoPoint2d){
191 t.normalizedPosition.x * 2 - 1,
192 (t.normalizedPosition.y * 2 - 1) * (t.deviceSize.height / t.deviceSize.width)
195 dispatch_async(dispatch_get_main_queue(), ^{
196 for (NSValue *v in
self.touchTriggers)
200 touchesMoved(touches);
204- (void)touchesBeganWithEvent:(NSEvent *)event
206 [
self fireTouches:event];
208- (void)touchesMovedWithEvent:(NSEvent *)event
210 [
self fireTouches:event];
212- (void)touchesEndedWithEvent:(NSEvent *)event
214 [
self fireTouches:event];
216- (void)touchesCancelledWithEvent:(NSEvent *)event
218 [
self fireTouches:event];
221- (void)magnifyWithEvent:(NSEvent *)event
223 if (event.magnification != 0)
224 dispatch_async(dispatch_get_main_queue(), ^{
225 for (NSValue *v in
self.zoomedTriggers)
227 void (*zoomed)(
VuoReal) = v.pointerValue;
229 zoomed(event.magnification);
234- (void)swipeWithEvent:(NSEvent *)event
236 if (event.deltaX > 0)
237 dispatch_async(dispatch_get_main_queue(), ^{
238 for (NSValue *v in
self.swipedLeftTriggers)
240 void (*swipedLeft)(void) = v.pointerValue;
245 else if (event.deltaX < 0)
246 dispatch_async(dispatch_get_main_queue(), ^{
247 for (NSValue *v in
self.swipedRightTriggers)
249 void (*swipedRight)(void) = v.pointerValue;
263 zoomed:(
void (*)(
VuoReal))zoomed
264 swipedLeft:(
void (*)(
void))swipedLeft
265 swipedRight:(
void (*)(
void))swipedRight
267 dispatch_async(dispatch_get_main_queue(), ^{
268 [
self.touchTriggers addObject:[NSValue valueWithPointer:touchesMoved]];
269 [
self.zoomedTriggers addObject:[NSValue valueWithPointer:zoomed]];
270 [
self.swipedLeftTriggers addObject:[NSValue valueWithPointer:swipedLeft]];
271 [
self.swipedRightTriggers addObject:[NSValue valueWithPointer:swipedRight]];
282 zoomed:(
void (*)(
VuoReal))zoomed
283 swipedLeft:(
void (*)(
void))swipedLeft
284 swipedRight:(
void (*)(
void))swipedRight
286 dispatch_async(dispatch_get_main_queue(), ^{
287 for (NSValue *v in
self.touchTriggers)
288 if (v.pointerValue == touchesMoved)
289 [
self.touchTriggers removeObject:v];
290 for (NSValue *v in
self.zoomedTriggers)
291 if (v.pointerValue == zoomed)
292 [
self.zoomedTriggers removeObject:v];
293 for (NSValue *v in
self.swipedLeftTriggers)
294 if (v.pointerValue == swipedLeft)
295 [
self.swipedLeftTriggers removeObject:v];
296 for (NSValue *v in
self.swipedRightTriggers)
297 if (v.pointerValue == swipedRight)
298 [
self.swipedRightTriggers removeObject:v];