1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
10
// Intel License Agreement
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
42
#include "precomp.hpp"
44
#include <Carbon/Carbon.h>
45
#include <Quicktime/Quicktime.h>//YV
51
//#define MS_TO_TICKS(a) a*3/50
54
#define INTERWIDGETSPACE 16
55
#define WIDGETHEIGHT 32
60
typedef struct CvTrackbar
73
int labelSize;//Yannick Verdie
74
CvTrackbarCallback notify;
75
CvTrackbarCallback2 notify2;
81
typedef struct CvWindow
90
WindowRef oldwindow;//YV
101
Ptr restoreState;//YV
103
CvMouseCallback on_mouse;
104
void* on_mouse_param;
116
static CvWindow* hg_windows = 0;
118
#define Assert(exp) \
121
printf("Assertion: %s %s: %d\n", #exp, __FILE__, __LINE__);\
125
static int wasInitialized = 0;
126
static char lastKey = NO_KEY;
127
OSStatus keyHandler(EventHandlerCallRef hcr, EventRef theEvent, void* inUserData);
128
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData);
130
static const EventTypeSpec applicationKeyboardEvents[] =
132
{ kEventClassKeyboard, kEventRawKeyDown },
135
CV_IMPL int cvInitSystem( int argc, char** argv )
138
if( !wasInitialized )
142
err = InstallApplicationEventHandler(NewEventHandlerUPP( keyHandler),GetEventTypeCount(applicationKeyboardEvents),applicationKeyboardEvents,NULL,NULL);
145
fprintf(stderr,"InstallApplicationEventHandler was not ok\n");
149
setlocale(LC_NUMERIC,"C");
154
// TODO: implement missing functionality
155
CV_IMPL int cvStartWindowThread()
160
static int icvCountTrackbarInWindow( const CvWindow* window)
162
CvTrackbar* trackbar = window->toolbar.first;
164
while (trackbar != 0) {
166
trackbar = trackbar->next;
171
static CvTrackbar* icvTrackbarByHandle( void * handle )
173
CvWindow* window = hg_windows;
174
CvTrackbar* trackbar = NULL;
175
while( window != 0 && window->window != handle) {
176
trackbar = window->toolbar.first;
177
while (trackbar != 0 && trackbar->trackbar != handle)
178
trackbar = trackbar->next;
179
if (trackbar != 0 && trackbar->trackbar == handle)
181
window = window->next;
186
static CvWindow* icvWindowByHandle( void * handle )
188
CvWindow* window = hg_windows;
190
while( window != 0 && window->window != handle)
191
window = window->next;
196
CV_IMPL CvWindow * icvFindWindowByName( const char* name)
198
CvWindow* window = hg_windows;
199
while( window != 0 && strcmp(name, window->name) != 0 )
200
window = window->next;
205
static CvTrackbar* icvFindTrackbarByName( const CvWindow* window, const char* name )
207
CvTrackbar* trackbar = window->toolbar.first;
209
while (trackbar != 0 && strcmp( trackbar->name, name ) != 0)
210
trackbar = trackbar->next;
216
/* draw image to frame */
217
static void icvDrawImage( CvWindow* window )
219
Assert( window != 0 );
220
if( window->imageRef == 0 ) return;
222
CGContextRef myContext;
225
int width = window->imageWidth;
226
int height = window->imageHeight;
228
GetWindowPortBounds(window->window, &portrect);
230
if(!( window->flags & CV_WINDOW_AUTOSIZE) ) //YV
232
CGPoint origin = {0,0};
233
CGSize size = {portrect.right-portrect.left, portrect.bottom-portrect.top-window->trackbarheight};
234
rect.origin = origin; rect.size = size;
238
CGPoint origin = {0, portrect.bottom - height - window->trackbarheight};
239
CGSize size = {width, height};
240
rect.origin = origin; rect.size = size;
243
/* To be sybnchronous we are using this, better would be to susbcribe to the draw event and process whenever requested, we might save SOME CPU cycles*/
244
SetPortWindowPort (window->window);
245
QDBeginCGContext (GetWindowPort (window->window), &myContext);
246
CGContextSetInterpolationQuality (myContext, kCGInterpolationLow);
247
CGContextDrawImage(myContext,rect,window->imageRef);
248
CGContextFlush(myContext);// 4
249
QDEndCGContext (GetWindowPort(window->window), &myContext);// 5
253
/* update imageRef */
254
static void icvPutImage( CvWindow* window )
256
Assert( window != 0 );
257
if( window->image == 0 ) return;
259
CGColorSpaceRef colorspace = NULL;
260
CGDataProviderRef provider = NULL;
261
int width = window->imageWidth = window->image->cols;
262
int height = window->imageHeight = window->image->rows;
264
colorspace = CGColorSpaceCreateDeviceRGB();
269
provider = CGDataProviderCreateWithData(NULL, window->image->data.ptr, width * height , NULL );
271
if (window->imageRef != NULL){
272
CGImageRelease(window->imageRef);
273
window->imageRef = NULL;
276
window->imageRef = CGImageCreate( width, height, size , size*nbChannels , window->image->step, colorspace, kCGImageAlphaNone , provider, NULL, true, kCGRenderingIntentDefault );
277
icvDrawImage( window );
279
/* release the provider's memory */
280
CGDataProviderRelease( provider );
283
static void icvUpdateWindowSize( const CvWindow* window )
285
int width = 0, height = 240; /* init à al taille de base de l'image*/
288
GetWindowBounds(window->window, kWindowContentRgn, &globalBounds);
292
if( window->image ) {
293
width = MAX(MAX(window->image->width, width), minWidth);
294
height = window->image->height;
298
height += window->trackbarheight;
300
//height +=WIDGETHEIGHT; /* 32 pixels are spearating tracbars from the video display */
302
globalBounds.right = globalBounds.left + width;
303
globalBounds.bottom = globalBounds.top + height;
304
SetWindowBounds(window->window, kWindowContentRgn, &globalBounds);
307
static void icvDeleteWindow( CvWindow* window )
309
CvTrackbar* trackbar;
312
window->prev->next = window->next;
314
hg_windows = window->next;
317
window->next->prev = window->prev;
319
window->prev = window->next = 0;
321
cvReleaseMat( &window->image );
322
cvReleaseMat( &window->dst_image );
324
for( trackbar = window->toolbar.first; trackbar != 0; )
326
CvTrackbar* next = trackbar->next;
327
cvFree( (void**)&trackbar );
331
if (window->imageRef != NULL)
332
CGImageRelease(window->imageRef);
334
DisposeWindow (window->window);//YV
336
cvFree( (void**)&window );
340
CV_IMPL void cvDestroyWindow( const char* name)
342
CV_FUNCNAME( "cvDestroyWindow" );
349
CV_ERROR( CV_StsNullPtr, "NULL name string" );
351
window = icvFindWindowByName( name );
355
icvDeleteWindow( window );
361
CV_IMPL void cvDestroyAllWindows( void )
365
CvWindow* window = hg_windows;
366
icvDeleteWindow( window );
371
CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
373
CV_FUNCNAME( "cvShowImage" );
383
CV_ERROR( CV_StsNullPtr, "NULL name" );
385
window = icvFindWindowByName(name);
388
cvNamedWindow(name, 1);
389
window = icvFindWindowByName(name);
392
if( !window || !arr )
393
EXIT; // keep silence here.
395
if( CV_IS_IMAGE_HDR( arr ))
396
origin = ((IplImage*)arr)->origin;
398
CV_CALL( image = cvGetMat( arr, &stub ));
402
cvResizeWindow( name, image->cols, image->rows );
406
!CV_ARE_SIZES_EQ(window->image, image) ) {
407
if ( ! (window->flags & CV_WINDOW_AUTOSIZE) )//FD
409
cvReleaseMat( &window->image );
412
if( !window->image ) {
414
window->image = cvCreateMat( image->rows, image->cols, CV_8UC3 );
417
cvConvertImage( image, window->image, (origin != 0 ? CV_CVTIMG_FLIP : 0) + CV_CVTIMG_SWAP_RB );
418
icvPutImage( window );
420
icvUpdateWindowSize( window );
425
CV_IMPL void cvResizeWindow( const char* name, int width, int height)
427
CV_FUNCNAME( "cvResizeWindow" );
432
//CvTrackbar* trackbar;
435
CV_ERROR( CV_StsNullPtr, "NULL name" );
437
window = icvFindWindowByName(name);
441
SizeWindow(window->window, width, height, true);
446
CV_IMPL void cvMoveWindow( const char* name, int x, int y)
448
CV_FUNCNAME( "cvMoveWindow" );
453
//CvTrackbar* trackbar;
456
CV_ERROR( CV_StsNullPtr, "NULL name" );
458
window = icvFindWindowByName(name);
462
MoveWindow(window->window, x, y, true);
467
void TrackbarActionProcPtr (ControlRef theControl, ControlPartCode partCode)
469
CvTrackbar * trackbar = icvTrackbarByHandle (theControl);
471
if (trackbar == NULL)
473
fprintf(stderr,"Error getting trackbar\n");
478
int pos = GetControl32BitValue (theControl);
479
if ( trackbar->data )
480
*trackbar->data = pos;
481
if ( trackbar->notify )
482
trackbar->notify(pos);
483
else if ( trackbar->notify2 )
484
trackbar->notify2(pos, trackbar->userdata);
486
//--------YV---------------------------
487
CFStringEncoding encoding = kCFStringEncodingASCII;
488
CFAllocatorRef alloc_default = kCFAllocatorDefault; // = NULL;
490
char valueinchar[20];
491
sprintf(valueinchar, " (%d)", *trackbar->data);
493
// create an empty CFMutableString
494
CFIndex maxLength = 256;
495
CFMutableStringRef cfstring = CFStringCreateMutable(alloc_default,maxLength);
497
// append some c strings into it.
498
CFStringAppendCString(cfstring,trackbar->name,encoding);
499
CFStringAppendCString(cfstring,valueinchar,encoding);
501
SetControlData(trackbar->label, kControlEntireControl,kControlStaticTextCFStringTag, sizeof(cfstring), &cfstring);
502
DrawControls(trackbar->parent->window);
503
//-----------------------------------------
508
static int icvCreateTrackbar (const char* trackbar_name,
509
const char* window_name,
511
CvTrackbarCallback on_notify,
512
CvTrackbarCallback2 on_notify2,
517
CV_FUNCNAME( "icvCreateTrackbar" );
520
/*char slider_name[32];*/
521
CvWindow* window = 0;
522
CvTrackbar* trackbar = 0;
524
ControlRef outControl;
525
ControlRef stoutControl;
528
if( !window_name || !trackbar_name )
529
CV_ERROR( CV_StsNullPtr, "NULL window or trackbar name" );
532
CV_ERROR( CV_StsOutOfRange, "Bad trackbar maximal value" );
534
window = icvFindWindowByName(window_name);
538
trackbar = icvFindTrackbarByName(window,trackbar_name);
541
int len = strlen(trackbar_name);
542
trackbar = (CvTrackbar*)cvAlloc(sizeof(CvTrackbar) + len + 1);
543
memset( trackbar, 0, sizeof(*trackbar));
544
trackbar->signature = CV_TRACKBAR_MAGIC_VAL;
545
trackbar->name = (char*)(trackbar+1);
546
memcpy( trackbar->name, trackbar_name, len + 1 );
547
trackbar->parent = window;
548
trackbar->next = window->toolbar.first;
549
window->toolbar.first = trackbar;
558
trackbar->pos = value;
559
trackbar->data = val;
562
trackbar->maxval = count;
564
//----------- YV ----------------------
567
while((count/=10)>10){
571
//pad size maxvalue in pixel
573
char valueinchar[strlen(trackbar_name)+1 +1 +1+nbDigit+1];//length+\n +space +(+nbDigit+)
574
sprintf(valueinchar, "%s (%d)",trackbar_name, trackbar->maxval);
576
CFStringRef text = CFStringCreateWithCString(NULL,valueinchar,kCFStringEncodingASCII);
577
GetThemeTextDimensions( text, kThemeCurrentPortFont, kThemeStateActive, false, &qdSize, &baseline );
578
trackbar->labelSize = qdSize.h;
579
//--------------------------------------
581
int c = icvCountTrackbarInWindow(window);
583
GetWindowBounds(window->window,kWindowContentRgn,&bounds);
585
stboundsRect.top = (INTERWIDGETSPACE +WIDGETHEIGHT)* (c-1)+INTERWIDGETSPACE;
586
stboundsRect.left = INTERWIDGETSPACE;
587
stboundsRect.bottom = stboundsRect.top + WIDGETHEIGHT;
588
stboundsRect.right = stboundsRect.left+LABELWIDTH;
590
//fprintf(stdout,"create trackabar bounds (%d %d %d %d)\n",stboundsRect.top,stboundsRect.left,stboundsRect.bottom,stboundsRect.right);
591
//----------- YV ----------------------
592
sprintf(valueinchar, "%s (%d)",trackbar_name, trackbar->pos);
593
CreateStaticTextControl (window->window,&stboundsRect,CFStringCreateWithCString(NULL,valueinchar,kCFStringEncodingASCII),NULL,&stoutControl);
594
//--------------------------------------
596
stboundsRect.top = (INTERWIDGETSPACE +WIDGETHEIGHT)* (c-1)+INTERWIDGETSPACE;
597
stboundsRect.left = INTERWIDGETSPACE*2+LABELWIDTH;
598
stboundsRect.bottom = stboundsRect.top + WIDGETHEIGHT;
599
stboundsRect.right = bounds.right-INTERWIDGETSPACE;
601
CreateSliderControl (window->window,&stboundsRect, trackbar->pos,0,trackbar->maxval,kControlSliderLiveFeedback,0,true,NewControlActionUPP(TrackbarActionProcPtr),&outControl);
603
bounds.bottom += INTERWIDGETSPACE + WIDGETHEIGHT;
604
SetControlVisibility (outControl,true,true);
605
SetControlVisibility (stoutControl,true,true);
607
trackbar->trackbar = outControl;
608
trackbar->label = stoutControl;
610
window->trackbarheight = INTERWIDGETSPACE*2 + WIDGETHEIGHT;
612
window->trackbarheight += INTERWIDGETSPACE + WIDGETHEIGHT;
613
icvUpdateWindowSize( window );
616
trackbar->notify = on_notify;
617
trackbar->notify2 = on_notify2;
618
trackbar->userdata = userdata;
627
CV_IMPL int cvCreateTrackbar (const char* trackbar_name,
628
const char* window_name,
630
CvTrackbarCallback on_notify)
632
return icvCreateTrackbar(trackbar_name, window_name, val, count, on_notify, 0, 0);
636
CV_IMPL int cvCreateTrackbar2(const char* trackbar_name,
637
const char* window_name,
639
CvTrackbarCallback2 on_notify2,
642
return icvCreateTrackbar(trackbar_name, window_name, val,
643
count, 0, on_notify2, userdata);
648
cvSetMouseCallback( const char* name, CvMouseCallback function, void* info)
650
CvWindow* window = icvFindWindowByName( name );
653
window->on_mouse = function;
654
window->on_mouse_param = info;
658
fprintf(stdout,"Error with cvSetMouseCallback. Window not found : %s\n",name);
662
CV_IMPL int cvGetTrackbarPos( const char* trackbar_name, const char* window_name )
666
CV_FUNCNAME( "cvGetTrackbarPos" );
671
CvTrackbar* trackbar = 0;
673
if( trackbar_name == 0 || window_name == 0 )
674
CV_ERROR( CV_StsNullPtr, "NULL trackbar or window name" );
676
window = icvFindWindowByName( window_name );
678
trackbar = icvFindTrackbarByName( window, trackbar_name );
688
CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name, int pos)
690
CV_FUNCNAME( "cvSetTrackbarPos" );
695
CvTrackbar* trackbar = 0;
697
if( trackbar_name == 0 || window_name == 0 )
698
CV_ERROR( CV_StsNullPtr, "NULL trackbar or window name" );
700
window = icvFindWindowByName( window_name );
702
trackbar = icvFindTrackbarByName( window, trackbar_name );
709
if( pos > trackbar->maxval )
710
pos = trackbar->maxval;
712
// Set new value and redraw the trackbar
713
SetControlValue( trackbar->trackbar, pos );
714
Draw1Control( trackbar->trackbar );
721
CV_IMPL void* cvGetWindowHandle( const char* name )
723
WindowRef result = 0;
728
window = icvFindWindowByName( name );
730
result = window->window;
740
CV_IMPL const char* cvGetWindowName( void* window_handle )
742
const char* window_name = "";
744
CV_FUNCNAME( "cvGetWindowName" );
750
if( window_handle == 0 )
751
CV_ERROR( CV_StsNullPtr, "NULL window" );
752
window = icvWindowByHandle(window_handle );
754
window_name = window->name;
761
double cvGetModeWindow_CARBON(const char* name)//YV
765
CV_FUNCNAME( "cvGetModeWindow_QT" );
772
CV_ERROR( CV_StsNullPtr, "NULL name string" );
774
window = icvFindWindowByName( name );
776
CV_ERROR( CV_StsNullPtr, "NULL window" );
778
result = window->status;
784
void cvSetModeWindow_CARBON( const char* name, double prop_value)//Yannick Verdie
786
OSStatus err = noErr;
789
CV_FUNCNAME( "cvSetModeWindow_QT" );
796
CV_ERROR( CV_StsNullPtr, "NULL name string" );
798
window = icvFindWindowByName( name );
800
CV_ERROR( CV_StsNullPtr, "NULL window" );
802
if(window->flags & CV_WINDOW_AUTOSIZE)//if the flag CV_WINDOW_AUTOSIZE is set
805
if (window->status==CV_WINDOW_FULLSCREEN && prop_value==CV_WINDOW_NORMAL)
807
err = EndFullScreen(window->restoreState,0);
809
fprintf(stdout,"Error EndFullScreen\n");
810
window->window = window->oldwindow;
811
ShowWindow( window->window );
813
window->status=CV_WINDOW_NORMAL;
817
if (window->status==CV_WINDOW_NORMAL && prop_value==CV_WINDOW_FULLSCREEN)
820
err = GetWindowGreatestAreaDevice(window->window, kWindowTitleBarRgn, &device, NULL);
822
fprintf(stdout,"Error GetWindowGreatestAreaDevice\n");
824
HideWindow(window->window);
825
window->oldwindow = window->window;
826
err = BeginFullScreen(&(window->restoreState), device, 0, 0, &window->window, 0, fullScreenAllowEvents | fullScreenDontSwitchMonitorResolution);
828
fprintf(stdout,"Error BeginFullScreen\n");
830
window->status=CV_WINDOW_FULLSCREEN;
837
void cv::setWindowTitle(const String& winname, const String& title)
839
CvWindow* window = icvFindWindowByName(winname.c_str());
843
namedWindow(winname);
844
window = icvFindWindowByName(winname.c_str());
848
CV_Error(Error::StsNullPtr, "NULL window");
850
if (noErr != SetWindowTitleWithCFString(window->window, CFStringCreateWithCString(NULL, title.c_str(), kCFStringEncodingASCII)))
851
CV_Error_(Error::StsError, ("Failed to set \"%s\" window title to \"%s\"", winname.c_str(), title.c_str()));
854
CV_IMPL int cvNamedWindow( const char* name, int flags )
857
CV_FUNCNAME( "cvNamedWindow" );
859
cvInitSystem(0, NULL);
861
// to be able to display a window, we need to be a 'faceful' application
862
// http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html
863
static bool switched_to_faceful = false;
864
if (! switched_to_faceful)
866
ProcessSerialNumber psn = { 0, kCurrentProcess };
867
OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication );
871
SetFrontProcess( &psn );
872
switched_to_faceful = true;
876
fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret);
883
WindowRef outWindow = NULL;
884
OSStatus err = noErr;
885
Rect contentBounds = {100,100,320,440};
888
UInt wAttributes = 0;
892
const EventTypeSpec genericWindowEventHandler[] = {
893
{ kEventClassMouse, kEventMouseMoved},
894
{ kEventClassMouse, kEventMouseDragged},
895
{ kEventClassMouse, kEventMouseUp},
896
{ kEventClassMouse, kEventMouseDown},
897
{ kEventClassWindow, kEventWindowClose },
898
{ kEventClassWindow, kEventWindowBoundsChanged }//FD
902
CV_ERROR( CV_StsNullPtr, "NULL name string" );
904
if( icvFindWindowByName( name ) != 0 ){
909
CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));
910
memset( window, 0, sizeof(*window));
911
window->name = (char*)(window + 1);
912
memcpy( window->name, name, len + 1 );
913
window->flags = flags;
914
window->status = CV_WINDOW_NORMAL;//YV
915
window->signature = CV_WINDOW_MAGIC_VAL;
917
window->last_key = 0;
918
window->on_mouse = 0;
919
window->on_mouse_param = 0;
921
window->next = hg_windows;
924
hg_windows->prev = window;
926
wAttributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
929
if (window->flags & CV_WINDOW_AUTOSIZE)//Yannick verdie, remove the handler at the bottom-right position of the window in AUTORESIZE mode
932
wAttributes = kWindowCloseBoxAttribute | kWindowFullZoomAttribute | kWindowCollapseBoxAttribute | kWindowStandardHandlerAttribute | kWindowLiveResizeAttribute;
935
err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow);
937
fprintf(stderr,"Error while creating the window\n");
939
SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString(NULL,name,kCFStringEncodingASCII));
941
fprintf(stdout,"Error SetWindowTitleWithCFString\n");
943
window->window = outWindow;
944
window->oldwindow = 0;//YV
946
err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler), GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow, NULL);
948
ShowWindow( outWindow );
955
static pascal OSStatus windowEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *inUserData)
957
CvWindow* window = NULL;
958
UInt32 eventKind, eventClass;
962
HIPoint point = {0,0};
963
EventMouseButton eventMouseButton = 0;//FD
964
UInt32 modifiers;//FD
966
WindowRef theWindow = (WindowRef)inUserData;
967
if (theWindow == NULL)
968
return eventNotHandledErr;
969
window = icvWindowByHandle(theWindow);
971
return eventNotHandledErr;
973
eventKind = GetEventKind(theEvent);
974
eventClass = GetEventClass(theEvent);
976
switch (eventClass) {
977
case kEventClassMouse : {
980
case kEventMouseDown :
981
case kEventMouseMoved :
982
case kEventMouseDragged : {
983
err = CallNextEventHandler(nextHandler, theEvent);
984
if (err != eventNotHandledErr)
986
err = GetEventParameter(theEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(eventMouseButton), NULL, &eventMouseButton);
987
err = GetEventParameter(theEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers);
988
err = GetEventParameter(theEvent,kEventParamClickCount,typeUInt32,NULL,sizeof(UInt32),NULL,&count);
990
if (count >1) event += 6;
992
event = CV_EVENT_MOUSEMOVE;
995
if (eventKind == kEventMouseUp)
997
if (eventKind == kEventMouseDown)
1000
unsigned int flags = 0;
1002
err = GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point);
1003
if (eventKind != kEventMouseMoved){
1004
switch(eventMouseButton){
1005
case kEventMouseButtonPrimary:
1006
if (modifiers & controlKey){
1007
flags += CV_EVENT_FLAG_RBUTTON;
1010
flags += CV_EVENT_FLAG_LBUTTON;
1013
case kEventMouseButtonSecondary:
1014
flags += CV_EVENT_FLAG_RBUTTON;
1017
case kEventMouseButtonTertiary:
1018
flags += CV_EVENT_FLAG_MBUTTON;
1024
if (modifiers&controlKey) flags += CV_EVENT_FLAG_CTRLKEY;
1025
if (modifiers&shiftKey) flags += CV_EVENT_FLAG_SHIFTKEY;
1026
if (modifiers& cmdKey ) flags += CV_EVENT_FLAG_ALTKEY;
1028
if (window->on_mouse != NULL){
1030
Rect structure, content;
1031
GetWindowBounds(theWindow, kWindowStructureRgn, &structure);
1032
GetWindowBounds(theWindow, kWindowContentRgn, &content);
1033
lx = (int)point.x - content.left + structure.left;
1034
ly = (int)point.y - window->trackbarheight - content.top + structure.top; /* minus la taille des trackbars */
1035
if (window->flags & CV_WINDOW_AUTOSIZE) {//FD
1036
//printf("was %d,%d\n", lx, ly);
1037
/* scale the mouse coordinates */
1038
lx = lx * window->imageWidth / (content.right - content.left);
1039
ly = ly * window->imageHeight / (content.bottom - content.top - window->trackbarheight);
1042
if (lx>0 && ly >0){ /* a remettre dans les coordonnées locale */
1043
window->on_mouse (event, lx, ly, flags, window->on_mouse_param);
1048
default : return eventNotHandledErr;
1051
case kEventClassWindow : {//FD
1053
case kEventWindowBoundsChanged :
1055
/* resize the trackbars */
1058
GetWindowBounds(window->window,kWindowContentRgn,&bounds);
1059
for ( t = window->toolbar.first; t != 0; t = t->next )
1060
SizeControl(t->trackbar,bounds.right - bounds.left - INTERWIDGETSPACE*3 - LABELWIDTH , WIDGETHEIGHT);
1062
/* redraw the image */
1063
icvDrawImage(window);
1066
return eventNotHandledErr;
1070
return eventNotHandledErr;
1073
return eventNotHandledErr;
1076
OSStatus keyHandler(EventHandlerCallRef hcr, EventRef theEvent, void* inUserData)
1082
eventKind = GetEventKind (theEvent);
1083
eventClass = GetEventClass (theEvent);
1084
err = GetEventParameter(theEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof(lastKey), NULL, &lastKey);
1091
CV_IMPL int cvWaitKey (int maxWait)
1093
EventRecord theEvent;
1095
// wait at least for one event (to allow mouse, etc. processing), exit if maxWait milliseconds passed (nullEvent)
1096
UInt32 start = TickCount();
1100
// remaining time until maxWait is over
1101
UInt32 wait = EventTimeToTicks (maxWait / 1000.0) - (TickCount() - start);
1104
if( maxWait > 0 && iters > 0 )
1109
WaitNextEvent (everyEvent, &theEvent, maxWait > 0 ? wait : kDurationForever, NULL);
1111
while (lastKey == NO_KEY && theEvent.what != nullEvent);