41 |
41 |
//
|
42 |
42 |
//M*/
|
43 |
43 |
|
|
44 |
#import <TargetConditionals.h>
|
|
45 |
|
|
46 |
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
|
|
47 |
/*** begin IPhone OS Stubs ***/
|
|
48 |
// When highgui functions are referred to on iPhone OS, they will fail silently.
|
|
49 |
CV_IMPL int cvInitSystem( int argc, char** argv) { return 0;}
|
|
50 |
CV_IMPL int cvStartWindowThread(){ return 0; }
|
|
51 |
CV_IMPL void cvDestroyWindow( const char* name) {}
|
|
52 |
CV_IMPL void cvDestroyAllWindows( void ) {}
|
|
53 |
CV_IMPL void cvShowImage( const char* name, const CvArr* arr) {}
|
|
54 |
CV_IMPL void cvResizeWindow( const char* name, int width, int height) {}
|
|
55 |
CV_IMPL void cvMoveWindow( const char* name, int x, int y){}
|
|
56 |
CV_IMPL int cvCreateTrackbar (const char* trackbar_name,const char* window_name,
|
|
57 |
int* val, int count, CvTrackbarCallback on_notify) {return 0;}
|
|
58 |
CV_IMPL int cvCreateTrackbar2(const char* trackbar_name,const char* window_name,
|
|
59 |
int* val, int count, CvTrackbarCallback2 on_notify2, void* userdata) {return 0;}
|
|
60 |
CV_IMPL void cvSetMouseCallback( const char* name, CvMouseCallback function, void* info) {}
|
|
61 |
CV_IMPL int cvGetTrackbarPos( const char* trackbar_name, const char* window_name ) {return 0;}
|
|
62 |
CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos) {}
|
|
63 |
CV_IMPL void* cvGetWindowHandle( const char* name ) {return NULL;}
|
|
64 |
CV_IMPL const char* cvGetWindowName( void* window_handle ) {return NULL;}
|
|
65 |
CV_IMPL int cvNamedWindow( const char* name, int flags ) {return 0; }
|
|
66 |
CV_IMPL int cvWaitKey (int maxWait) {return 0;}
|
|
67 |
//*** end IphoneOS Stubs ***/
|
|
68 |
#else
|
|
69 |
|
|
70 |
|
44 |
71 |
#import <Cocoa/Cocoa.h>
|
45 |
72 |
#include "precomp.hpp"
|
46 |
73 |
|
|
74 |
#include <iostream>
|
|
75 |
using namespace std;
|
|
76 |
|
47 |
77 |
const int TOP_BORDER = 7;
|
48 |
78 |
|
49 |
79 |
static NSApplication *application = nil;
|
... | ... | |
54 |
84 |
@interface CVView : NSView {
|
55 |
85 |
NSImage *image;
|
56 |
86 |
}
|
57 |
|
@property(assign) NSImage *image;
|
|
87 |
@property(retain) NSImage *image;
|
58 |
88 |
- (void)setImageData:(CvArr *)arr;
|
59 |
89 |
@end
|
60 |
90 |
|
... | ... | |
66 |
96 |
CvTrackbarCallback callback;
|
67 |
97 |
CvTrackbarCallback2 callback2;
|
68 |
98 |
}
|
69 |
|
@property(assign) NSSlider *slider;
|
70 |
|
@property(assign) NSTextField *name;
|
|
99 |
@property(retain) NSSlider *slider;
|
|
100 |
@property(retain) NSTextField *name;
|
71 |
101 |
@property(assign) int *value;
|
72 |
102 |
@property(assign) void *userData;
|
73 |
103 |
@property(assign) CvTrackbarCallback callback;
|
... | ... | |
79 |
109 |
CvMouseCallback mouseCallback;
|
80 |
110 |
void *mouseParam;
|
81 |
111 |
BOOL autosize;
|
|
112 |
BOOL firstContent;
|
82 |
113 |
}
|
83 |
114 |
@property(assign) CvMouseCallback mouseCallback;
|
84 |
115 |
@property(assign) void *mouseParam;
|
85 |
116 |
@property(assign) BOOL autosize;
|
86 |
|
@property(assign) NSMutableDictionary *sliders;
|
|
117 |
@property(assign) BOOL firstContent;
|
|
118 |
@property(retain) NSMutableDictionary *sliders;
|
87 |
119 |
- (CVView *)contentView;
|
88 |
120 |
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags;
|
89 |
121 |
- (void)cvMouseEvent:(NSEvent *)event;
|
... | ... | |
92 |
124 |
|
93 |
125 |
static void icvCocoaCleanup(void)
|
94 |
126 |
{
|
|
127 |
//cout << "icvCocoaCleanup" << endl;
|
95 |
128 |
if( application )
|
96 |
129 |
{
|
97 |
|
[application terminate:nil];
|
|
130 |
cvDestroyAllWindows();
|
|
131 |
//[application terminate:nil];
|
98 |
132 |
application = 0;
|
99 |
133 |
[pool release];
|
100 |
134 |
}
|
... | ... | |
102 |
136 |
|
103 |
137 |
CV_IMPL int cvInitSystem( int argc, char** argv)
|
104 |
138 |
{
|
|
139 |
//cout << "cvInitSystem" << endl;
|
105 |
140 |
wasInitialized = true;
|
106 |
141 |
|
107 |
142 |
pool = [[NSAutoreleasePool alloc] init];
|
... | ... | |
116 |
151 |
if( floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5 )
|
117 |
152 |
[application setActivationPolicy:0/*NSApplicationActivationPolicyRegular*/];
|
118 |
153 |
#endif
|
119 |
|
[application finishLaunching];
|
120 |
|
atexit(icvCocoaCleanup);
|
|
154 |
//[application finishLaunching];
|
|
155 |
//atexit(icvCocoaCleanup);
|
121 |
156 |
|
122 |
157 |
return 0;
|
123 |
158 |
}
|
124 |
159 |
|
125 |
160 |
CVWindow *cvGetWindow(const char *name) {
|
126 |
|
NSString *cvname = [NSString stringWithFormat:@"%s", name];
|
127 |
|
return (CVWindow *)[windows valueForKey:cvname];
|
|
161 |
//cout << "cvGetWindow" << endl;
|
|
162 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
|
163 |
NSString *cvname = [NSString stringWithFormat:@"%s", name];
|
|
164 |
CVWindow* retval = (CVWindow*) [windows valueForKey:cvname] ;
|
|
165 |
//cout << "retain count: " << [retval retainCount] << endl;
|
|
166 |
//retval = [retval retain];
|
|
167 |
//cout << "retain count: " << [retval retainCount] << endl;
|
|
168 |
[localpool drain];
|
|
169 |
//cout << "retain count: " << [retval retainCount] << endl;
|
|
170 |
return retval;
|
128 |
171 |
}
|
129 |
172 |
|
130 |
173 |
CV_IMPL int cvStartWindowThread()
|
131 |
174 |
{
|
|
175 |
//cout << "cvStartWindowThread" << endl;
|
132 |
176 |
return 0;
|
133 |
177 |
}
|
134 |
178 |
|
135 |
179 |
CV_IMPL void cvDestroyWindow( const char* name)
|
136 |
180 |
{
|
|
181 |
|
|
182 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
|
183 |
//cout << "cvDestroyWindow" << endl;
|
137 |
184 |
CVWindow *window = cvGetWindow(name);
|
138 |
185 |
if(window) {
|
139 |
186 |
[window performClose:nil];
|
140 |
187 |
[windows removeObjectForKey:[NSString stringWithFormat:@"%s", name]];
|
141 |
188 |
}
|
|
189 |
[localpool drain];
|
142 |
190 |
}
|
143 |
191 |
|
144 |
192 |
|
145 |
193 |
CV_IMPL void cvDestroyAllWindows( void )
|
146 |
194 |
{
|
|
195 |
//cout << "cvDestroyAllWindows" << endl;
|
|
196 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
147 |
197 |
for(NSString *key in windows) {
|
148 |
198 |
[[windows valueForKey:key] performClose:nil];
|
149 |
199 |
}
|
150 |
200 |
[windows removeAllObjects];
|
|
201 |
[localpool drain];
|
151 |
202 |
}
|
152 |
203 |
|
153 |
204 |
|
154 |
205 |
CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
|
155 |
206 |
{
|
|
207 |
//cout << "cvShowImage" << endl;
|
|
208 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
156 |
209 |
CVWindow *window = cvGetWindow(name);
|
157 |
210 |
if(!window)
|
158 |
211 |
{
|
... | ... | |
167 |
220 |
NSRect vrectOld = [[window contentView] frame];
|
168 |
221 |
|
169 |
222 |
[[window contentView] setImageData:(CvArr *)arr];
|
170 |
|
if(/*[window autosize] ||*/ empty)
|
|
223 |
if([window autosize] || [window firstContent] || empty)
|
171 |
224 |
{
|
172 |
225 |
NSRect vrectNew = vrectOld;
|
173 |
226 |
vrectNew.size = [[[window contentView] image] size];
|
174 |
227 |
rect.size.width += vrectNew.size.width - vrectOld.size.width;
|
175 |
228 |
rect.size.height += vrectNew.size.height - vrectOld.size.height;
|
|
229 |
rect.origin.y -= vrectNew.size.height - vrectOld.size.height;
|
|
230 |
|
176 |
231 |
[window setFrame:rect display:YES];
|
177 |
232 |
}
|
178 |
233 |
else
|
179 |
234 |
[window display];
|
|
235 |
[window setFirstContent:NO];
|
180 |
236 |
}
|
|
237 |
[localpool drain];
|
181 |
238 |
}
|
182 |
239 |
|
183 |
240 |
CV_IMPL void cvResizeWindow( const char* name, int width, int height)
|
184 |
241 |
{
|
|
242 |
|
|
243 |
//cout << "cvResizeWindow" << endl;
|
|
244 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
185 |
245 |
CVWindow *window = cvGetWindow(name);
|
186 |
246 |
if(window) {
|
187 |
247 |
NSRect frame = [window frame];
|
... | ... | |
189 |
249 |
frame.size.height = height;
|
190 |
250 |
[window setFrame:frame display:YES];
|
191 |
251 |
}
|
|
252 |
[localpool drain];
|
192 |
253 |
}
|
193 |
254 |
|
194 |
255 |
CV_IMPL void cvMoveWindow( const char* name, int x, int y)
|
195 |
256 |
{
|
|
257 |
|
196 |
258 |
CV_FUNCNAME("cvMoveWindow");
|
197 |
259 |
__BEGIN__;
|
198 |
260 |
|
|
261 |
NSAutoreleasePool* localpool1 = [[NSAutoreleasePool alloc] init];
|
199 |
262 |
CVWindow *window = nil;
|
200 |
263 |
|
201 |
264 |
if(name == NULL)
|
202 |
265 |
CV_ERROR( CV_StsNullPtr, "NULL window name" );
|
203 |
|
|
|
266 |
//cout << "cvMoveWindow"<< endl;
|
204 |
267 |
window = cvGetWindow(name);
|
205 |
268 |
if(window) {
|
206 |
269 |
y = [[window screen] frame].size.height - y;
|
207 |
270 |
[window setFrameTopLeftPoint:NSMakePoint(x, y)];
|
208 |
271 |
}
|
|
272 |
[localpool1 drain];
|
209 |
273 |
|
210 |
274 |
__END__;
|
211 |
275 |
}
|
... | ... | |
216 |
280 |
CvTrackbarCallback on_notify)
|
217 |
281 |
{
|
218 |
282 |
CV_FUNCNAME("cvCreateTrackbar");
|
|
283 |
|
219 |
284 |
|
220 |
285 |
int result = 0;
|
221 |
286 |
CVWindow *window = nil;
|
|
287 |
NSAutoreleasePool* localpool2 = nil;
|
222 |
288 |
|
223 |
289 |
__BEGIN__;
|
|
290 |
if (localpool2 != nil) [localpool2 drain];
|
|
291 |
localpool2 = [[NSAutoreleasePool alloc] init];
|
224 |
292 |
|
225 |
293 |
if(window_name == NULL)
|
226 |
294 |
CV_ERROR( CV_StsNullPtr, "NULL window name" );
|
227 |
295 |
|
|
296 |
//cout << "cvCreateTrackbar" << endl ;
|
228 |
297 |
window = cvGetWindow(window_name);
|
229 |
298 |
if(window) {
|
230 |
299 |
[window createSliderWithName:trackbar_name
|
... | ... | |
233 |
302 |
callback:on_notify];
|
234 |
303 |
result = 1;
|
235 |
304 |
}
|
236 |
|
|
|
305 |
[localpool2 drain];
|
237 |
306 |
__END__;
|
238 |
307 |
return result;
|
239 |
308 |
}
|
... | ... | |
245 |
314 |
CvTrackbarCallback2 on_notify2,
|
246 |
315 |
void* userdata)
|
247 |
316 |
{
|
|
317 |
//cout <<"cvCreateTrackbar2" << endl;
|
|
318 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
248 |
319 |
int res = cvCreateTrackbar(trackbar_name, window_name, val, count, NULL);
|
249 |
320 |
if(res) {
|
250 |
321 |
CVSlider *slider = [[cvGetWindow(window_name) sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
251 |
322 |
[slider setCallback2:on_notify2];
|
252 |
323 |
[slider setUserData:userdata];
|
253 |
324 |
}
|
|
325 |
[localpool drain];
|
254 |
326 |
return res;
|
255 |
327 |
}
|
256 |
328 |
|
... | ... | |
261 |
333 |
CV_FUNCNAME("cvSetMouseCallback");
|
262 |
334 |
|
263 |
335 |
CVWindow *window = nil;
|
264 |
|
|
|
336 |
NSAutoreleasePool* localpool3 = nil;
|
265 |
337 |
__BEGIN__;
|
|
338 |
//cout << "cvSetMouseCallback" << endl;
|
266 |
339 |
|
|
340 |
if (localpool3 != nil) [localpool3 drain];
|
|
341 |
localpool3 = [[NSAutoreleasePool alloc] init];
|
|
342 |
|
267 |
343 |
if(name == NULL)
|
268 |
344 |
CV_ERROR( CV_StsNullPtr, "NULL window name" );
|
269 |
345 |
|
... | ... | |
272 |
348 |
[window setMouseCallback:function];
|
273 |
349 |
[window setMouseParam:info];
|
274 |
350 |
}
|
|
351 |
[localpool3 drain];
|
275 |
352 |
|
276 |
353 |
__END__;
|
277 |
354 |
}
|
... | ... | |
282 |
359 |
|
283 |
360 |
CVWindow *window = nil;
|
284 |
361 |
int pos = -1;
|
285 |
|
|
|
362 |
NSAutoreleasePool* localpool4 = nil;
|
286 |
363 |
__BEGIN__;
|
287 |
364 |
|
|
365 |
//cout << "cvGetTrackbarPos" << endl;
|
288 |
366 |
if(trackbar_name == NULL || window_name == NULL)
|
289 |
367 |
CV_ERROR( CV_StsNullPtr, "NULL trackbar or window name" );
|
290 |
368 |
|
|
369 |
if (localpool4 != nil) [localpool4 drain];
|
|
370 |
localpool4 = [[NSAutoreleasePool alloc] init];
|
|
371 |
|
291 |
372 |
window = cvGetWindow(window_name);
|
292 |
373 |
if(window) {
|
293 |
374 |
CVSlider *slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
... | ... | |
295 |
376 |
pos = [[slider slider] intValue];
|
296 |
377 |
}
|
297 |
378 |
}
|
298 |
|
|
|
379 |
[localpool4 drain];
|
299 |
380 |
__END__;
|
300 |
381 |
return pos;
|
301 |
382 |
}
|
... | ... | |
306 |
387 |
|
307 |
388 |
CVWindow *window = nil;
|
308 |
389 |
CVSlider *slider = nil;
|
|
390 |
NSAutoreleasePool* localpool5 = nil;
|
309 |
391 |
|
310 |
392 |
__BEGIN__;
|
311 |
|
|
|
393 |
//cout << "cvSetTrackbarPos" << endl;
|
312 |
394 |
if(trackbar_name == NULL || window_name == NULL)
|
313 |
395 |
CV_ERROR( CV_StsNullPtr, "NULL trackbar or window name" );
|
314 |
396 |
|
315 |
397 |
if(pos <= 0)
|
316 |
398 |
CV_ERROR( CV_StsOutOfRange, "Bad trackbar maximal value" );
|
317 |
399 |
|
|
400 |
if (localpool5 != nil) [localpool5 drain];
|
|
401 |
localpool5 = [[NSAutoreleasePool alloc] init];
|
|
402 |
|
318 |
403 |
window = cvGetWindow(window_name);
|
319 |
404 |
if(window) {
|
320 |
405 |
slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
... | ... | |
322 |
407 |
[[slider slider] setIntValue:pos];
|
323 |
408 |
}
|
324 |
409 |
}
|
|
410 |
[localpool5 drain];
|
325 |
411 |
|
326 |
412 |
__END__;
|
327 |
413 |
}
|
328 |
414 |
|
329 |
415 |
CV_IMPL void* cvGetWindowHandle( const char* name )
|
330 |
416 |
{
|
|
417 |
//cout << "cvGetWindowHandle" << endl;
|
331 |
418 |
return cvGetWindow(name);
|
332 |
419 |
}
|
333 |
420 |
|
334 |
421 |
|
335 |
422 |
CV_IMPL const char* cvGetWindowName( void* window_handle )
|
336 |
423 |
{
|
|
424 |
//cout << "cvGetWindowName" << endl;
|
|
425 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
337 |
426 |
for(NSString *key in windows) {
|
338 |
|
if([windows valueForKey:key] == window_handle)
|
|
427 |
if([windows valueForKey:key] == window_handle) {
|
|
428 |
[localpool drain];
|
339 |
429 |
return [key UTF8String];
|
|
430 |
}
|
340 |
431 |
}
|
|
432 |
[localpool drain];
|
341 |
433 |
return 0;
|
342 |
434 |
}
|
343 |
435 |
|
... | ... | |
346 |
438 |
if( !wasInitialized )
|
347 |
439 |
cvInitSystem(0, 0);
|
348 |
440 |
|
|
441 |
//cout << "cvNamedWindow" << endl;
|
|
442 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
349 |
443 |
CVWindow *window = cvGetWindow(name);
|
350 |
444 |
if( window )
|
351 |
445 |
{
|
352 |
446 |
[window setAutosize:(flags == CV_WINDOW_AUTOSIZE)];
|
|
447 |
[localpool drain];
|
353 |
448 |
return 0;
|
354 |
449 |
}
|
355 |
|
|
356 |
|
window = [[CVWindow alloc] initWithContentRect:NSMakeRect(0,0,200,200)
|
357 |
|
styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|
|
358 |
|
(!(flags & CV_WND_PROP_AUTOSIZE) ? NSResizableWindowMask : 0)
|
359 |
|
backing:NSBackingStoreBuffered
|
360 |
|
defer:NO];
|
361 |
450 |
|
|
451 |
NSScreen* mainDisplay = [NSScreen mainScreen];
|
|
452 |
|
362 |
453 |
NSString *windowName = [NSString stringWithFormat:@"%s", name];
|
|
454 |
NSUInteger showResize = (flags == CV_WINDOW_AUTOSIZE) ? 0: NSResizableWindowMask ;
|
|
455 |
NSUInteger styleMask = NSTitledWindowMask|NSMiniaturizableWindowMask|showResize;
|
|
456 |
CGFloat windowWidth = [NSWindow minFrameWidthWithTitle:windowName styleMask:styleMask];
|
|
457 |
NSRect initContentRect = NSMakeRect(0, 0, windowWidth, 0);
|
|
458 |
if (mainDisplay) {
|
|
459 |
NSRect dispFrame = [mainDisplay visibleFrame];
|
|
460 |
initContentRect.origin.y = dispFrame.size.height-20;
|
|
461 |
}
|
|
462 |
|
363 |
463 |
|
|
464 |
window = [[CVWindow alloc] initWithContentRect:initContentRect
|
|
465 |
styleMask:NSTitledWindowMask|NSMiniaturizableWindowMask|showResize
|
|
466 |
backing:NSBackingStoreBuffered
|
|
467 |
defer:YES
|
|
468 |
screen:mainDisplay];
|
|
469 |
|
|
470 |
[window setFrameTopLeftPoint:initContentRect.origin];
|
|
471 |
|
|
472 |
[window setFirstContent:YES];
|
|
473 |
|
364 |
474 |
[window setContentView:[[CVView alloc] init]];
|
365 |
475 |
|
366 |
476 |
[window setHasShadow:YES];
|
... | ... | |
372 |
482 |
[window setAutosize:(flags == CV_WINDOW_AUTOSIZE)];
|
373 |
483 |
|
374 |
484 |
[windows setValue:window forKey:windowName];
|
375 |
|
|
|
485 |
|
|
486 |
[localpool drain];
|
376 |
487 |
return [windows count]-1;
|
377 |
488 |
}
|
378 |
489 |
|
379 |
490 |
CV_IMPL int cvWaitKey (int maxWait)
|
380 |
491 |
{
|
|
492 |
//cout << "cvWaitKey" << endl;
|
381 |
493 |
int returnCode = -1;
|
382 |
494 |
double start = [[NSDate date] timeIntervalSince1970];
|
383 |
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
495 |
NSAutoreleasePool *localpool = [[NSAutoreleasePool alloc] init];
|
384 |
496 |
|
385 |
497 |
while(true) {
|
386 |
498 |
if(([[NSDate date] timeIntervalSince1970] - start) * 1000 >= maxWait && maxWait>0)
|
387 |
499 |
break;
|
388 |
500 |
|
389 |
501 |
//event = [application currentEvent];
|
390 |
|
[pool release];
|
391 |
|
pool = [[NSAutoreleasePool alloc] init];
|
|
502 |
[localpool drain];
|
|
503 |
localpool = [[NSAutoreleasePool alloc] init];
|
392 |
504 |
|
393 |
505 |
NSEvent *event =
|
394 |
506 |
[application
|
... | ... | |
408 |
520 |
|
409 |
521 |
[NSThread sleepForTimeInterval:1/100.];
|
410 |
522 |
}
|
411 |
|
[pool release];
|
|
523 |
[localpool drain];
|
412 |
524 |
|
413 |
525 |
return returnCode;
|
414 |
526 |
}
|
... | ... | |
418 |
530 |
@synthesize mouseCallback;
|
419 |
531 |
@synthesize mouseParam;
|
420 |
532 |
@synthesize autosize;
|
|
533 |
@synthesize firstContent;
|
421 |
534 |
@synthesize sliders;
|
422 |
535 |
|
423 |
536 |
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
|
|
537 |
//cout << "cvSendMouseEvent" << endl;
|
424 |
538 |
NSPoint mp = [NSEvent mouseLocation];
|
425 |
539 |
NSRect visible = [[self contentView] frame];
|
426 |
540 |
mp = [self convertScreenToBase: mp];
|
... | ... | |
444 |
558 |
}
|
445 |
559 |
|
446 |
560 |
- (void)cvMouseEvent:(NSEvent *)event {
|
|
561 |
//cout << "cvMouseEvent" << endl;
|
447 |
562 |
if(!mouseCallback)
|
448 |
563 |
return;
|
449 |
564 |
|
... | ... | |
464 |
579 |
if([event type] == NSOtherMouseDragged) {[self cvSendMouseEvent:event type:CV_EVENT_MOUSEMOVE flags:flags | CV_EVENT_FLAG_MBUTTON];}
|
465 |
580 |
}
|
466 |
581 |
- (void)keyDown:(NSEvent *)theEvent {
|
|
582 |
//cout << "keyDown" << endl;
|
467 |
583 |
[super keyDown:theEvent];
|
468 |
584 |
}
|
469 |
585 |
- (void)rightMouseDragged:(NSEvent *)theEvent {
|
|
586 |
//cout << "rightMouseDragged" << endl ;
|
470 |
587 |
[self cvMouseEvent:theEvent];
|
471 |
588 |
}
|
472 |
589 |
- (void)rightMouseUp:(NSEvent *)theEvent {
|
|
590 |
//cout << "rightMouseUp" << endl;
|
473 |
591 |
[self cvMouseEvent:theEvent];
|
474 |
592 |
}
|
475 |
593 |
- (void)rightMouseDown:(NSEvent *)theEvent {
|
476 |
594 |
// Does not seem to work?
|
|
595 |
//cout << "rightMouseDown" << endl;
|
477 |
596 |
[self cvMouseEvent:theEvent];
|
478 |
597 |
}
|
479 |
598 |
- (void)mouseMoved:(NSEvent *)theEvent {
|
... | ... | |
499 |
618 |
}
|
500 |
619 |
|
501 |
620 |
- (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)value callback:(CvTrackbarCallback)callback {
|
|
621 |
//cout << "createSliderWithName" << endl;
|
502 |
622 |
if(sliders == nil)
|
503 |
623 |
sliders = [[NSMutableDictionary alloc] init];
|
504 |
624 |
|
... | ... | |
512 |
632 |
CVSlider *slider = [[CVSlider alloc] init];
|
513 |
633 |
[[slider name] setStringValue:cvname];
|
514 |
634 |
[[slider slider] setMaxValue:max];
|
|
635 |
[[slider slider] setMinValue:0];
|
|
636 |
[[slider slider] setNumberOfTickMarks:(max+1)];
|
|
637 |
[[slider slider] setAllowsTickMarkValuesOnly:YES];
|
515 |
638 |
if(value)
|
516 |
639 |
{
|
517 |
640 |
[[slider slider] setIntValue:*value];
|
... | ... | |
527 |
650 |
// Update slider sizes
|
528 |
651 |
[[self contentView] setFrameSize:[[self contentView] frame].size];
|
529 |
652 |
[[self contentView] setNeedsDisplay:YES];
|
|
653 |
|
|
654 |
|
|
655 |
int height = 0;
|
|
656 |
for(NSString *key in sliders) {
|
|
657 |
height += [[sliders valueForKey:key] frame].size.height;
|
|
658 |
}
|
|
659 |
[self setContentMinSize:NSMakeSize(0, height)];
|
530 |
660 |
}
|
531 |
661 |
|
532 |
662 |
- (CVView *)contentView {
|
... | ... | |
540 |
670 |
@synthesize image;
|
541 |
671 |
|
542 |
672 |
- (id)init {
|
|
673 |
//cout << "CVView init" << endl;
|
543 |
674 |
[super init];
|
544 |
|
image = nil;
|
|
675 |
image = [[NSImage alloc] init];
|
545 |
676 |
return self;
|
546 |
677 |
}
|
547 |
678 |
|
548 |
679 |
- (void)setImageData:(CvArr *)arr {
|
|
680 |
//cout << "setImageData" << endl;
|
|
681 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
549 |
682 |
CvMat *arrMat, *cvimage, stub;
|
550 |
683 |
|
551 |
684 |
arrMat = cvGetMat(arr, &stub);
|
... | ... | |
567 |
700 |
|
568 |
701 |
CGImageRef imageRef = CGImageCreate(width, height, size , size*nbChannels , cvimage->step, colorspace, kCGImageAlphaNone , provider, NULL, true, kCGRenderingIntentDefault);
|
569 |
702 |
|
570 |
|
NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithCGImage:imageRef] autorelease];
|
|
703 |
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:imageRef];
|
571 |
704 |
if(image) {
|
572 |
705 |
[image release];
|
573 |
706 |
}
|
|
707 |
|
574 |
708 |
image = [[NSImage alloc] init];
|
575 |
709 |
[image addRepresentation:bitmap];
|
|
710 |
[bitmap release];
|
576 |
711 |
|
|
712 |
CGColorSpaceRelease(colorspace);
|
577 |
713 |
CGDataProviderRelease(provider);
|
|
714 |
CGImageRelease(imageRef);
|
578 |
715 |
cvReleaseMat(&cvimage);
|
|
716 |
[localpool drain];
|
579 |
717 |
|
580 |
718 |
[self setNeedsDisplay:YES];
|
|
719 |
|
581 |
720 |
}
|
582 |
721 |
|
583 |
722 |
- (void)setFrameSize:(NSSize)size {
|
|
723 |
//cout << "setFrameSize" << endl;
|
584 |
724 |
[super setFrameSize:size];
|
|
725 |
|
|
726 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
585 |
727 |
int height = size.height;
|
586 |
728 |
|
587 |
|
CVWindow *window = (CVWindow *)[self window];
|
588 |
|
for(NSString *key in [window sliders]) {
|
589 |
|
NSSlider *slider = [[window sliders] valueForKey:key];
|
|
729 |
CVWindow *cvwindow = (CVWindow *)[self window];
|
|
730 |
for(NSString *key in [cvwindow sliders]) {
|
|
731 |
NSSlider *slider = [[cvwindow sliders] valueForKey:key];
|
590 |
732 |
NSRect r = [slider frame];
|
591 |
733 |
r.origin.y = height - r.size.height;
|
592 |
734 |
[slider setFrame:r];
|
593 |
735 |
height -= r.size.height;
|
594 |
736 |
}
|
|
737 |
[localpool drain];
|
595 |
738 |
}
|
596 |
739 |
|
597 |
740 |
- (void)drawRect:(NSRect)rect {
|
598 |
|
CVWindow *window = (CVWindow *)[self window];
|
|
741 |
//cout << "drawRect" << endl;
|
|
742 |
[super drawRect:rect];
|
|
743 |
|
|
744 |
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
|
745 |
CVWindow *cvwindow = (CVWindow *)[self window];
|
599 |
746 |
int height = 0;
|
600 |
|
for(NSString *key in [window sliders]) {
|
601 |
|
height += [[[window sliders] valueForKey:key] frame].size.height;
|
|
747 |
for(NSString *key in [cvwindow sliders]) {
|
|
748 |
height += [[[cvwindow sliders] valueForKey:key] frame].size.height;
|
602 |
749 |
}
|
603 |
750 |
|
604 |
|
[super drawRect:rect];
|
605 |
751 |
|
606 |
752 |
NSRect imageRect = {{0,0}, {self.frame.size.width, self.frame.size.height-height-6}};
|
607 |
753 |
|
... | ... | |
611 |
757 |
operation: NSCompositeSourceOver
|
612 |
758 |
fraction: 1.0];
|
613 |
759 |
}
|
|
760 |
[localpool release];
|
614 |
761 |
|
615 |
762 |
}
|
616 |
763 |
|
... | ... | |
671 |
818 |
|
672 |
819 |
@end
|
673 |
820 |
|
|
821 |
#endif
|
|
822 |
|
674 |
823 |
/* End of file. */
|