Re: Help me about this "drawable" error
- From: Jonathan Irwin <jmi25 cam ac uk>
- To: Jung-Wuk Hong <jwhong MIT EDU>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Help me about this "drawable" error
- Date: Fri, 10 Nov 2000 11:54:15 +0000 (GMT)
On Fri, 10 Nov 2000, Jung-Wuk Hong wrote:
I wrote a function to write text on popup window. However it doesn't work
correctly.
I met the error drawable!=NULL.
Please help me about this problem.
Before you can use GDK functions to draw on a window, it's X window has to
exist. You need to call gtk_widget_realize() on property_window so it's X
window (or gdk window) is created, then you can draw on it (GDK windows
are not created immediately when you gtk_widget_show() a widget).
Alternatively (and a better approach in this case) you could use a signal
handler connected to the "expose_event" event on the GtkDrawingArea (then
things will get redrawn properly when the user covers up the window and
then uncovers it):
gtk_signal_connect(GTK_OBJECT(plot_area), "expose_event",
GTK_SIGNAL_FUNC(expose_event), NULL);
Then do the drawing in that instead:
gint expose_event (GtkWidget *w, GdkEventExpose *ev, gpointer data) {
gdk_draw_text(GTK_WIDGET(w)->window, font,
GTK_WIDGET(w)->style->black_gc, 10,10,
"abc",15);
return(FALSE);
}
If you are going to do a lot of drawing, then it may be a good idea to
create a pixmap, and draw on that (I would use the "realize" event to
create the pixmap and allocate colours, fonts, etc., storing them in a
struct), then draw on the pixmap as required, updating the display by
drawing the pixmap to the GtkDrawingArea: I do this in the expose_event
handler, and then call gtk_widget_draw() on the GtkDrawingArea, which
triggers the expose_event handler. That should eliminate most of the
flickering which will be seen if you update the window directly.
Jonathan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]