[Gtk-sharp-list] Problems with Gdk.Pixmap

Lee Mallabone gnome@fonicmonkey.net
14 Mar 2003 21:39:43 +0000


--=-XzKS3uYDNpSPAdMgunc+
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all,

I'm trying to write a custom widget in Gtk# with Gtk.DrawingArea.

I basically want to draw a huge Pixmap and then have my DrawingArea's
expose method draw a small bit of the Pixmap, depending on various
factors.

However, only garbled pixels get rendered to my Pixmap. I've attached
the simplest test case I could write that demonstrates this.

Could someone take a look at my attached code and see if it "should
work"? I've not used Gdk very much, so I might just be using Pixmap
wrong. However, I tried to follow Miguel's mlist example to get the
right idea...

If anyone can verify I'm doing The Right Thing, I'll open a bug for
this.

Regards,

Lee.


--=-XzKS3uYDNpSPAdMgunc+
Content-Disposition: attachment; filename=pixmaptest.cs
Content-Type: text/plain; name=pixmaptest.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit


using Gtk;
using Gdk;
using Pango;
using GtkSharp;

public class PixmapTest: Gtk.DrawingArea
{
	private const int WIDTH = 60;
	private const int HEIGHT = 400;
	private Pango.Layout textRenderer;

	public PixmapTest()
	{
		SetSizeRequest(WIDTH, HEIGHT);
		textRenderer = new Pango.Layout(PangoContext);
		textRenderer.FontDescription = Pango.FontDescription.FromString("Tahoma 7");
		
		ExposeEvent += new ExposeEventHandler(ExposeHandler);
		Show();
	}

	private Gdk.Pixmap image;
	
	private void CreateBigPixmap(Gdk.Window win)
	{
		image = new Pixmap(win, WIDTH, HEIGHT, -1);	
		
		if (image == null)
		{	
			throw new System.Exception("Pixmap did not initialize!");
		}
		
		int wide, high;
		
		image.GetSize(out wide, out high);
		// Draw the background
		win.DrawRectangle (Style.WhiteGC, 1, 0, 0, wide, high);
		
		// Draw a line and some text
		textRenderer.SetText("TESTING TESTING 123! Testing Pixmap!");
		win.DrawLine(Style.BlackGC, 0, 5, wide, 5);
		win.DrawLayout(Style.BlackGC, 0, 20, textRenderer);
	}
	
	
	private void ExposeHandler(object source, ExposeEventArgs args)
	{
		if (image == null)
		{
			CreateBigPixmap(args.Event.window);
		}
		args.Event.window.DrawDrawable(Style.BlackGC, image, 10, 10, 
						 0, 0, WIDTH, HEIGHT);
		//args.RetVal = true;
	}

	public static void Main()
	{
  		Gtk.Application.Init();
		
		Gtk.Window win = new Gtk.Window("Pixmap test");
		DrawingArea zone = new PixmapTest();
		win.Add(zone);
		win.ShowAll();
		
		Gtk.Application.Run();
	}
}

--=-XzKS3uYDNpSPAdMgunc+--