static void cvImageWidget_realize (GtkWidget *widget) { CvImageWidget *image_widget; GdkWindowAttr attributes; gint attributes_mask; //printf("cvImageWidget_realize\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); image_widget = CV_IMAGE_WIDGET (widget); attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual (widget); attributes.colormap = gtk_widget_get_colormap (widget); 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->style = gtk_style_attach (widget->style, widget->window); gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); }
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) { #ifdef HAVE_OPENGL CvWindow* window = (CvWindow*)data; if (window->useGl) { drawGl(window); return TRUE; } #else (void)data; #endif CvImageWidget *image_widget = NULL; cairo_t *cr = NULL; GdkPixbuf *pixbuf = NULL; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (event->count > 0) return FALSE; cr = gdk_cairo_create(widget->window); image_widget = CV_IMAGE_WIDGET (widget); if( image_widget->scaled_image ){ // center image in available region int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int y0 = (widget->allocation.height - 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, widget->allocation.width), MIN(image_widget->scaled_image->rows, widget->allocation.height), 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, widget->allocation.width), MIN(image_widget->original_image->rows, widget->allocation.height), image_widget->original_image->step, NULL, NULL); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); } cairo_paint(cr); g_object_unref(pixbuf); cairo_destroy(cr); return TRUE; }
static void cvImageWidget_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { CvImageWidget *image_widget; //printf("cvImageWidget_size_allocate\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; image_widget = CV_IMAGE_WIDGET (widget); if( (image_widget->flags & CV_WINDOW_AUTOSIZE)==0 && image_widget->original_image ){ // (re) allocated scaled image if( image_widget->flags & CV_WINDOW_NO_IMAGE ){ cvImageWidget_set_size( widget, image_widget->original_image->cols, image_widget->original_image->rows); } else{ cvImageWidget_set_size( widget, allocation->width, allocation->height ); } cvResize( image_widget->original_image, image_widget->scaled_image, CV_INTER_AREA ); } if (GTK_WIDGET_REALIZED (widget)) { image_widget = CV_IMAGE_WIDGET (widget); if( image_widget->original_image && ((image_widget->flags & CV_WINDOW_AUTOSIZE) || (image_widget->flags & CV_WINDOW_NO_IMAGE)) ) { widget->allocation.width = image_widget->original_image->cols; widget->allocation.height = image_widget->original_image->rows; gdk_window_move_resize( widget->window, allocation->x, allocation->y, image_widget->original_image->cols, image_widget->original_image->rows ); if(image_widget->flags & CV_WINDOW_NO_IMAGE){ image_widget->flags &= ~CV_WINDOW_NO_IMAGE; gtk_widget_queue_resize( GTK_WIDGET(widget) ); } } else{ gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height ); } } }
static gboolean cvImageWidget_expose(GtkWidget* widget, GdkEventExpose* event, gpointer data) { #ifdef HAVE_OPENGL CvWindow* window = (CvWindow*)data; if (window->useGl) { drawGl(window); return TRUE; } #else (void)data; #endif CvImageWidget *image_widget; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (CV_IS_IMAGE_WIDGET (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (event->count > 0) return FALSE; image_widget = CV_IMAGE_WIDGET (widget); gdk_window_clear_area (widget->window, 0, 0, widget->allocation.width, widget->allocation.height); if( image_widget->scaled_image ){ // center image in available region int x0 = (widget->allocation.width - image_widget->scaled_image->cols)/2; int y0 = (widget->allocation.height - image_widget->scaled_image->rows)/2; gdk_draw_rgb_image( widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], x0, y0, MIN(image_widget->scaled_image->cols, widget->allocation.width), MIN(image_widget->scaled_image->rows, widget->allocation.height), GDK_RGB_DITHER_MAX, image_widget->scaled_image->data.ptr, image_widget->scaled_image->step ); } else if( image_widget->original_image ){ gdk_draw_rgb_image( widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, 0, MIN(image_widget->original_image->cols, widget->allocation.width), MIN(image_widget->original_image->rows, widget->allocation.height), GDK_RGB_DITHER_MAX, image_widget->original_image->data.ptr, image_widget->original_image->step ); } return TRUE; }
static void cvImageWidget_destroy (GtkObject *object) { CvImageWidget *image_widget; g_return_if_fail (object != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (object)); image_widget = CV_IMAGE_WIDGET (object); cvReleaseMat( &image_widget->scaled_image ); cvReleaseMat( &image_widget->original_image ); if (GTK_OBJECT_CLASS (parent_class)->destroy) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); }
static void cvImageWidget_destroy (GtkObject *object) #endif //GTK_VERSION3 { CvImageWidget *image_widget; g_return_if_fail (object != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (object)); image_widget = CV_IMAGE_WIDGET (object); cvReleaseMat( &image_widget->scaled_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) (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); #endif //GTK_VERSION3 }
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; } }
static void cvImageWidget_realize (GtkWidget *widget) { GdkWindowAttr attributes; gint attributes_mask; #if defined(GTK_VERSION3) GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); #endif //GTK_VERSION3 //printf("cvImageWidget_realize\n"); g_return_if_fail (widget != NULL); g_return_if_fail (CV_IS_IMAGE_WIDGET (widget)); 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.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; #endif //GTK_VERSION3 attributes.wclass = GDK_INPUT_OUTPUT; attributes.window_type = GDK_WINDOW_CHILD; attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; attributes.visual = gtk_widget_get_visual (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; widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); widget->style = gtk_style_attach (widget->style, widget->window); gdk_window_set_user_data (widget->window, widget); gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE); #endif // GTK_VERSION3 }