Vuo  2.0.0
VuoGraphicsView.m
Go to the documentation of this file.
1 
10 #import "VuoGraphicsView.h"
11 
12 #import "module.h"
13 #import "VuoGraphicsLayer.h"
14 
15 #ifdef VUO_COMPILER
17  "title" : "VuoGraphicsView",
18  "dependencies" : [
19  "VuoGraphicsLayer",
20  ]
21 });
22 #endif
23 
27 @interface VuoGraphicsView ()
28 @property(retain) NSImage *circleImage;
29 @property NSRect circleRect;
30 @end
31 
32 @implementation VuoGraphicsView
33 
39 - (instancetype)init
40 {
41  if (self = [super init])
42  {
43  self.wantsLayer = true;
44 
45  // Prepare the circle mouse cursor.
46  {
47  _circleRect = NSMakeRect(0,0,48,48);
48  _circleImage = [[NSImage alloc] initWithSize:_circleRect.size];
49  [_circleImage lockFocus];
50  {
51  [[NSColor colorWithDeviceWhite:1 alpha:0.75] setFill];
52  [[NSColor colorWithDeviceWhite:0 alpha:0.15] setStroke];
53  NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(_circleRect, 1, 1)];
54  [circlePath fill];
55  [circlePath stroke];
56  }
57  [_circleImage unlockFocus];
58  }
59  }
60  return self;
61 }
62 
69 - (void)viewDidMoveToWindow
70 {
71  if (!self.window)
72  return;
73 
74  _viewport = self.frame;
75 }
76 
83 - (void)viewDidChangeBackingProperties
84 {
85  VuoGraphicsLayer *l = (VuoGraphicsLayer *)self.layer;
87  [l setNeedsDisplay];
88 }
89 
94 - (void)resetCursorRects
95 {
96  VuoGraphicsWindow *gw = (VuoGraphicsWindow *)self.window;
97  VuoCursor cursor = gw.cursor;
98  NSCursor *nsCursor = nil;
99 
100  if (cursor == VuoCursor_None)
101  {
102  NSImage *im = [[NSImage alloc] initWithSize:NSMakeSize(1,1)];
103  nsCursor = [[[NSCursor alloc] initWithImage:im hotSpot:NSMakePoint(0,0)] autorelease];
104  [im release];
105  }
106  else if (cursor == VuoCursor_Pointer)
107  nsCursor = [NSCursor arrowCursor];
108  else if (cursor == VuoCursor_Crosshair)
109  nsCursor = [NSCursor crosshairCursor];
110  else if (cursor == VuoCursor_HandOpen)
111  nsCursor = [NSCursor openHandCursor];
112  else if (cursor == VuoCursor_HandClosed)
113  nsCursor = [NSCursor closedHandCursor];
114  else if (cursor == VuoCursor_IBeam)
115  nsCursor = [NSCursor IBeamCursor];
116  else if (cursor == VuoCursor_Circle)
117  nsCursor = [[[NSCursor alloc] initWithImage:_circleImage hotSpot:NSMakePoint(NSMidX(_circleRect),NSMidY(_circleRect))] autorelease];
118 
119  if (nsCursor)
120  [self addCursorRect:[self visibleRect] cursor:nsCursor];
121 }
122 
129 - (BOOL)acceptsFirstResponder
130 {
131  return YES;
132 }
133 
145 - (BOOL)mouseDownCanMoveWindow
146 {
147  return NO;
148 }
149 
153 - (void)dealloc
154 {
155  [_circleImage release];
156  [super dealloc];
157 }
158 
159 @end