[Gtk-sharp-list] howto draw a line

Rachel Hestilow hestilow@ximian.com
12 Jul 2002 01:32:59 -0500

(comments written below)

On Fri, 2002-07-12 at 01:14, Kees Jongenburger wrote:
> Hi, 
> I am very very new to c# and gtksharp. I am having great time 
> but it's very difficult to known where error lies, is it my programming 
> is it mono? is it gtksharp? anyway I am trying to write a little game
> using gtksharp/c# (Pong). 
> I am stucked because I can't find a way to draw lines on the screen 
> I have tried different approaches.
> -1 tried to create an DrawingArea and using the Expose event. but I
> can't find any method to draw on it :(

This is a bug in the wrapper generation.

> public void expose(object obj, EventArgs args){
> 	if (args is SignalArgs){
>              SignalArgs signalArgs = (SignalArgs)args;
>              signalArgs.RetVal = true;
>         }
>         if (obj is Pong){
>             Pong thePong = (Pong)obj;
>             Gdk.Window w = ParentWindow;
>         }
> }
> one other "problem" is that I can't write the 
> ExposeEvent += new EventHandler(pong.expose); in the Pong constructor
> I have to do something like this:
> Pong pong = new Pong();
> pong.ExposeEvent += new EventHandler(pong.expose);

A bug in how mcs handles events. Last I heard, Ravi is fixing it.
> -2 using a Gtk.image by loading it from disk and then changing the image
> Gtk.Image image= new Gtk.Image();
> image.Pixbuf = new Gdk.Pixbuf("pong.xpm");
> Gdk.Image img = image.ImageProp;
> for (int x =0 ; x < 640;x++){
>       for (int y =0 ; y < 200;y++){
>                img.PutPixel(0,0,1);
>       }
> }

You really don't want to do this, it is very broken from an X point of
view (Generates way too much traffic). Much better would be to edit the
pixel buffer within the Pixbuf before rendering, but I'm not sure that
is being wrapped correctly either.
> Do you think it is now possible to create a little multi-user game?
> I can think of a other possibility 
> -loading a background
> -loading the two pong bats and placing them on the background
> -moving the ball around
> is that possible?
> any help is welcome :)
> bye and thanks

The best way to do this is to use the Gnome Canvas, which is wrapped but
I don't imagine it is working very well (variable arguments,
_get_type-based constructors.) Feel free to try, of course. How did you
manage to run into so many existing problem areas? :-)

Hopefully some or most of these will be fixed within a week or two (or

-- Rachel