From a2d78e1123c4225b1cff60de6da466fee1fb9f7b Mon Sep 17 00:00:00 2001 From: vp153 Date: Thu, 25 Mar 2010 22:45:32 +0000 Subject: [PATCH] put back Carbon UI as alternative highgui back-end (for MacOSX 10.5 users, where the current Cocoa back-end does not work properly) git-svn-id: https://code.ros.org/svn/opencv/trunk@2909 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08 --- opencv/CMakeLists.txt | 30 +++++++++++++++++++++++------- opencv/src/highgui/CMakeLists.txt | 14 ++++++++++++-- opencv/src/highgui/window_cocoa.mm | 30 ++++++++++++++++++++++-------- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt index 5223ce4f..e9fc0ca6 100644 --- a/opencv/CMakeLists.txt +++ b/opencv/CMakeLists.txt @@ -263,13 +263,19 @@ set(WITH_TIFF ON CACHE BOOL "Include TIFF support") if(UNIX) set(WITH_FFMPEG ON CACHE BOOL "Include FFMPEG support") - set(WITH_UNICAP ON CACHE BOOL "Include Unicap support") - set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support") - set(WITH_GTK ON CACHE BOOL "Include GTK support") - set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support") - set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support") - set(WITH_V4L ON CACHE BOOL "Include Video 4 Linux support") - set(WITH_XINE ON CACHE BOOL "Include Xine support") + if(NOT APPLE) + set(WITH_UNICAP OFF CACHE BOOL "Include Unicap support (GPL)") + set(WITH_GTK ON CACHE BOOL "Include GTK support") + set(WITH_GSTREAMER ON CACHE BOOL "Include Gstreamer support") + set(WITH_V4L ON CACHE BOOL "Include Video 4 Linux support") + set(WITH_XINE OFF CACHE BOOL "Include Xine support (GPL)") + endif() + set(WITH_PVAPI ON CACHE BOOL "Include Prosilica GigE support") + set(WITH_1394 ON CACHE BOOL "Include IEEE1394 support") +endif() + +if(APPLE) + set(WITH_CARBON OFF CACHE BOOL "Use Carbon for UI instead of Cocoa") endif() set(WITH_TBB OFF CACHE BOOL "Include TBB support") @@ -1036,6 +1042,16 @@ message(STATUS " GThread: ${HAVE_GTHREAD}") message(STATUS "") endif() +if(APPLE) +message(STATUS "") +if(HAVE_CARBON) +message(STATUS " GUI Back-end: Carbon") +else() +message(STATUS " GUI Back-end: Cocoa") +endif() +message(STATUS "") +endif() + message(STATUS " Image I/O: ") if(NOT WITH_JPEG OR JPEG_FOUND) message(STATUS " JPEG: ${JPEG_FOUND}") diff --git a/opencv/src/highgui/CMakeLists.txt b/opencv/src/highgui/CMakeLists.txt index 07710c23..f4b64c02 100644 --- a/opencv/src/highgui/CMakeLists.txt +++ b/opencv/src/highgui/CMakeLists.txt @@ -145,11 +145,18 @@ if(UNIX) endif() if(APPLE) - add_definitions(-DHAVE_QUICKTIME=1 -DHAVE_COCOA=1) + add_definitions(-DHAVE_QUICKTIME=1) if(NOT OPENCV_BUILD_3RDPARTY_LIBS) add_definitions(-DHAVE_IMAGEIO=1) endif() - set(highgui_srcs ${highgui_srcs} window_cocoa.mm cvcap_qt.mm) + set(highgui_srcs ${highgui_srcs} cvcap_qt.mm) + if(WITH_CARBON) + add_definitions(-DHAVE_CARBON=1) + set(highgui_srcs ${highgui_srcs} window_carbon.cpp) + else() + add_definitions(-DHAVE_COCOA=1) + set(highgui_srcs ${highgui_srcs} window_cocoa.mm) + endif() endif(APPLE) source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs}) @@ -259,6 +266,9 @@ endif() if(APPLE) target_link_libraries(${the_target} "-framework QTKit -lbz2 -framework Cocoa -framework CoreFoundation -framework QuartzCore") + if(WITH_CARBON) + target_link_libraries(${the_target} "-framework Carbon -framework QuickTime") + endif() endif() install(TARGETS ${the_target} diff --git a/opencv/src/highgui/window_cocoa.mm b/opencv/src/highgui/window_cocoa.mm index 1f9ce0af..06916a14 100644 --- a/opencv/src/highgui/window_cocoa.mm +++ b/opencv/src/highgui/window_cocoa.mm @@ -92,12 +92,12 @@ static bool wasInitialized = false; static void icvCocoaCleanup(void) { - /*if( application ) + if( application ) { [application terminate:nil]; application = 0; [pool release]; - }*/ + } } CV_IMPL int cvInitSystem( int argc, char** argv) @@ -154,23 +154,30 @@ CV_IMPL void cvDestroyAllWindows( void ) CV_IMPL void cvShowImage( const char* name, const CvArr* arr) { CVWindow *window = cvGetWindow(name); - if(window) { + if(!window) + { + cvNamedWindow(name, CV_WINDOW_AUTOSIZE); + window = cvGetWindow(name); + } + + if(window) + { bool empty = [[window contentView] image] == nil; NSRect rect = [window frame]; NSRect vrectOld = [[window contentView] frame]; [[window contentView] setImageData:(CvArr *)arr]; - if([window autosize] || empty) { + if([window autosize] || empty) + { NSRect vrectNew = vrectOld; vrectNew.size = [[[window contentView] image] size]; rect.size.width += vrectNew.size.width - vrectOld.size.width; rect.size.height += vrectNew.size.height - vrectOld.size.height; [window setFrame:rect display:YES]; - } else { - [window display]; } + else + [window display]; } - } CV_IMPL void cvResizeWindow( const char* name, int width, int height) @@ -339,7 +346,14 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) if( !wasInitialized ) cvInitSystem(0, 0); - CVWindow *window = [[CVWindow alloc] initWithContentRect:NSMakeRect(0,0,200,200) + CVWindow *window = cvGetWindow(name); + if( window ) + { + [window setAutosize:(flags == CV_WINDOW_AUTOSIZE)]; + return 0; + } + + window = [[CVWindow alloc] initWithContentRect:NSMakeRect(0,0,200,200) styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask| (!(flags & CV_WND_PROP_AUTOSIZE) ? NSResizableWindowMask : 0) backing:NSBackingStoreBuffered -- 2.39.2