Gtk.DotNet && System.Drawing && Images, strange behavior

View: New views
3 Messages — Rating Filter:   Alert me  

Gtk.DotNet && System.Drawing && Images, strange behavior

by plushpuffin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I just ditched WinXP a few weeks ago and switched to Ubuntu 8.04, and I'm trying to port my C# Windows.Forms applications over to Gtk#. I have a newly-created sample Gtk# project that simply isn't working, and I'm not sure what it is that I'm doing wrong. I am using Gtk# with the Gtk-dotnet library so that my library files' graphics handling functions don't have to be rewritten. I noticed that many of my images, rectangles, and ellipses are being drawn at the wrong positions on the DrawingArea. Below is my code and a screenshot of the strange behavior I'm seeing.

I'm running monodevelop 1.0 and mono 1.9.1 (from the badgerports Ubuntu repository). I was originally using the official Ubuntu mono 1.2.6 release, but I decided to upgrade mono before coming here for help. It didn't fix anything.

I finally figured out what the problem is. For some reason, after drawing an image on the Graphics object, the next thing drawn, NO MATTER WHAT IT IS OR WHERE IT IS PLACED, is offset vertically by about the height of the image drawn. The next thing drawn after that is drawn in its proper position. Have I found a bug in the Gtk.DotNet class library, or I am just not understanding something?

I know that certain graphics libraries have a "pen cursor" which moves from place to place, so you can draw a square by saying 'place pen at 50:50, draw 100 right, draw 100 up, draw 100 left, draw 100 down," but that doesn't seem to be the case here because this strange behavior only takes effect after drawing an image. If I draw ellipse->rectangle->image, everything is in the right place. If I draw ellipse->image->rectangle, the rectangle will be shifted down by about the height of the image. Notice that I say "about the height," because as you can see in the attached screenshot, my attempted 4x4 square of images is NOT aligned along 32x32 boundaries. The top-left image is in the proper location, but the other three are shifted down 29 pixels (they shouldn't be shifted down at all), which makes no sense.

    protected virtual void OnDrawingarea1ExposeEvent (object o, Gtk.ExposeEventArgs args)
    {
        System.Drawing.Image pic = new Bitmap("./bots/grad.png");
       
        using( Graphics g = Gtk.DotNet.Graphics.FromDrawable(args.Event.Window) )
        {
            g.Clear(Color.Aqua);
            g.DrawImage(pic, 50.0F, 50.0F, 32, 32);
            g.DrawImage(pic, 50.0F, 82.0F, 32, 32);
            g.DrawImage(pic, 82.0F, 50.0F, 32, 32);
            g.DrawImage(pic, 82.0F, 82.0F, 32, 32);
        }
    }



Re: Gtk.DotNet && System.Drawing && Images, strange behavior

by plushpuffin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

plushpuffin wrote:
The top-left image is in the proper location, but the other three are shifted down 29 pixels (they shouldn't be shifted down at all), which makes no sense.

I think I've discovered the reason for this. It can't be coincidence that my menu strip is 29 pixels tall. It seems that, after drawing an image, the graphics library (or the Drawingarea widget itself) mistakenly adds the height of the menu strip a second time to the Drawingarea's y-offset. After drawing the NEXT image/polygon/line, however, it seems to recalculate and get the right y-offset again.

I have no idea why it screws up or why it fixes itself afterward. If someone else can confirm that does seem to be a bug (and that it's not one of those "up late last night, eyes bloodshot, brain fried, ignoring something that's staring me right in the face" situations), then I'll go find out how to submit a bug report.

Re: Gtk.DotNet && System.Drawing && Images, strange behavior

by Mike Kestner-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 2008-06-25 at 12:15 -0700, plushpuffin wrote:

> I have no idea why it screws up or why it fixes itself afterward. If someone
> else can confirm that does seem to be a bug (and that it's not one of those
> "up late last night, eyes bloodshot, brain fried, ignoring something that's
> staring me right in the face" situations), then I'll go find out how to
> submit a bug report.

I suspect this would be a problem with mono's System.Drawing as opposed
to Gtk.Dotnet, since all it does is hand you a surface to draw on.  One
way to verify that would be to make a simple test case in winforms on
mono and see if it does the same thing.  If so, you could probably file
a bug against mcs/classlibs.  That assumes the same code works properly
on the MS System.Drawing implementation.

Mike

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list