From: Marijn van Vliet Date: Fri, 29 Jan 2010 14:05:57 +0000 (+0000) Subject: Added correct resize handling X-Git-Url: https://git.stderr.nl/gitweb?p=rodin%2Fchimara.git;a=commitdiff_plain;h=9e4d74d44d12f977c573c31cab7bcb3819a27976 Added correct resize handling git-svn-id: http://lassie.dyndns-server.com/svn/gargoyle-gtk@217 ddfedd41-794f-dd11-ae45-00112f111e67 --- diff --git a/libchimara/graphics.c b/libchimara/graphics.c index 48b3a12..f94b90c 100644 --- a/libchimara/graphics.c +++ b/libchimara/graphics.c @@ -62,7 +62,7 @@ glk_image_get_info(glui32 image, glui32 *width, glui32 *height) /* Determine the image dimensions */ if(!size_determined) { - WARNING("Cannot read image size: file data trimmed?"); + WARNING("Cannot read image size"); g_free(info); return FALSE; } @@ -73,8 +73,6 @@ glk_image_get_info(glui32 image, glui32 *width, glui32 *height) *height =info->height; g_free(info); - //printf("size loaded: %d x %d\n", (int) *width, (int) *height); - return TRUE; } @@ -86,10 +84,40 @@ on_size_prepared(GdkPixbufLoader *loader, gint width, gint height, struct image_ size_determined = TRUE; } +/*** Called when the graphics window is resized. Resize the backing pixmap if necessary ***/ void -on_graphics_size_allocate(GtkWidget *widget, GtkAllocation *allocation, winid_t *win) +on_graphics_size_allocate(GtkWidget *widget, GtkAllocation *allocation, winid_t win) { - printf("size allocated: %dx%d\n", allocation->width, allocation->height); + printf("allocate to: %dx%d\n", allocation->width, allocation->height); + GdkPixmap *oldmap; + gtk_image_get_pixmap( GTK_IMAGE(widget), &oldmap, NULL ); + gint oldwidth = 0; + gint oldheight = 0; + + /* Determine whether a pixmap exists with the correct size */ + gboolean needs_resize = FALSE; + if(oldmap == NULL) + needs_resize = TRUE; + else { + gdk_drawable_get_size( GDK_DRAWABLE(oldmap), &oldwidth, &oldheight ); + if(oldwidth != allocation->width || oldheight != allocation->height) + needs_resize = TRUE; + } + + if(needs_resize) { + printf("needs resize\n"); + /* Create a new pixmap */ + GdkPixmap *newmap = gdk_pixmap_new(widget->window, allocation->width, allocation->height, -1); + gdk_draw_rectangle( GDK_DRAWABLE(newmap), widget->style->white_gc, TRUE, 0, 0, allocation->width, allocation->height); + + /* Copy the contents of the old pixmap */ + if(oldmap != NULL) + gdk_draw_drawable( GDK_DRAWABLE(newmap), widget->style->white_gc, GDK_DRAWABLE(oldmap), 0, 0, 0, 0, oldwidth, oldheight); + + /* Use the new pixmap */ + gtk_image_set_from_pixmap( GTK_IMAGE(widget), newmap, NULL ); + g_object_unref(newmap); + } } glui32 @@ -107,8 +135,6 @@ glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) { guchar *buffer; GdkPixmap *canvas; - //printf("glk_image_get_info(%d)\n", image); - /* Lookup the proper resource */ blorb_error = giblorb_load_resource(glk_data->resource_map, giblorb_method_FilePos, &res, giblorb_ID_Pict, image); if(blorb_error != giblorb_err_None) { @@ -135,6 +161,7 @@ glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) { total_read += num_read; } + printf("Loading done\n"); giblorb_unload_chunk(glk_data->resource_map, image); g_free(buffer); @@ -152,11 +179,13 @@ glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) { return FALSE; } + // TODO: FIX hang? gdk_draw_pixbuf( GDK_DRAWABLE(canvas), NULL, pixbuf, 0, 0, val1, val2, -1, -1, GDK_RGB_DITHER_NONE, 0, 0 ); gdk_pixbuf_loader_close(loader, &pixbuf_error); /* Update the screen */ gtk_widget_queue_draw(win->widget); + return TRUE; } diff --git a/libchimara/graphics.h b/libchimara/graphics.h index cf81d59..34cde77 100644 --- a/libchimara/graphics.h +++ b/libchimara/graphics.h @@ -14,6 +14,6 @@ struct image_info { gint width, height; }; -void on_graphics_size_allocate(GtkWidget *widget, GtkAllocation *allocation, winid_t *win); +void on_graphics_size_allocate(GtkWidget *widget, GtkAllocation *allocation, winid_t win); #endif diff --git a/libchimara/window.c b/libchimara/window.c index 209cda6..02f1e5c 100644 --- a/libchimara/window.c +++ b/libchimara/window.c @@ -561,16 +561,13 @@ glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, case wintype_Graphics: { - // TODO: Find real size - GdkPixmap *newmap = gdk_pixmap_new(NULL, 800, 600, 24); - GtkWidget *image = gtk_image_new_from_pixmap(newmap, NULL); - g_object_unref(newmap); - + GtkWidget *image = gtk_image_new_from_pixmap(NULL, NULL); gtk_widget_show(image); + win->unit_width = 1; + win->unit_height = 1; win->widget = image; win->frame = image; - /* Connect signal handlers */ win->button_press_event_handler = g_signal_connect(image, "button-press-event", G_CALLBACK(on_window_button_press), win);