-
Notifications
You must be signed in to change notification settings - Fork 0
/
VNCContentView.m
220 lines (187 loc) · 5.33 KB
/
VNCContentView.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//
// VNCContentView.m
// vnsea
//
// Created by Chris Reed on 9/15/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
// Modified by: Glenn Kreisel
#import "VNCContentView.h"
#import "VnseaApp.h"
@implementation VNCContentView
- (id)initWithFrame:(CGRect)frame
{
if ([super initWithFrame:frame])
{
[self setOpaque:YES];
[self setAlpha:1.0f];
}
_scalePercent = 0.50f;
return self;
}
- (void)dealloc
{
[_frameBuffer release];
[super dealloc];
}
- (UIHardwareOrientation)getOrientationState
{
return _orientationState;
}
- (void)setDelegate:(id)newDelegate
{
_delegate = newDelegate;
}
- (id)delegate
{
return _delegate;
}
- (void)setOrientationState:(UIHardwareOrientation)wState
{
_orientationState = wState;
switch (wState)
{
case kOrientationHorizontalRight:
_orientationDeg = -90;
break;
case kOrientationHorizontalLeft:
_orientationDeg = 90;
break;
case kOrientationVertical:
_orientationDeg = 180;
break;
case kOrientationVerticalUpsideDown:
_orientationDeg = 0;
break;
}
}
- (void)setOrientationDeg:(float)wDeg
{
_orientationDeg = wDeg;
}
- (float)getOrientationDeg
{
return _orientationDeg;
}
- (float)getScalePercent
{
return _scalePercent;
}
- (CGRect)getFrame
{
return _frame;
}
- (void)setScalePercent:(float)wScale
{
_scalePercent = wScale;
}
- (void)setFrameBuffer:(FrameBuffer *)buffer
{
[_frameBuffer autorelease];
if (buffer)
{
_frameBuffer = [buffer retain];
CGRect f = [self frame];
f.size = [buffer size];
[self setFrame:f];
}
else
{
_frameBuffer = nil;
}
}
- (CGPoint)getIPodScreenPoint:(CGRect)r bounds:(CGRect)bounds
{
CGPoint ptIPod = CGPointApplyAffineTransform(r.origin, _matrixPreviousTransform);
CGRect rcFrame = _frame;
switch (_orientationState)
{
case kOrientationVerticalUpsideDown:
ptIPod.x = (rcFrame.size.width + ptIPod.x) - bounds.origin.x;
ptIPod.y = (rcFrame.size.height - ptIPod.y) - bounds.origin.y;
break;
case kOrientationVertical:
ptIPod.x = ptIPod.x - bounds.origin.x;
ptIPod.y = 0 - (ptIPod.y + bounds.origin.y);
break;
case kOrientationHorizontalRight:
ptIPod.x = 0 - (ptIPod.x + bounds.origin.x);
ptIPod.y = (rcFrame.size.height + ptIPod.y) - bounds.origin.y ;
break;
case kOrientationHorizontalLeft:
ptIPod.x = (rcFrame.size.width - ptIPod.x) - bounds.origin.x;
ptIPod.y = (ptIPod.y - bounds.origin.y);
break;
}
return ptIPod;
}
- (void)setRemoteDisplaySize:(CGSize)remoteSize animate:(BOOL)bAnimate
{
CGRect bounds = [self bounds];
CGRect frame = CGRectMake(0,0, remoteSize.width, remoteSize.height);
// NSLog(@"Frame = %f %f %f %f", frame.origin.x, frame.origin.y, frame.size.width,frame.size.height);
// NSLog(@"Bounds = %f %f %f %f ", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
// NSLog(@"RemoteSize = %f %f", remoteSize.width, remoteSize.height);
_frame = frame;
[self setFrame:frame];
[self setBounds:bounds];
// Set our transformation matrix so that we're inverted top to bottom.
// This accounts for the bitmap being drawn inverted. If we don't set the
// matrix after setting the bounds, then we'd have to translate in addition
// to scale.
//! @todo This should be fixed by rendering the bitmap correctly.
CGAffineTransform matrix = CGAffineTransformRotate(CGAffineTransformMakeScale(0-_scalePercent, _scalePercent), _orientationDeg * M_PI / 180.0f);
if (bAnimate)
{
UITransformAnimation *scaleAnim = [[UITransformAnimation alloc] initWithTarget: self];
[scaleAnim setStartTransform: _matrixPreviousTransform];
[scaleAnim setEndTransform: matrix];
UIAnimator *anim = [[UIAnimator alloc] init];
[anim addAnimation:scaleAnim withDuration:0.30f start:YES];
}
[self setTransform:matrix];
_matrixPreviousTransform = matrix;
}
- (void)drawRect:(CGRect)destRect
{
if (_frameBuffer)
{
CGRect b = [self bounds];
CGRect r = destRect;
CGContextRef context = UICurrentContext();
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
r.origin.y = b.size.height - CGRectGetMaxY(r);
[_frameBuffer drawRect:r at:destRect.origin];
}
else
{
// When not in connection put some text on the screen
// instead of just BLACK
CGRect b = [self bounds];
char _szBubbleText[100] = "Processing...";
CGContextRef context = UICurrentContext();
CGContextSaveGState(context);
NSLog(@"Drawing Text");
CGContextSetRGBFillColor(context, 0, 0, 0, 1);
CGContextFillRect(context, destRect);
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextSetRGBStrokeColor(context, 1, 1, 1, .7);
CGContextSelectFont(context, "MarkerFeltThin", 35.0, kCGEncodingMacRoman);
CGContextSetTextPosition(context, 0, 0);
CGPoint ptBefore = CGContextGetTextPosition(context);
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowText(context, _szBubbleText, strlen(_szBubbleText));
CGPoint ptAfter = CGContextGetTextPosition(context);
float dxText = ptAfter.x - ptBefore.x;
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowTextAtPoint(context, (b.size.width/2)-(dxText / 2), (b.size.height/2) - 6, _szBubbleText, strlen(_szBubbleText));
CGContextRestoreGState(context);
}
}
- (void)displayFromBuffer:(CGRect)aRect
{
CGRect b = [self bounds];
CGRect r = aRect;
r.origin.y = b.size.height - CGRectGetMaxY(r);
[self setNeedsDisplayInRect:r];
}
@end