Commit 16383412 authored by Tony's avatar Tony

Use GTK_VERSION_MAJOR to switch between GTK+ version two and three

specific code. As a result of this, HAVE_GTK3 no longer needs to be
exposed.

The use of HAVE_GTK, and HAVE_ GTK3 have been changed to mirror the
method used by HAVE_QT and HAVE_QT5.
 On branch gtk3
 Changes to be committed:
        modified:   CMakeLists.txt
        modified:   cmake/OpenCVFindLibsGUI.cmake
        modified:   cmake/templates/cvconfig.h.in
        modified:   modules/highgui/src/window.cpp
        modified:   modules/highgui/src/window_gtk.cpp
parent befdef96
...@@ -127,6 +127,7 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON ...@@ -127,6 +127,7 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON
OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF )
OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (NOT IOS) ) OCV_OPTION(WITH_IPP "Include Intel IPP support" ON IF (NOT IOS) )
OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) )
OCV_OPTION(WITH_JPEG "Include JPEG support" ON) OCV_OPTION(WITH_JPEG "Include JPEG support" ON)
...@@ -157,7 +158,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON ...@@ -157,7 +158,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) ) OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS) )
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 ) OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF WIN32 )
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 ) OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF WIN32 )
OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
# OpenCV build components # OpenCV build components
# =================================================== # ===================================================
...@@ -748,6 +749,7 @@ else() ...@@ -748,6 +749,7 @@ else()
endif() endif()
else() else()
status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO)
status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO)
status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO)
status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO)
endif() endif()
...@@ -916,17 +918,13 @@ endif(DEFINED WITH_INTELPERC) ...@@ -916,17 +918,13 @@ endif(DEFINED WITH_INTELPERC)
status("") status("")
status(" Other third-party libraries:") status(" Other third-party libraries:")
if(WITH_IPP AND HAVE_IPP) if(WITH_IPP AND IPP_FOUND)
status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]") status(" Use IPP:" "${IPP_LATEST_VERSION_STR} [${IPP_LATEST_VERSION_MAJOR}.${IPP_LATEST_VERSION_MINOR}.${IPP_LATEST_VERSION_BUILD}]")
status(" at:" "${IPP_ROOT_DIR}") status(" at:" "${IPP_ROOT_DIR}")
else() else()
status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) status(" Use IPP:" WITH_IPP AND NOT IPP_FOUND THEN "IPP not found" ELSE NO)
endif() endif()
if(DEFINED WITH_IPP_A)
status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO)
endif(DEFINED WITH_IPP_A)
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO) status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO) status(" Use TBB:" HAVE_TBB THEN "YES (ver ${TBB_VERSION_MAJOR}.${TBB_VERSION_MINOR} interface ${TBB_INTERFACE_VERSION})" ELSE NO)
status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO) status(" Use OpenMP:" HAVE_OPENMP THEN YES ELSE NO)
......
...@@ -44,17 +44,19 @@ if(WITH_GTK AND NOT HAVE_QT) ...@@ -44,17 +44,19 @@ if(WITH_GTK AND NOT HAVE_QT)
if(WITH_GTK_2_X) if(WITH_GTK_2_X)
CHECK_MODULE(gtk+-2.0 HAVE_GTK) CHECK_MODULE(gtk+-2.0 HAVE_GTK)
if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK)) if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK))
message (FATAL_ERROR "Gtk support requires a minimum gtk+ version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)") message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)")
endif() endif()
else() else()
CHECK_MODULE(gtk+-3.0 HAVE_GTK3) CHECK_MODULE(gtk+-3.0 HAVE_GTK3)
if(NOT HAVE_GTK3) if(HAVE_GTK3)
message(WARNING "Unable to locate Gtk3 development libraries") set(HAVE_GTK ON)
else()
message(WARNING "Unable to locate GTK3 development libraries")
endif() endif()
endif() endif()
CHECK_MODULE(gthread-2.0 HAVE_GTHREAD) CHECK_MODULE(gthread-2.0 HAVE_GTHREAD)
if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD) if(HAVE_GTK OR HAVE_GTK3 AND NOT HAVE_GTHREAD)
message(FATAL_ERROR "gthread not found. This library is required when building with Gtk support") message(FATAL_ERROR "gthread not found. This library is required when building with GTK support")
endif() endif()
if(WITH_OPENGL AND NOT HAVE_GTK3) if(WITH_OPENGL AND NOT HAVE_GTK3)
CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT) CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT)
......
...@@ -85,9 +85,6 @@ ...@@ -85,9 +85,6 @@
/* GTK+ 2.x toolkit */ /* GTK+ 2.x toolkit */
#cmakedefine HAVE_GTK #cmakedefine HAVE_GTK
/* GTK+ 3.x toolkit */
#cmakedefine HAVE_GTK3
/* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H 1 #cmakedefine HAVE_INTTYPES_H 1
......
...@@ -59,7 +59,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu ...@@ -59,7 +59,7 @@ CV_IMPL void cvSetWindowProperty(const char* name, int prop_id, double prop_valu
cvSetModeWindow_QT(name,prop_value); cvSetModeWindow_QT(name,prop_value);
#elif defined(HAVE_WIN32UI) #elif defined(HAVE_WIN32UI)
cvSetModeWindow_W32(name,prop_value); cvSetModeWindow_W32(name,prop_value);
#elif defined (HAVE_GTK) | defined (HAVE_GTK3) #elif defined (HAVE_GTK)
cvSetModeWindow_GTK(name,prop_value); cvSetModeWindow_GTK(name,prop_value);
#elif defined (HAVE_CARBON) #elif defined (HAVE_CARBON)
cvSetModeWindow_CARBON(name,prop_value); cvSetModeWindow_CARBON(name,prop_value);
...@@ -98,7 +98,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) ...@@ -98,7 +98,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetModeWindow_QT(name); return cvGetModeWindow_QT(name);
#elif defined(HAVE_WIN32UI) #elif defined(HAVE_WIN32UI)
return cvGetModeWindow_W32(name); return cvGetModeWindow_W32(name);
#elif defined (HAVE_GTK) | defined(HAVE_GTK3) #elif defined (HAVE_GTK)
return cvGetModeWindow_GTK(name); return cvGetModeWindow_GTK(name);
#elif defined (HAVE_CARBON) #elif defined (HAVE_CARBON)
return cvGetModeWindow_CARBON(name); return cvGetModeWindow_CARBON(name);
...@@ -115,7 +115,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) ...@@ -115,7 +115,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetPropWindow_QT(name); return cvGetPropWindow_QT(name);
#elif defined(HAVE_WIN32UI) #elif defined(HAVE_WIN32UI)
return cvGetPropWindowAutoSize_W32(name); return cvGetPropWindowAutoSize_W32(name);
#elif defined (HAVE_GTK) | defined(HAVE_GTK3) #elif defined (HAVE_GTK)
return cvGetPropWindowAutoSize_GTK(name); return cvGetPropWindowAutoSize_GTK(name);
#else #else
return -1; return -1;
...@@ -128,7 +128,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) ...@@ -128,7 +128,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetRatioWindow_QT(name); return cvGetRatioWindow_QT(name);
#elif defined(HAVE_WIN32UI) #elif defined(HAVE_WIN32UI)
return cvGetRatioWindow_W32(name); return cvGetRatioWindow_W32(name);
#elif defined (HAVE_GTK) | defined(HAVE_GTK3) #elif defined (HAVE_GTK)
return cvGetRatioWindow_GTK(name); return cvGetRatioWindow_GTK(name);
#else #else
return -1; return -1;
...@@ -141,7 +141,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id) ...@@ -141,7 +141,7 @@ CV_IMPL double cvGetWindowProperty(const char* name, int prop_id)
return cvGetOpenGlProp_QT(name); return cvGetOpenGlProp_QT(name);
#elif defined(HAVE_WIN32UI) #elif defined(HAVE_WIN32UI)
return cvGetOpenGlProp_W32(name); return cvGetOpenGlProp_W32(name);
#elif defined (HAVE_GTK) | defined(HAVE_GTK3) #elif defined (HAVE_GTK)
return cvGetOpenGlProp_GTK(name); return cvGetOpenGlProp_GTK(name);
#else #else
return -1; return -1;
...@@ -477,7 +477,6 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool ) ...@@ -477,7 +477,6 @@ int cv::createButton(const String&, ButtonCallback, void*, int , bool )
#if defined(HAVE_WIN32UI) // see window_w32.cpp #if defined(HAVE_WIN32UI) // see window_w32.cpp
#elif defined (HAVE_GTK) // see window_gtk.cpp #elif defined (HAVE_GTK) // see window_gtk.cpp
#elif defined (HAVE_GTK3) // see window_gtk.cpp
#elif defined (HAVE_COCOA) // see window_carbon.cpp #elif defined (HAVE_COCOA) // see window_carbon.cpp
#elif defined (HAVE_CARBON) #elif defined (HAVE_CARBON)
#elif defined (HAVE_QT) //YV see window_QT.cpp #elif defined (HAVE_QT) //YV see window_QT.cpp
......
...@@ -43,13 +43,17 @@ ...@@ -43,13 +43,17 @@
#ifndef WIN32 #ifndef WIN32
#ifdef HAVE_GTK #if defined (HAVE_GTK)
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h" #include "gdk/gdkkeysyms.h"
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdio.h> #include <stdio.h>
#if (GTK_MAJOR_VERSION == 3)
#define GTK_VERSION3
#endif //GTK_MAJOR_VERSION >= 3
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
#include <gtk/gtkgl.h> #include <gtk/gtkgl.h>
#include <GL/gl.h> #include <GL/gl.h>
...@@ -150,32 +154,77 @@ cvImageWidget_realize (GtkWidget *widget) ...@@ -150,32 +154,77 @@ cvImageWidget_realize (GtkWidget *widget)
GdkWindowAttr attributes; GdkWindowAttr attributes;
gint attributes_mask; gint attributes_mask;
#if defined(GTK_VERSION3)
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
#endif //GTK_VERSION3
//printf("cvImageWidget_realize\n"); //printf("cvImageWidget_realize\n");
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget));
gtk_widget_set_realized(widget, TRUE); gtk_widget_set_realized(widget, TRUE);
#if defined(GTK_VERSION3)
attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.width = allocation.width;
attributes.height = allocation.height;
#else
attributes.x = widget->allocation.x; attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y; attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width; attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height; attributes.height = widget->allocation.height;
#endif //GTK_VERSION3
attributes.wclass = GDK_INPUT_OUTPUT; attributes.wclass = GDK_INPUT_OUTPUT;
attributes.window_type = GDK_WINDOW_CHILD; attributes.window_type = GDK_WINDOW_CHILD;
attributes.event_mask = gtk_widget_get_events (widget) | attributes.event_mask = gtk_widget_get_events (widget) |
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK;
attributes.visual = gtk_widget_get_visual (widget); attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
#if defined(GTK_VERSION3)
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
gtk_widget_set_window(
widget,
gdk_window_new(
gtk_widget_get_parent_window(widget),
&attributes,
attributes_mask
)
);
gtk_widget_set_style(
widget,
gtk_style_attach(
gtk_widget_get_style(widget),
gtk_widget_get_window(widget)
)
);
gdk_window_set_user_data (
gtk_widget_get_window(widget),
widget
);
gtk_style_set_background (
gtk_widget_get_style(widget),
gtk_widget_get_window(widget),
GTK_STATE_ACTIVE
);
#else
// The following lines are included to prevent breaking
// compatibility with older Gtk2 (<gtk+-2.18) libraries.
attributes.colormap = gtk_widget_get_colormap (widget);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
widget->style = gtk_style_attach (widget->style, widget->window); widget->style = gtk_style_attach (widget->style, widget->window);
gdk_window_set_user_data (widget->window, widget); gdk_window_set_user_data (widget->window, widget);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
#endif // GTK_VERSION3
} }
static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_width, int max_height ){ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_width, int max_height ){
...@@ -187,6 +236,56 @@ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_widt ...@@ -187,6 +236,56 @@ static CvSize cvImageWidget_calc_size( int im_width, int im_height, int max_widt
return cvSize( cvRound(max_height*aspect), max_height ); return cvSize( cvRound(max_height*aspect), max_height );
} }
#if defined (GTK_VERSION3)
static void
cvImageWidget_get_preferred_width (GtkWidget *widget, gint *minimal_width, gint *natural_width)
{
g_return_if_fail (widget != NULL);
g_return_if_fail (CV_IS_IMAGE_WIDGET (widget));
CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget );
if(image_widget->original_image != NULL) {
*minimal_width = image_widget->flags & CV_WINDOW_AUTOSIZE ?
gdk_window_get_width(gtk_widget_get_window(widget)) : image_widget->original_image->cols;
}
else {
*minimal_width = 320;
}
if(image_widget->scaled_image != NULL) {
*natural_width = *minimal_width < image_widget->scaled_image->cols ?
image_widget->scaled_image->cols : *minimal_width;
}
else {
*natural_width = *minimal_width;
}
}
static void
cvImageWidget_get_preferred_height (GtkWidget *widget, gint *minimal_height, gint *natural_height)
{
g_return_if_fail (widget != NULL);
g_return_if_fail (CV_IS_IMAGE_WIDGET (widget));
CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget );
if(image_widget->original_image != NULL) {
*minimal_height = image_widget->flags & CV_WINDOW_AUTOSIZE ?
gdk_window_get_height(gtk_widget_get_window(widget)) : image_widget->original_image->rows;
}
else {
*minimal_height = 240;
}
if(image_widget->scaled_image != NULL) {
*natural_height = *minimal_height < image_widget->scaled_image->rows ?
image_widget->scaled_image->cols : *minimal_height;
}
else {
*natural_height = *minimal_height;
}
}
#else
static void static void
cvImageWidget_size_request (GtkWidget *widget, cvImageWidget_size_request (GtkWidget *widget,
GtkRequisition *requisition) GtkRequisition *requisition)
...@@ -217,6 +316,7 @@ cvImageWidget_size_request (GtkWidget *widget, ...@@ -217,6 +316,7 @@ cvImageWidget_size_request (GtkWidget *widget,
} }
//printf("%d %d\n",requisition->width, requisition->height); //printf("%d %d\n",requisition->width, requisition->height);
} }
#endif //GTK_VERSION3
static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){ static void cvImageWidget_set_size(GtkWidget * widget, int max_width, int max_height){
CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget ); CvImageWidget * image_widget = CV_IMAGE_WIDGET( widget );
...@@ -255,7 +355,11 @@ cvImageWidget_size_allocate (GtkWidget *widget, ...@@ -255,7 +355,11 @@ cvImageWidget_size_allocate (GtkWidget *widget,
g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget));
g_return_if_fail (allocation != NULL); g_return_if_fail (allocation != NULL);
#if defined (GTK_VERSION3)
gtk_widget_set_allocation(widget, allocation);
#else
widget->allocation = *allocation; widget->allocation = *allocation;
#endif //GTK_VERSION3
image_widget = CV_IMAGE_WIDGET (widget); image_widget = CV_IMAGE_WIDGET (widget);
...@@ -279,9 +383,16 @@ cvImageWidget_size_allocate (GtkWidget *widget, ...@@ -279,9 +383,16 @@ cvImageWidget_size_allocate (GtkWidget *widget,
((image_widget->flags & CV_WINDOW_AUTOSIZE) || ((image_widget->flags & CV_WINDOW_AUTOSIZE) ||
(image_widget->flags & CV_WINDOW_NO_IMAGE)) ) (image_widget->flags & CV_WINDOW_NO_IMAGE)) )
{ {
#if defined (GTK_VERSION3)
allocation->width = image_widget->original_image->cols;
allocation->height = image_widget->original_image->rows;
gtk_widget_set_allocation(widget, allocation);
#else
widget->allocation.width = image_widget->original_image->cols; widget->allocation.width = image_widget->original_image->cols;
widget->allocation.height = image_widget->original_image->rows; widget->allocation.height = image_widget->original_image->rows;
gdk_window_move_resize( widget->window, allocation->x, allocation->y, #endif //GTK_VERSION3
gdk_window_move_resize( gtk_widget_get_window(widget),
allocation->x, allocation->y,
image_widget->original_image->cols, image_widget->original_image->rows ); image_widget->original_image->cols, image_widget->original_image->rows );
if(image_widget->flags & CV_WINDOW_NO_IMAGE){ if(image_widget->flags & CV_WINDOW_NO_IMAGE){
image_widget->flags &= ~CV_WINDOW_NO_IMAGE; image_widget->flags &= ~CV_WINDOW_NO_IMAGE;
...@@ -289,16 +400,20 @@ cvImageWidget_size_allocate (GtkWidget *widget, ...@@ -289,16 +400,20 @@ cvImageWidget_size_allocate (GtkWidget *widget,
} }
} }
else{ else{
gdk_window_move_resize (widget->window, gdk_window_move_resize (gtk_widget_get_window(widget),
allocation->x, allocation->y, allocation->x, allocation->y,
allocation->width, allocation->height ); allocation->width, allocation->height );
} }
} }
} }
#if defined (GTK_VERSION3)
static void
cvImageWidget_destroy (GtkWidget *object)
#else
static void static void
cvImageWidget_destroy (GtkObject *object) cvImageWidget_destroy (GtkObject *object)
#endif //GTK_VERSION3
{ {
CvImageWidget *image_widget; CvImageWidget *image_widget;
...@@ -310,24 +425,39 @@ cvImageWidget_destroy (GtkObject *object) ...@@ -310,24 +425,39 @@ cvImageWidget_destroy (GtkObject *object)
cvReleaseMat( &image_widget->scaled_image ); cvReleaseMat( &image_widget->scaled_image );
cvReleaseMat( &image_widget->original_image ); cvReleaseMat( &image_widget->original_image );
#if defined (GTK_VERSION3)
if (GTK_WIDGET_CLASS (parent_class)->destroy)
(* GTK_WIDGET_CLASS (parent_class)->destroy) (object);
#else
if (GTK_OBJECT_CLASS (parent_class)->destroy) if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object); (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
#endif //GTK_VERSION3
} }
static void cvImageWidget_class_init (CvImageWidgetClass * klass) static void cvImageWidget_class_init (CvImageWidgetClass * klass)
{ {
#if defined (GTK_VERSION3)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
#else
GtkObjectClass *object_class; GtkObjectClass *object_class;
GtkWidgetClass *widget_class; GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) klass; object_class = (GtkObjectClass*) klass;
widget_class = (GtkWidgetClass*) klass; widget_class = (GtkWidgetClass*) klass;
#endif //GTK_VERSION3
parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) ); parent_class = GTK_WIDGET_CLASS( g_type_class_peek (gtk_widget_get_type ()) );
#if defined (GTK_VERSION3)
widget_class->destroy = cvImageWidget_destroy;
widget_class->get_preferred_width = cvImageWidget_get_preferred_width;
widget_class->get_preferred_height = cvImageWidget_get_preferred_height;
#else
object_class->destroy = cvImageWidget_destroy; object_class->destroy = cvImageWidget_destroy;
widget_class->size_request = cvImageWidget_size_request;
#endif //GTK_VERSION3
widget_class->realize = cvImageWidget_realize; widget_class->realize = cvImageWidget_realize;
widget_class->size_request = cvImageWidget_size_request;
widget_class->size_allocate = cvImageWidget_size_allocate; widget_class->size_allocate = cvImageWidget_size_allocate;
widget_class->button_press_event = NULL; widget_class->button_press_event = NULL;
widget_class->button_release_event = NULL; widget_class->button_release_event = NULL;
...@@ -347,13 +477,15 @@ GType cvImageWidget_get_type (void){ ...@@ -347,13 +477,15 @@ GType cvImageWidget_get_type (void){
if (!image_type) if (!image_type)
{ {
image_type = g_type_register_static_simple( GTK_TYPE_WIDGET, image_type = g_type_register_static_simple(
GTK_TYPE_WIDGET,
(gchar*) "CvImageWidget", (gchar*) "CvImageWidget",
sizeof(CvImageWidgetClass), sizeof(CvImageWidgetClass),
(GClassInitFunc) cvImageWidget_class_init, (GClassInitFunc) cvImageWidget_class_init,
sizeof(CvImageWidget), sizeof(CvImageWidget),
(GInstanceInitFunc) cvImageWidget_init, (GInstanceInitFunc) cvImageWidget_init,
(GTypeFlags)NULL); (GTypeFlags)NULL
);
} }
return image_type; return image_type;
...@@ -642,8 +774,12 @@ double cvGetRatioWindow_GTK(const char* name) ...@@ -642,8 +774,12 @@ double cvGetRatioWindow_GTK(const char* name)
if (!window) if (!window)
EXIT; // keep silence here EXIT; // keep silence here
#if defined (GTK_VERSION3)
result = static_cast<double>(
gtk_widget_get_allocated_width(window->widget)) / gtk_widget_get_allocated_height(window->widget);
#else
result = static_cast<double>(window->widget->allocation.width) / window->widget->allocation.height; result = static_cast<double>(window->widget->allocation.width) / window->widget->allocation.height;
#endif // GTK_VERSION3
__END__; __END__;
return result; return result;
...@@ -738,7 +874,55 @@ namespace ...@@ -738,7 +874,55 @@ namespace
#endif // HAVE_OPENGL #endif // HAVE_OPENGL
#if defined (GTK_VERSION3)
static gboolean cvImageWidget_draw(GtkWidget* widget, cairo_t *cr, gpointer data)
{
#ifdef HAVE_OPENGL
CvWindow* window = (CvWindow*)data;
if (window->useGl)
{
drawGl(window);
return TRUE;
}
#else
(void)data;
#endif
CvImageWidget *image_widget = NULL;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE);
image_widget = CV_IMAGE_WIDGET (widget);
if( image_widget->scaled_image ){
// center image in available region
int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2;
int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2;
pixbuf = gdk_pixbuf_new_from_data(image_widget->scaled_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->scaled_image->cols, gtk_widget_get_allocated_width(widget)),
MIN(image_widget->scaled_image->rows, gtk_widget_get_allocated_height(widget)),
image_widget->scaled_image->step, NULL, NULL);
gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
}
else if( image_widget->original_image ){
pixbuf = gdk_pixbuf_new_from_data(image_widget->original_image->data.ptr, GDK_COLORSPACE_RGB, false,
8, MIN(image_widget->original_image->cols, gtk_widget_get_allocated_width(widget)),
MIN(image_widget->original_image->rows, gtk_widget_get_allocated_height(widget)),
image_widget->original_image->step, NULL, NULL);
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
}
cairo_paint(cr);
g_object_unref(pixbuf);
return TRUE;
}
#else
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data)
{ {
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
...@@ -776,6 +960,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g ...@@ -776,6 +960,7 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g
8, MIN(image_widget->scaled_image->cols, widget->allocation.width), 8, MIN(image_widget->scaled_image->cols, widget->allocation.width),
MIN(image_widget->scaled_image->rows, widget->allocation.height), MIN(image_widget->scaled_image->rows, widget->allocation.height),
image_widget->scaled_image->step, NULL, NULL); image_widget->scaled_image->step, NULL, NULL);
gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0); gdk_cairo_set_source_pixbuf(cr, pixbuf, x0, y0);
} }
else if( image_widget->original_image ){ else if( image_widget->original_image ){
...@@ -787,9 +972,11 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g ...@@ -787,9 +972,11 @@ static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, g
} }
cairo_paint(cr); cairo_paint(cr);
g_object_unref(pixbuf);
cairo_destroy(cr); cairo_destroy(cr);
return TRUE; return TRUE;
} }
#endif //GTK_VERSION3
CV_IMPL int cvNamedWindow( const char* name, int flags ) CV_IMPL int cvNamedWindow( const char* name, int flags )
{ {
...@@ -862,8 +1049,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags ) ...@@ -862,8 +1049,13 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
G_CALLBACK(icvOnMouse), window ); G_CALLBACK(icvOnMouse), window );
g_signal_connect( window->frame, "delete-event", g_signal_connect( window->frame, "delete-event",
G_CALLBACK(icvOnClose), window ); G_CALLBACK(icvOnClose), window );
#if defined(GTK_VERSION3)
g_signal_connect( window->widget, "draw",
G_CALLBACK(cvImageWidget_draw), window );
#else
g_signal_connect( window->widget, "expose-event", g_signal_connect( window->widget, "expose-event",
G_CALLBACK(cvImageWidget_expose), window ); G_CALLBACK(cvImageWidget_expose), window );
#endif //GTK_VERSION3
gtk_widget_add_events (window->widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ; gtk_widget_add_events (window->widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK) ;
...@@ -1420,6 +1612,13 @@ CV_IMPL const char* cvGetWindowName( void* window_handle ) ...@@ -1420,6 +1612,13 @@ CV_IMPL const char* cvGetWindowName( void* window_handle )
return window_name; return window_name;
} }
#if defined (GTK_VERSION3)
#define GDK_Escape GDK_KEY_Escape
#define GDK_Return GDK_KEY_Return
#define GDK_Linefeed GDK_KEY_Linefeed
#define GDK_Tab GDK_KEY_Tab
#endif //GTK_VERSION3
static gboolean icvOnKeyPress( GtkWidget * /*widget*/, static gboolean icvOnKeyPress( GtkWidget * /*widget*/,
GdkEventKey* event, gpointer /*user_data*/ ) GdkEventKey* event, gpointer /*user_data*/ )
{ {
...@@ -1550,8 +1749,13 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da ...@@ -1550,8 +1749,13 @@ static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_da
image_widget->original_image && image_widget->original_image &&
image_widget->scaled_image ){ image_widget->scaled_image ){
// image origin is not necessarily at (0,0) // image origin is not necessarily at (0,0)
#if defined (GTK_VERSION3)
int x0 = (gtk_widget_get_allocated_width(widget) - image_widget->scaled_image->cols)/2;
int y0 = (gtk_widget_get_allocated_height(widget) - image_widget->scaled_image->rows)/2;
#else
int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2;
int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2; int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2;
#endif //GTK_VERSION3
pt.x = cvFloor( ((pt32f.x-x0)*image_widget->original_image->cols)/ pt.x = cvFloor( ((pt32f.x-x0)*image_widget->original_image->cols)/
image_widget->scaled_image->cols ); image_widget->scaled_image->cols );
pt.y = cvFloor( ((pt32f.y-y0)*image_widget->original_image->rows)/ pt.y = cvFloor( ((pt32f.y-y0)*image_widget->original_image->rows)/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment