Re: [gtk-list] Need help with gdk_draw_*
- From: Owen Taylor <owt1 cornell edu>
- To: gtk-list redhat com
- Cc: Ian Main <slow intergate bc ca>
- Subject: Re: [gtk-list] Need help with gdk_draw_*
- Date: Tue, 16 Dec 1997 16:08:21 -0500
> I am trying to learn how to use the various gdk_draw_* routines, so far
> without success. I read the tutorial, especially the Scribble drawing
> program part, yet I can't get the following code to work. If I understood
> what I read, I should be getting a 200x200 pixel window with a white
> rectangle inside of it; instead I just get the 200x200 pixel window.
>
> I'd appreciate any insights. Actually, the Scribble part of the tutorial
> refers the reader to the complete source code for Scribble, which I can't
> find. I'd prefer it if someone just pointed me to the source code since I'd
> like to tackle it all myself - I feel I learn better that way. I though
> maybe I'd look at the gzilla sources but I am still too novice to
> comprehend programs of that size easily.
http://www.msc.cornell.edu/~otaylor/gtk-gimp/tutorial/
When Ian gets a chance, hopefully these can be put at the same place
as the main tutorial or a link can can be set up.
> #include <gtk/gtk.h>
>
> int main(int argc, char *argv[])
> {
> GtkWidget *mainwin;
>
> gtk_init(&argc, &argv);
> mainwin=gtk_window_new(GTK_WINDOW_TOPLEVEL);
> gtk_widget_show(mainwin);
>
> gdk_draw_rectangle(mainwin->window, mainwin->style->white_gc, TRUE,
> 50, 50, 150, 150);
>
> gtk_main();
> return 0;
> }
This is a sort of a classic problem. You can't draw on a window
until is realized (the X window is created) and it is mapped
(The window is drawn on the screen) The easiest way to do
this is to do your drawing in an expose handler. (That way,
it will also be redrawn if the window is hidden and then revealed)
(Also, you should compile GTK with --enable-debug. You would get
a warning that mainwin->window is NULL here)
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]