[Gtk-sharp-list] EventBox attached to Cairo Context?

MrFreeman biggestsonicfan at gmail.com
Wed Apr 6 23:55:48 EDT 2011


I have finally found a method that works in displaying the animated GIF file
with correct transparency:

using System;

using Gtk;

using Cairo;



public class MacMacro2 : Gtk.Window
{
	public MacMacro2  (string imgstring) : base(Gtk.WindowType.Popup)
	{
		//base.AppPaintable = true;
		Gtk.EventBox eb = new Gtk.EventBox();
		eb.Colormap = Gdk.Screen.Default.RgbaColormap;
		eb.Events = Gdk.EventMask.ButtonPressMask;
		Gtk.Image img = new Gtk.Image(imgstring);
		
		if(img.StorageType == Gtk.ImageType.Pixbuf){
		Gdk.Pixbuf pba = img.Pixbuf;
		img.Destroy();
		base.Resize(pba.Width, pba.Height);
		base.Move(Gdk.Screen.Default.Width - pba.Width, Gdk.Screen.Default.Height
- pba.Height);
		base.ExposeEvent += delegate(object o, ExposeEventArgs args) {
			
			Context context = Gdk.CairoHelper.Create(base.GdkWindow);
			context.SetSourceRGBA(1.0, 1.0, 1.0, 0.0);
			context.Operator = Operator.Source;
			context.Paint();			

			Gdk.CairoHelper.SetSourcePixbuf(context, pba.AddAlpha(true, 213, 218,
240), 0, 0);
			context.Paint();
			((IDisposable)context).Dispose();		

			};
		}else if (img.StorageType == Gtk.ImageType.Animation){
			img.Destroy();
			
			Gdk.PixbufAnimation pba = new Gdk.PixbufAnimation(imgstring);
			Gdk.PixbufAnimationIter iter = pba.GetIter(IntPtr.Zero);
			base.Resize(iter.Pixbuf.Width, iter.Pixbuf.Height);
			base.Move(Gdk.Screen.Default.Width - iter.Pixbuf.Width,
Gdk.Screen.Default.Height - iter.Pixbuf.Height);

			base.ExposeEvent+= delegate(object o, ExposeEventArgs args) {
				pba.Dispose();
				Context context = Gdk.CairoHelper.Create(base.GdkWindow);
				context.SetSourceRGBA(1.0, 1.0, 1.0, 0.0);
				context.Operator = Operator.Source;
				context.Paint();
				Gdk.Pixbuf temp = iter.Pixbuf;
				Console.WriteLine(iter.DelayTime);
				if(iter.DelayTime > -1)
				{
					Gdk.CairoHelper.SetSourcePixbuf(context, temp.AddAlpha(true, 213, 218,
240), 0, 0);
					context.Paint();
					//base.GdkWindow.InvalidateRegion(base.GdkWindow.VisibleRegion, true);
					//base.GdkWindow.ProcessUpdates(true);
				
				System.Threading.Thread.Sleep(iter.DelayTime);
				iter.Advance(IntPtr.Zero);
				//temp.Dispose();
				((IDisposable)temp).Dispose();
				((IDisposable)context).Dispose();
				base.QueueDraw();
			}else{

				}
			};

		}else{	

		}
		eb.ButtonPressEvent += delegate(object o, ButtonPressEventArgs be) {					
			if(be.Event.Button == 3){
				img.Destroy();
				eb.Destroy();
				base.Destroy();
				Main.Quit();
			}else{
				img.Destroy();
				eb.Destroy();
				base.Destroy();
				System.Diagnostics.Process.Start("website url here");
				Main.Quit();
			}
		};
		//eb.Add(img);
		//base.Add(eb);
		//eb.Realize();
		//eb.ShowAll();
	}
}


But now I am having a very difficult time managing memory. However, the GIF
displays properly. The EventBox does not like being attached to this for
whatever reason.

--
View this message in context: http://mono.1490590.n4.nabble.com/EventBox-attached-to-Cairo-Context-tp3427011p3432434.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110406/a9f10ad8/attachment.html 


More information about the Gtk-sharp-list mailing list