forked from pixmeo/osirix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLLScoutView.m
336 lines (274 loc) · 9.6 KB
/
LLScoutView.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*=========================================================================
Program: OsiriX
Copyright (c) OsiriX Team
All rights reserved.
Distributed under GNU - LGPL
See http://www.osirix-viewer.com/copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
=========================================================================*/
#import "OrthogonalMPRController.h"
#import "LLScoutView.h"
#import "DCMPix.h"
#import "OrthogonalMPRController.h"
#import "LLScoutViewer.h"
@implementation LLScoutView
-(void)setTopLimit:(int)newLimit
{
topLimit = newLimit;
}
-(void)setBottomLimit:(int)newLimit;
{
bottomLimit = newLimit;
}
-(void)setIsFlipped:(BOOL)boo;
{
isFlipped = boo;
}
- (void)subDrawRect:(NSRect)aRect
{
CGLContextObj cgl_ctx = [[NSOpenGLContext currentContext] CGLContextObj];
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
float positions[3];
[self getOpenGLLimitPosition:positions];
NSRect viewFrame = [self frame];
float halfViewFrameWidth = viewFrame.size.width/2.0;
glColor3f(0.0f, 1.0f, 0.0f);
glLineWidth(1.0 * self.window.backingScaleFactor);
glTranslatef( -origin.x, 0.0f, 0.0f);
glBegin(GL_LINES);
glVertex2f(-halfViewFrameWidth, positions[0]);
glVertex2f(halfViewFrameWidth, positions[0]);
glVertex2f(-halfViewFrameWidth, positions[1]);
glVertex2f(halfViewFrameWidth, positions[1]);
glEnd();
[self drawArrowButtonAtPosition: positions[0]];
[self drawArrowButtonAtPosition: positions[1]];
[self drawArrowButtonAtPosition: positions[2]];
glTranslatef(origin.x, 0.0f, 0.0f);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_POLYGON_SMOOTH);
glDisable(GL_POINT_SMOOTH);
glDisable(GL_BLEND);
}
- (void)getOpenGLLimitPosition:(float*)positions;
{
float topLimitPosition, bottomLimitPosition;
if (isFlipped)
{
topLimitPosition = (float)[[controller originalDCMPixList] count] - (float)topLimit - 1.0;
bottomLimitPosition = (float)[[controller originalDCMPixList] count] - (float)bottomLimit - 1.0;
}
else
{
topLimitPosition = (float)topLimit;
bottomLimitPosition = (float)bottomLimit;
}
topLimitPosition = (topLimitPosition - [[self curDCM] pheight]/2.0) * scaleValue;
bottomLimitPosition = (bottomLimitPosition - [[self curDCM] pheight]/2.0) * scaleValue;
positions[0] = topLimitPosition;
positions[1] = bottomLimitPosition;
positions[2] = (float)[[self curDCM] pheight]/2.0 * scaleValue;
}
const float ArrowButtonBottomMargin = 7.0, ArrowButtonRightMargin = 6.0, ArrowButtonTriangleHeight = 10.0, ArrowButtonTriangleHalfBasis = 5.0;
- (void)drawArrowButtonAtPosition:(float)position;
{
NSRect viewFrame = [self frame];
float ArrowButtonRightSide = viewFrame.size.width/2.0 - ArrowButtonRightMargin;
float ArrowButtonLeftSide = ArrowButtonRightSide - ArrowButtonTriangleHeight;
float centerX, centerY;
centerX = (2.0*ArrowButtonLeftSide+ArrowButtonRightSide)/3.0;
centerY = position-(ArrowButtonBottomMargin+ArrowButtonTriangleHalfBasis)*[curDCM pixelSpacingX]/[curDCM pixelSpacingY];
float radius = ArrowButtonRightSide - centerX + 2.0;
CGLContextObj cgl_ctx = [[NSOpenGLContext currentContext] CGLContextObj];
// circle border
glColor3f(0.6f, 0.6f, 0.733f);
glPointSize((radius+1.0)*2.0);
glBegin(GL_POINTS);
glVertex2f(centerX, centerY);
glEnd();
// circle
glColor3f(0.4f, 0.4f, 0.6f);
glPointSize(radius*2.0);
glBegin(GL_POINTS);
glVertex2f(centerX, centerY);
glEnd();
// triangle
glLineWidth(1.0 * self.window.backingScaleFactor);
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_TRIANGLES);
glVertex2f(ArrowButtonLeftSide,position-ArrowButtonBottomMargin*[curDCM pixelSpacingX]/[curDCM pixelSpacingY]);
glVertex2f(ArrowButtonLeftSide,position-(ArrowButtonBottomMargin+2*ArrowButtonTriangleHalfBasis)*[curDCM pixelSpacingX]/[curDCM pixelSpacingY]);
glVertex2f(ArrowButtonRightSide,position-(ArrowButtonBottomMargin+ArrowButtonTriangleHalfBasis)*[curDCM pixelSpacingX]/[curDCM pixelSpacingY]);
glEnd();
}
- (NSRect)rectForArrowButtonAtIndex:(int)index;
{
float positions[3];
[self getOpenGLLimitPosition:positions];
NSRect viewFrame = [self frame];
float ArrowButtonRightSide = viewFrame.size.width/2.0 - ArrowButtonRightMargin;
float ArrowButtonLeftSide = ArrowButtonRightSide - ArrowButtonTriangleHeight;
float centerX = (2.0*ArrowButtonLeftSide+ArrowButtonRightSide)/3.0;
float centerY = positions[index]-(ArrowButtonBottomMargin+ArrowButtonTriangleHalfBasis)*[curDCM pixelSpacingX]/[curDCM pixelSpacingY];
float radius = ArrowButtonRightSide - centerX + 2.0;
float diameter = 2.0 * radius;
NSRect rectForArrowButton = NSMakeRect(centerX-radius-origin.x, centerY-radius*[curDCM pixelSpacingX]/[curDCM pixelSpacingY], diameter, diameter*[curDCM pixelSpacingX]/[curDCM pixelSpacingY]);
return rectForArrowButton;
}
- (NSRect)rectForLimitAtIndex:(int)index;
{
float positions[3];
[self getOpenGLLimitPosition:positions];
NSRect viewFrame = [self frame];
float halfHeight = 5;
NSRect rectForArrowButton = NSMakeRect(-viewFrame.size.width/2.0-origin.x, positions[index]-halfHeight*[curDCM pixelSpacingX]/[curDCM pixelSpacingY], viewFrame.size.width, halfHeight*2.0*[curDCM pixelSpacingX]/[curDCM pixelSpacingY]);
return rectForArrowButton;
}
- (void)mouseDown:(NSEvent *)event
{
NSPoint eventLocation = [event locationInWindow];
NSPoint tempPt = [self convertPoint:eventLocation fromView: nil];
tempPt = [self ConvertFromNSView2GL:tempPt];
tempPt.x = (tempPt.x - [[self curDCM] pwidth]/2.0) * scaleValue;
tempPt.y = (tempPt.y - [[self curDCM] pheight]/2.0) * scaleValue;
NSRect rect1 = [self rectForArrowButtonAtIndex:0];
NSRect rect2 = [self rectForArrowButtonAtIndex:1];
NSRect rect3 = [self rectForArrowButtonAtIndex:2];
NSRect rectTopLimit = [self rectForLimitAtIndex:0];
NSRect rectBottomLimit = [self rectForLimitAtIndex:1];
start = tempPt;
if(NSPointInRect(tempPt, rect1))
{
[(LLScoutViewer*)[controller viewer] displayMPR:0];
}
else if(NSPointInRect(tempPt, rect2))
{
[(LLScoutViewer*)[controller viewer] displayMPR:1];
}
else if(NSPointInRect(tempPt, rect3))
{
[(LLScoutViewer*)[controller viewer] displayMPR:2];
}
else if(NSPointInRect(tempPt, rectTopLimit))
{
draggingTopLimit = YES;
}
else if(NSPointInRect(tempPt, rectBottomLimit))
{
draggingBottomLimit = YES;
}
else
{
[super mouseDown:event];
}
}
-(void) mouseMoved: (NSEvent*) event
{
if( ![[self window] isVisible])
return;
//NSLog(@"mouseMoved");
NSPoint eventLocation = [event locationInWindow];
NSPoint tempPt = [self convertPoint:eventLocation fromView: nil];
tempPt = [self ConvertFromNSView2GL:tempPt];
tempPt.x = (tempPt.x - [[self curDCM] pwidth]/2.0) * scaleValue;
tempPt.y = (tempPt.y - [[self curDCM] pheight]/2.0) * scaleValue;
NSRect rect1 = [self rectForArrowButtonAtIndex:0];
NSRect rect2 = [self rectForArrowButtonAtIndex:1];
NSRect rect3 = [self rectForArrowButtonAtIndex:2];
NSRect rectTopLimit = [self rectForLimitAtIndex:0];
NSRect rectBottomLimit = [self rectForLimitAtIndex:1];
if(NSPointInRect(tempPt, rect1) || NSPointInRect(tempPt, rect2) || NSPointInRect(tempPt, rect3))
{
[[NSCursor pointingHandCursor] set];
}
else if(NSPointInRect(tempPt, rectTopLimit) || NSPointInRect(tempPt, rectBottomLimit))
{
[[NSCursor resizeUpDownCursor] set];
previous = tempPt;
}
else
{
[super mouseMoved:event];
[cursor set];
}
}
- (void)mouseDragged:(NSEvent *)event
{
//NSLog(@"mouseDragged");
NSRect rectTopLimit = [self rectForLimitAtIndex:0];
NSRect rectBottomLimit = [self rectForLimitAtIndex:1];
NSRect rect1 = [self rectForArrowButtonAtIndex:0];
NSRect rect2 = [self rectForArrowButtonAtIndex:1];
NSRect rect3 = [self rectForArrowButtonAtIndex:2];
if(draggingTopLimit || draggingBottomLimit)
{
NSPoint eventLocation = [event locationInWindow];
NSPoint tempPt = [self convertPoint:eventLocation fromView: nil];
tempPt = [self ConvertFromNSView2GL:tempPt];
tempPt.x = (tempPt.x - [[self curDCM] pwidth]/2.0) * scaleValue;
tempPt.y = (tempPt.y - [[self curDCM] pheight]/2.0) * scaleValue;
int top, bottom;
if(draggingTopLimit)
{
top = (tempPt.y/scaleValue)+[[self curDCM] pheight]/2.0;
top = (isFlipped) ? (float)[[controller originalDCMPixList] count] - (float)top - 1.0 : top ;
bottom = bottomLimit;
}
else
{
top = topLimit;
bottom = (tempPt.y/scaleValue)+[[self curDCM] pheight]/2.0;
bottom = (isFlipped) ? (float)[[controller originalDCMPixList] count] - (float)bottom - 1.0 : bottom ;
}
if(top-bottom < 10)
{
if(draggingTopLimit)
{
bottom -= 10-(top-bottom);
}
if(draggingBottomLimit)
{
top += 10-(top-bottom);
}
}
if(bottom <= 10)
{
bottom = 10;
if(draggingTopLimit && top <= 20)
top = 20;
}
if(top >= (long)[[controller originalDCMPixList] count]-10)
{
top = (long)[[controller originalDCMPixList] count]-10;
if(draggingBottomLimit && bottom >= [[controller originalDCMPixList] count]-20)
bottom = [[controller originalDCMPixList] count]-20;
}
[(LLScoutViewer*)[controller viewer] setTopLimit:top bottomLimit:bottom];
}
else if(NSPointInRect(start, rect1) || NSPointInRect(start, rect2) || NSPointInRect(start, rect3) || NSPointInRect(start, rectTopLimit) || NSPointInRect(start, rectBottomLimit))
{
//NSLog(@"mouseDraged from a arrow button");
}
else
{
[super mouseDragged:event];
}
}
- (void)mouseUp:(NSEvent *)event
{
//NSLog(@"mouseUp");
draggingTopLimit = NO;
draggingBottomLimit = NO;
[super mouseUp:event];
}
- (void) dealloc {
NSLog(@"Scout View dealloc");
[super dealloc];
}
@end