Date: Fri, 05 Jan 2001 00:23:18 -0800 From: Chris Hecker Subject: Re: resize event? To: lablgtk at kaba.or.jp Message-id: <4.3.2.7.2.20010105002151.00baf5c0 at shell16.ba.best.com> MIME-version: 1.0 Content-type: text/plain; charset="us-ascii" [Resent to the list to keep people updated...Jacques and I had a private thread going.] >It is possible that events work differently on windows and X11. >Try using other events, like configure, in place of expose, this may >work better. I tried configure, but that didn't work either. Which one is supposed to be called on resize? Now that I've looked at it closer, it looks like the image does get repainted on resize, it's just that the window gets cleared immediately afterwards. I decided to dig up a gtk sample app that's similar. I've attached it below (I also put image.ml in there). It works correctly, and the image is rock solid. So, it doesn't look like a GTK bug. Any ideas? Chris #include #define IMAGE_WIDTH 256 #define IMAGE_HEIGHT 256 guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3]; gboolean on_darea_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data); int main (int argc, char *argv[]) { GtkWidget *window, *darea; gint x, y; guchar *pos; gtk_init (&argc, &argv); gdk_rgb_init(); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); darea = gtk_drawing_area_new(); gtk_drawing_area_size (GTK_DRAWING_AREA (darea), IMAGE_WIDTH, IMAGE_HEIGHT); gtk_container_add (GTK_CONTAINER (window), darea); gtk_signal_connect (GTK_OBJECT (darea), "expose-event", GTK_SIGNAL_FUNC (on_darea_expose), NULL); gtk_widget_show_all (window); /* Set up the RGB buffer. */ pos = rgbbuf; for (y = 0; y < IMAGE_HEIGHT; y++) { for (x = 0; x < IMAGE_WIDTH; x++) { *pos++ = x - x % 32; /* Red. */ *pos++ = (x / 32) * 4 + y - y % 32; /* Green. */ *pos++ = y - y % 32; /* Blue. */ } } gtk_main(); return 0; } gboolean on_darea_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { gdk_draw_rgb_image (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3); } (* $Id: image.ml,v 1.6 2000/06/06 03:51:04 garrigue Exp $ *) open GMain open Gdk (* load image *) let buf = String.create (256*256*3) let ic = open_in_bin "image256x256.rgb" let _ = really_input ic ~buf:buf ~pos:0 ~len:(256*256*3); close_in ic let rgb_at x y = let offset = (y * 256 + x) * 3 in (int_of_char buf.[offset ], int_of_char buf.[offset+1], int_of_char buf.[offset+2]) (* let id = Thread.create GtkThread.main () *) (* Choose a visual appropriate for RGB *) let _ = Gdk.Rgb.init (); GtkBase.Widget.set_default_visual (Gdk.Rgb.get_visual ()); GtkBase.Widget.set_default_colormap (Gdk.Rgb.get_cmap ()) (* We need show: true because of the need of visual *) let window = GWindow.window ~show:true ~width: 256 ~height: 256 () let visual = window#misc#visual let color_create = Truecolor.color_creator visual let w = window#misc#window let drawing = new GDraw.drawable w let _ = window#connect#destroy ~callback:Main.quit; let image = Image.create ~kind: `FASTEST ~visual: visual ~width: 256 ~height: 256 in let draw () = for x = 0 to 255 do for y = 0 to 255 do let r,g,b = rgb_at x y in Image.put_pixel image ~x: x ~y: y ~pixel: (color_create ~red: (r * 256) ~green: (g * 256) ~blue: (b * 256)) done done in let display () = drawing#put_image image ~xsrc:0 ~ysrc:0 ~xdest:0 ~ydest:0 ~width:256 ~height:256 in draw (); window#event#connect#after#expose ~callback: begin fun _ -> display (); false end; (* Thread.join id *) window#show (); Main.main ()