Merge pull request #20281 from alalek:highgui_win32ui_plugin

pull/20299/head^2
Alexander Alekhin 3 years ago
commit 9b7dca2fa1
  1. 9
      cmake/OpenCVFindLibsGUI.cmake
  2. 3
      cmake/templates/cvconfig.h.in
  3. 16
      modules/highgui/CMakeLists.txt
  4. 17
      modules/highgui/cmake/detect_win32ui.cmake
  5. 3
      modules/highgui/cmake/init.cmake
  6. 4
      modules/highgui/src/backend.hpp
  7. 8
      modules/highgui/src/precomp.hpp
  8. 8
      modules/highgui/src/registry.impl.hpp
  9. 65
      modules/highgui/src/window.cpp
  10. 3
      modules/highgui/src/window_QT.cpp
  11. 6
      modules/highgui/src/window_cocoa.mm
  12. 4
      modules/highgui/src/window_gtk.cpp
  13. 2331
      modules/highgui/src/window_w32.cpp

@ -2,15 +2,6 @@
# Detect 3rd-party GUI libraries
# ----------------------------------------------------------------------------
#--- Win32 UI ---
ocv_clear_vars(HAVE_WIN32UI)
if(WITH_WIN32UI)
try_compile(HAVE_WIN32UI
"${OpenCV_BINARY_DIR}"
"${OpenCV_SOURCE_DIR}/cmake/checks/win32uitest.cpp"
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=user32;gdi32")
endif()
# --- QT4/5 ---
ocv_clear_vars(HAVE_QT HAVE_QT5)
if(WITH_QT)

@ -121,9 +121,6 @@
/* TIFF codec */
#cmakedefine HAVE_TIFF
/* Win32 UI */
#cmakedefine HAVE_WIN32UI
/* Define if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#cmakedefine WORDS_BIGENDIAN

@ -131,12 +131,6 @@ elseif(WINRT)
message(STATUS " ${name}: Removing 'comctl32.lib, gdi32.lib, ole32.lib, setupapi.lib'")
message(STATUS " ${name}: Leaving '${HIGHGUI_LIBRARIES}'")
endif()
elseif(HAVE_WIN32UI)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WIN32UI")
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_w32.cpp)
if(OpenCV_ARCH STREQUAL "ARM64")
list(APPEND HIGHGUI_LIBRARIES "comdlg32" "advapi32")
endif()
elseif(HAVE_COCOA)
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "COCOA")
add_definitions(-DHAVE_COCOA)
@ -144,6 +138,16 @@ elseif(HAVE_COCOA)
list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
endif()
if(TARGET ocv.3rdparty.win32ui)
if("win32ui" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all")
ocv_create_builtin_highgui_plugin(opencv_highgui_win32 ocv.3rdparty.win32ui "window_w32.cpp")
else()
set(OPENCV_HIGHGUI_BUILTIN_BACKEND "WIN32UI")
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_w32.cpp)
list(APPEND tgts ocv.3rdparty.win32ui)
endif()
endif()
if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
if(TARGET ocv.3rdparty.gtk3 AND NOT WITH_GTK_2_X)
set(__gtk_dependency "ocv.3rdparty.gtk3")

@ -0,0 +1,17 @@
#--- Win32 UI ---
ocv_clear_vars(HAVE_WIN32UI)
if(WITH_WIN32UI)
try_compile(HAVE_WIN32UI
"${CMAKE_CURRENT_BINARY_DIR}"
"${OpenCV_SOURCE_DIR}/cmake/checks/win32uitest.cpp"
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=user32;gdi32")
if(HAVE_WIN32UI)
set(__libs "user32" "gdi32")
if(OpenCV_ARCH STREQUAL "ARM64")
list(APPEND __libs "comdlg32" "advapi32")
endif()
ocv_add_external_target(win32ui "" "${__libs}" "HAVE_WIN32UI")
endif()
endif()
set(HAVE_WIN32UI "${HAVE_WIN32UI}" PARENT_SCOPE) # informational

@ -43,8 +43,7 @@ else()
endif()
add_backend("gtk" WITH_GTK)
# TODO win32
add_backend("win32ui" WITH_WIN32UI)
# TODO cocoa
# TODO qt
# TODO opengl

@ -114,6 +114,10 @@ bool setUIBackend(const std::string& backendName);
#ifndef BUILD_PLUGIN
#ifdef HAVE_WIN32UI
std::shared_ptr<UIBackend> createUIBackendWin32UI();
#endif
#ifdef HAVE_GTK
std::shared_ptr<UIBackend> createUIBackendGTK();
#endif

@ -67,7 +67,6 @@
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <assert.h>
#if defined _WIN32 || defined WINCE
#include <windows.h>
@ -127,6 +126,13 @@ void cvSetPropTopmost_COCOA(const char* name, const bool topmost);
double cvGetPropVsync_W32(const char* name);
void cvSetPropVsync_W32(const char* name, const bool enabled);
void setWindowTitle_W32(const cv::String& name, const cv::String& title);
void setWindowTitle_GTK(const cv::String& name, const cv::String& title);
void setWindowTitle_QT(const cv::String& name, const cv::String& title);
void setWindowTitle_COCOA(const cv::String& name, const cv::String& title);
int pollKey_W32();
//for QT
#if defined (HAVE_QT)
CvRect cvGetWindowRect_QT(const char* name);

@ -50,6 +50,14 @@ std::vector<BackendInfo>& getBuiltinBackendsInfo()
#elif defined(ENABLE_PLUGINS)
DECLARE_DYNAMIC_BACKEND("QT")
#endif
#endif
#ifdef _WIN32
#ifdef HAVE_WIN32UI
DECLARE_STATIC_BACKEND("WIN32", createUIBackendWin32UI)
#elif defined(ENABLE_PLUGINS)
DECLARE_DYNAMIC_BACKEND("WIN32")
#endif
#endif
};
return g_backends;

@ -586,6 +586,46 @@ void cv::moveWindow( const String& winname, int x, int y )
#endif
}
void cv::setWindowTitle(const String& winname, const String& title)
{
CV_TRACE_FUNCTION();
{
cv::AutoLock lock(cv::getWindowMutex());
auto window = findWindow_(winname);
if (window)
{
return window->setTitle(title);
}
}
#if defined(OPENCV_HIGHGUI_WITHOUT_BUILTIN_BACKEND) && defined(ENABLE_PLUGINS)
auto backend = getCurrentUIBackend();
if (backend)
{
CV_LOG_WARNING(NULL, "Can't find window with name: '" << winname << "'. Do nothing");
CV_NOT_FOUND_DEPRECATION;
}
else
{
CV_LOG_WARNING(NULL, "No UI backends available. Use OPENCV_LOG_LEVEL=DEBUG for investigation");
}
return;
#elif defined(HAVE_WIN32UI)
return setWindowTitle_W32(winname, title);
#elif defined (HAVE_GTK)
return setWindowTitle_GTK(winname, title);
#elif defined (HAVE_QT)
return setWindowTitle_QT(winname, title);
#elif defined (HAVE_COCOA)
return setWindowTitle_COCOA(winname, title);
#else
CV_Error(Error::StsNotImplemented, "The function is not implemented. "
"Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "
"If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script");
#endif
}
void cv::setWindowProperty(const String& winname, int prop_id, double prop_value)
{
CV_TRACE_FUNCTION();
@ -630,9 +670,9 @@ int cv::waitKey(int delay)
return (code != -1) ? (code & 0xff) : -1;
}
#if defined(HAVE_QT) || (defined (WINRT) && !defined (WINRT_8_0)) || \
!defined(HAVE_WIN32UI) && (defined(HAVE_GTK) || defined(HAVE_COCOA))
// pollKey() fallback implementation
/*
* process until queue is empty but don't wait.
*/
int cv::pollKey()
{
CV_TRACE_FUNCTION();
@ -646,12 +686,13 @@ int cv::pollKey()
}
}
#if defined(HAVE_WIN32UI)
return pollKey_W32();
#else
// fallback. please implement a proper polling function
return cvWaitKey(1);
}
#elif defined(HAVE_WIN32UI)
// pollKey() implemented in window_w32.cpp
#endif
}
int cv::createTrackbar(const String& trackbarName, const String& winName,
int* value, int count, TrackbarCallback callback,
@ -1203,13 +1244,6 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool )
// version with a more capable one without a need to recompile dependent
// applications or libraries.
void cv::setWindowTitle(const String&, const String&)
{
CV_Error(Error::StsNotImplemented, "The function is not implemented. "
"Rebuild the library with Windows, GTK+ 2.x or Cocoa support. "
"If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script");
}
#define CV_NO_GUI_ERROR(funcname) \
cv::error(cv::Error::StsError, \
"The function is not implemented. " \
@ -1360,11 +1394,6 @@ CV_IMPL int cvCreateButton(const char*, void (*)(int, void*), void*, int, int)
CV_NO_GUI_ERROR("cvCreateButton");
}
int cv::pollKey()
{
CV_NO_GUI_ERROR("cv::pollKey()");
}
#endif
/* End of file. */

@ -63,6 +63,7 @@
#endif
#endif
using namespace cv;
//Static and global first
static GuiReceiver *guiMainThread = NULL;
@ -197,7 +198,7 @@ void cvSetPropWindow_QT(const char* name,double prop_value)
Q_ARG(double, prop_value));
}
void cv::setWindowTitle(const String& winname, const String& title)
void setWindowTitle_QT(const String& winname, const String& title)
{
if (!guiMainThread)
CV_Error(Error::StsNullPtr, "NULL guiReceiver (please create a window)");

@ -795,18 +795,18 @@ void cvSetPropTopmost_COCOA( const char* name, const bool topmost )
__END__;
}
void cv::setWindowTitle(const String& winname, const String& title)
void setWindowTitle_COCOA(const cv::String& winname, const cv::String& title)
{
CVWindow *window = cvGetWindow(winname.c_str());
if (window == NULL)
{
namedWindow(winname);
cv::namedWindow(winname);
window = cvGetWindow(winname.c_str());
}
if (window == NULL)
CV_Error(Error::StsNullPtr, "NULL window");
CV_Error(cv::Error::StsNullPtr, "NULL window");
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];

@ -364,7 +364,7 @@ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_he
}
assert( image_widget->scaled_image );
CV_Assert(image_widget->scaled_image);
}
static void
@ -849,7 +849,7 @@ static bool setModeWindow_(const std::shared_ptr<CvWindow>& window, int mode)
return false;
}
void cv::setWindowTitle(const String& winname, const String& title)
void setWindowTitle_GTK(const String& winname, const String& title)
{
CV_LOCK_MUTEX();

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save