From: Stalkern 2 Reply-To: stalkern2 at tin.it To: lablgtk at kaba.or.jp Subject: offscreen backing pixmap: C/gtk to ocaml/lablgtk translation? Date: Thu, 3 Jul 2003 09:47:41 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200307030947.41209.stalkern2 at tin.it> Hello I'm trying to manage to use a few gtk code in a lablgtk flavor. Can anybody look at my attempt? I don't use C, but most of all I can't find the equivalent of some functions. My comments are in /*(**)*/ (from http://www.gtk.org/tutorial1.2/gtk_tut-23.html) --------------------------------------------------------------------------- Having to remember everything that was drawn on the screen so we can properly redraw it can, to say the least, be a nuisance. In addition, it can be visually distracting if portions of the window are cleared, then redrawn step by step. The solution to this problem is to use an offscreen backing pixmap. Instead of drawing directly to the screen, we draw to an image stored in server memory but not displayed, then when the image changes or new portions of the image are displayed, we copy the relevant portions onto the screen. [...] We create the pixmap in our "configure_event" handler. This event is generated whenever the window changes size, including when it is originally created. /* Backing pixmap for drawing area */ static GdkPixmap *pixmap = NULL; /*(*-->a option ref in Ocaml*)*/ /* Create a new backing pixmap of the appropriate size */ static gint configure_event (GtkWidget *widget, GdkEventConfigure *event) { if (pixmap) /*(*-->a match for a option ref in Ocaml*)*/ gdk_pixmap_unref(pixmap); /*(*-->???*)*/ pixmap = gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1); /*(*-->Gdk.Pixmap #create args*)*/ gdk_draw_rectangle (pixmap, widget->style->white_gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height); /*(*-->Gdk.drawable #rectangle args*)*/ return TRUE; } The call to gdk_draw_rectangle() clears the pixmap initially to white. We'll say more about that in a moment. Our exposure event handler then simply copies the relevant portion of the pixmap onto the screen (we determine the area we need to redraw by using the event->area field of the exposure event): /*(*-->GdkEvent.Expose #area???*)*/ /* Redraw the screen from the backing pixmap */ static gint expose_event (GtkWidget *widget, GdkEventExpose *event) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], pixmap, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height); return FALSE; } /*(*furthermore we need to connect this redrawing function as a callback for the expose signal*)*/ --------------------------------------------------------------------------- Thanks for any hint Ernesto