[Gtk-sharp-list] Strange output working with Gtk.Image. Maybe a bug?

Antonio Martínez Alvarez amartinez@atc.ugr.es
Sun, 20 Jun 2004 15:06:08 +0200


Hello folks,

I'm trying to add a Bitmap inside a Gtk.ScrolledWindow. I create the 
bitmap in memory  with a Gdk.Pixmap.
This is what I obtain depending on the height of the bitmap:

1.- If the height is small, everything works.
2.- If the height is not small, for example 60000 pixels:
       2.1 If executed under Linux: Drawing not work. A black screen.
       2.2 If executed under Windows: It seems to works, but when I try 
to scroll down the bitmap I can see naughty things.

Probed with:
    Mono Beta3 and Gtk# 0.98 under Linux and Mono 0.31 and Gtk# 0.18 
under Window.

I paste a little example which shows this behavior, to compile:     mcs 
-r:gtk-sharp -r:gdk-sharp theexample.cs
You can try to change the Height value to 200 (int the clicked method) 
to see how it works !!!

Thanks in advance.

// Exaple...
using System;
using Gtk;

class app {
  static ScrolledWindow sw;
  static Gtk.Image im = null;
  static Gdk.GC gc;

  public app () {
    Application.Init ();

    Gtk.Window win = new Gtk.Window ("OffScreen test");
    win.DeleteEvent += new DeleteEventHandler (quit);
    win.SetDefaultSize (200,400);
    sw = new Gtk.ScrolledWindow ();
    Button b = new Button ("Draw");
    b.Clicked += new EventHandler (clicked);
    VBox vb = new VBox (false, 3);
    vb.PackStart (sw, true, true, 2);
    vb.PackStart (b, false, true, 2);    
    win.Add (vb); win.ShowAll ();
    gc = new Gdk.GC (win.GdkWindow);
   
    Application.Run ();
  }

  static void clicked (object o, EventArgs ea) {
   
    int Height = 3000;  // It works with for example .. 200
    int Size = 40; // Size of every square
   
    Gdk.Pixmap pm = new Gdk.Pixmap (sw.GdkWindow, Size + 2, 
Height*(Size+1), -1);
    Random rg = new Random (255);
   
    for (int file = 0; file < Height*(Size/10); file ++) {
         gc.RgbFgColor = new Gdk.Color ((byte) rg.Next (), (byte) 
rg.Next(), 255);
         pm.DrawRectangle (gc, true,1,file*(Size-1),Size,Size-2);
    }
    if (im == null) {
      im = new Gtk.Image ();
      im.SetFromPixmap (pm, null);   
      sw.AddWithViewport (im);
    }  
    im.Show ();
  }

  static void quit (object o, DeleteEventArgs dea) {
    Application.Quit ();
    System.Environment.Exit (0);
  }

  static void Main () {
    new app();
  }
}

--
Antonio Martinez