[Gtk-sharp-list] Memory Issue with Drawable

Luciano _ lnc19 at hotmail.com
Tue Mar 13 08:06:09 EDT 2007


Hi:

1) The first and the most importan problem: I'm having problem to make a 
draw into a drawable. It uses to much memory. My application get to much 
bussy for this operation. The idea is to show a number of lines in a drawing 
area with line numbers (It is a file viewer like, so the number of lines is 
around 1500 or 100000 and even more).

2) The other problem is that the Rectangle that i Draw in 
OnDrawing_ButtonPressed is displayed but at the same time, it is hidden 
automatically. Why is that? (If i did a rectangle on expose event it works 
great, but i need to do when the user press the mouse button).

The source code:

using System;
using System.Drawing;
using Gtk;

namespace Test
{
	public partial class TextViewer : Gtk.Bin
	{
		protected int MaxWidth;
		protected string[] Lines;
		public TextViewer(string[] lines)
		{
			this.Build();
			this.da.AddEvents((int)Gdk.EventMask.ButtonPressMask);
			this.da.ExposeEvent += new ExposeEventHandler(this.OnDrawing_Exposed);
			this.da.ButtonPressEvent += new 
ButtonPressEventHandler(this.OnDrawing_ButtonPressed);
			Lines = lines;
			this.ShowAll();
		}

		protected void OnDrawing_Exposed(object sender, ExposeEventArgs args)
		{
			int h = this.Lines.Length * 10 + 10;
			DrawingArea da = (DrawingArea)sender;
			using(Graphics g = Gtk.DotNet.Graphics.FromDrawable(da.GdkWindow))
			{
	               Font f = new Font("Arial", 10);
	               using(Brush b = new SolidBrush(Color.Black))
	               {
		               for(int i = 0; i < this.Lines.Length; i ++)
		               {
		               		int pos = 0 + (10 * i);
							g.DrawString(i.ToString().PadLeft(8, '0'), f, b, 5, pos);
							g.DrawString(this.Lines[i], f, b, 90, pos);
							if(this.Lines[i].Trim().Length > this.MaxWidth)
								this.MaxWidth = this.Lines[i].Trim().Length;
		               }
		               this.MaxWidth = this.MaxWidth * 2;
					   using(Pen p = new Pen(b))
							g.DrawLine(p, 80, 0, 80, h);
		           }
			}
			da.SetSizeRequest(this.MaxWidth, h);
		}

		protected void OnDrawing_ButtonPressed(object sender, ButtonPressEventArgs 
args)
		{
			DrawingArea da = (DrawingArea)sender;
			int lmin;
			int l = Convert.ToInt32(args.Event.Y);
			string ls = l.ToString();
			if(ls.Length == 1) {
				lmin = 0;
			}
			else {
				lmin = Convert.ToInt32(ls.Substring(0, ls.Length-1) + "0");
			}
			using(Graphics g = Gtk.DotNet.Graphics.FromDrawable(da.GdkWindow))
			{
				Point p = new Point(0, lmin);
				Size sz = new Size(this.MaxWidth, 10);
				Rectangle r = new Rectangle(p, sz);
				Brush b = new SolidBrush(Color.Red);
				Pen pe = new Pen(b);
				g.DrawRectangle(pe, r);
				((IDisposable)b).Dispose();
				((IDisposable)pe).Dispose();
			}

		}
	}
}


Thanks a lot
Luciano

_________________________________________________________________
¿Cuánto vale tu auto? Tips para mantener tu carro. ¡De todo en MSN Latino 
Autos! http://latino.msn.com/autos/



More information about the Gtk-sharp-list mailing list