-
Notifications
You must be signed in to change notification settings - Fork 1
/
NodoboView.m
106 lines (82 loc) · 2.64 KB
/
NodoboView.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
//
// NodoboView.m
//
// Created by Alisdair McDiarmid on 30/07/2010.
// Copyright 2010 Nodobo. All rights reserved.
//
#import "NodoboView.h"
@implementation NodoboView
@synthesize screen;
@synthesize touch;
@synthesize rotated;
- (void) setScreen:(Screen *)s
{
[screen autorelease];
screen = [s retain];
[self setNeedsDisplay: YES];
}
- (void) setTouch:(Touch *)t
{
[touch autorelease];
touch = [t retain];
[self setNeedsDisplay: YES];
}
- (void) clearTouch: (id) obj
{
self.touch = nil;
}
- (void) resizeWindow
{
if (self.screen == nil || self.screen.image == nil)
return;
NSRect windowFrame = [[self window] frame];
NSRect viewFrame = [self frame];
NSSize imageSize = [self.screen.image size];
CGFloat viewSize = MAX(imageSize.width, imageSize.height);
CGFloat width = windowFrame.size.width - viewFrame.size.width + viewSize;
CGFloat height = windowFrame.size.height - viewFrame.size.height + viewSize;
windowFrame = NSMakeRect(windowFrame.origin.x, windowFrame.origin.y, width, height);
[[self window] setFrame: windowFrame display: YES];
[[self window] makeKeyAndOrderFront: self];
}
- (void) drawRect: (NSRect) rect
{
if (self.screen == nil || self.screen.image == nil)
return;
NSGraphicsContext *context = [NSGraphicsContext currentContext];
[context saveGraphicsState];
NSImage * image = self.screen.image;
NSSize imageSize = [image size];
if (rotated)
{
NSAffineTransform * rotate = [NSAffineTransform transform];
[rotate translateXBy: imageSize.height yBy: 0.0];
[rotate rotateByDegrees: 90.0];
[rotate concat];
}
CGFloat offset = (ABS(imageSize.height - imageSize.width))/2.0;
NSAffineTransform * centre = [NSAffineTransform transform];
[centre translateXBy: offset yBy: 0.0];
[centre concat];
[image drawAtPoint: NSZeroPoint fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 1];
if (self.touch != nil)
{
NSRect fingerRect;
CGFloat radius = 20.0;
radius = radius * (self.touch.pressure / 50.0);
fingerRect.origin.x = self.touch.point.x - radius;
fingerRect.origin.y = self.touch.point.y - radius;
fingerRect.size.width = 2 * radius;
fingerRect.size.height = 2 * radius;
[[NSColor colorWithCalibratedRed: 1.0 green: 0.3 blue: 0.1 alpha: 0.5] set];
[[NSBezierPath bezierPathWithOvalInRect: fingerRect] fill];
}
[context restoreGraphicsState];
}
- (void) dealloc
{
self.screen = nil;
self.touch = nil;
[super dealloc];
}
@end