Re: [gtk-list] Simple Newbie Question: Draw a line in a window
- From: "Shawn T . Amundson" <amundson gimp org>
- To: khosro iglou com
- Cc: gtk-list redhat com
- Subject: Re: [gtk-list] Simple Newbie Question: Draw a line in a window
- Date: Sun, 27 Sep 1998 19:12:11 -0700
The reason you get the error is that you must differentiate between
the GTK+ and GDK windows. The GDK window is the window which is like
a simple X window and the GTK+ window is a high-level widget. So,
you want your draw line to look like:
gdk_draw_line (window->window,
window->style->black_gc,
100, 50, 50, 100);
Even with this change, you are not going to see a line drawn unless
you do it in an expose event. Below is a bit of code which does
what you are trying:
#include <gtk/gtk.h>
gint
expose (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
gdk_draw_line (widget->window,
widget->style->black_gc,
100, 50, 50, 100);
}
int
main (int argc, char *argv[])
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_signal_connect (GTK_OBJECT (window), "expose_event",
GTK_SIGNAL_FUNC (expose), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
An excellent example of using the expose event is the scribble-simple.c
example distributed with GTK+.
Obviously in order to get what you want (to show lines as they are drawn),
you can't do all your drawing in an expose event. Basically the expose
event tells you to show what is already there.
So, what you want is probably to draw to a pixmap and then draw the
pixmap into the window when you want to see the next frame or when
and expose event happens. scribble-simple.c does this, so you have
a place to look for that too.
Good luck,
-Shawn
On Sun, Sep 27, 1998 at 09:23:35PM -0400, khosro@iglou.com wrote:
>
> Hi all,
>
> First of all, thanks to all, who sent me hints, upon my first post. he problem is not quite rectified though:
>
> I am trying to open a window,
> show it,
> "then" draw a line in it,
> (later draw other things in it),
> and watch while the line (and other figures) are sequentially drawn.
>
> The following simple code, creates a window, which appears for a fraction of a second, then disappears; and I get the following error message:
>
> simple-line-in-window.c: In function `main':
> simple-line-in-window.c:13: warning: passing arg 1 of `gdk_draw_line' from incompatible pointer type
> ** ERROR **: sigsegv caught
>
> I know, that gdk_draw_line(...) expects a GdkWindow instead of the GtkWindow. How do I remedy that? And what else do I need to change to make it work?
>
> Many TIA,
>
> khosro
> =============================================================================
>
> #include <gtk/gtk.h>
>
> int
> main (int argc, char *argv[])
> {
> GtkWidget *window;
>
> gtk_init (&argc, &argv);
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_widget_show (window);
> gdk_draw_line (window,
> window->style->black_gc,
> 100, 50, 50, 100);
> gtk_main ();
> return 0;
> }
>
>
>
>
>
>
>
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
>
--
Shawn T. Amundson
amundson@gimp.org http://www.gimp.org/~amundson
"The assumption that the universe looks the same in every
direction is clearly not true in reality." - Stephen Hawking
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]