Click here to Skip to main content
15,879,474 members
Articles / Programming Languages / C#

Article Two: Building a UI Platform in C# - Testing via UI Animation

,
Rate me:
Please Sign up or sign in to vote.
4.20/5 (7 votes)
3 Mar 20055 min read 51.3K   927   33  
Describes an implementation of UI animation for the support of Test-Driven Development.
// (c) 2003-2005 Datron, Inc.  All rights reserved. http://www.blix.net

using System;

namespace freeBlix
{
	public class Graphics: IDisposable
	{
		#region static FromImage
		public static Graphics FromImage(System.Drawing.Image aImage)
		{
			return new Graphics(System.Drawing.Graphics.FromImage(aImage));
		}
		#endregion

		#region Fields
		private System.Drawing.Graphics _WindowsGraphics;
		#endregion

		#region Graphics(aGraphics)
		public Graphics(System.Drawing.Graphics aGraphics)
		{
			_WindowsGraphics = aGraphics;
		}
		#endregion

		#region Clear
		public void Clear(System.Drawing.Color aColor)
		{
			_WindowsGraphics.Clear(aColor);
		}
		#endregion
		#region DrawImage(aImage, aLocation)
		public void DrawImage(System.Drawing.Image aImage, Point aLocation)
		{
			_WindowsGraphics.DrawImage(aImage, aLocation.X, aLocation.Y);
		}
		#endregion
		#region DrawImage(aImage, aLocation, aRectangle)
		public void DrawImage(System.Drawing.Image aImage, Point aLocation, Rectangle aRectangle)
		{	
			System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(aRectangle.Left, aRectangle.Top, aRectangle.Width, aRectangle.Height);

			_WindowsGraphics.DrawImage(aImage, aLocation.X, aLocation.Y, rectangle, System.Drawing.GraphicsUnit.Pixel);			
		}
		#endregion
		#region DrawImage(aImage, aDestinationRectangle, aSourceRectangle)
		public void DrawImage(System.Drawing.Image aImage, Rectangle aDestinationRectangle, Rectangle aSourceRectangle)
		{
			System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(aDestinationRectangle.Left, aDestinationRectangle.Top, aDestinationRectangle.Width, aDestinationRectangle.Height);
			System.Drawing.Rectangle sourceRect = new System.Drawing.Rectangle(aSourceRectangle.Left, aSourceRectangle.Top, aSourceRectangle.Width, aSourceRectangle.Height);

			_WindowsGraphics.DrawImage(aImage, destRect, sourceRect, System.Drawing.GraphicsUnit.Pixel);
		}
		#endregion	
		#region DrawRectangle
		public void DrawRectangle(System.Drawing.Pen aPen, Rectangle aRectangle)
		{
			_WindowsGraphics.DrawRectangle(aPen, aRectangle.Left, aRectangle.Top, aRectangle.Width - 1, aRectangle.Height - 1);
		}
		#endregion
		#region DrawLine(aPen, aStartPoint, aEndPoint)
		public void DrawLine(System.Drawing.Pen aPen, Point aStartPoint, Point aEndPoint)
		{
			int x1 = aStartPoint.X;
			int x2 = aEndPoint.X;
			int y1 = aStartPoint.Y;
			int y2 = aEndPoint.Y;

			_WindowsGraphics.DrawLine(aPen, x1, y1, x2, y2);
		}
		#endregion
		#region DrawLine(aPen, aX1, aY1, aX2, aY2)
		public void DrawLine(System.Drawing.Pen aPen, int aX1, int aY1, int aX2, int aY2)
		{
			_WindowsGraphics.DrawLine(aPen, aX1, aY1, aX2, aY2);
		}
		#endregion
		#region DrawPixel(aPen, aX, aY)
		public void DrawPixel(System.Drawing.Pen aPen, int aX, int aY)
		{
			_WindowsGraphics.DrawLine(aPen, aX, aY, (float)aX + 0.1f, aY);
		}
		#endregion
		#region DrawPixel(aPen, aPoint)
		public void DrawPixel(System.Drawing.Pen aPen, Point aPoint)
		{
			_WindowsGraphics.DrawLine(aPen, aPoint.X, aPoint.Y, (float)aPoint.X + 0.1f, aPoint.Y);
		}
		#endregion
		#region FillRectangle
		public void FillRectangle(System.Drawing.Brush aBrush, Rectangle aRectangle)
		{
			_WindowsGraphics.FillRectangle(aBrush, aRectangle.Left, aRectangle.Top, aRectangle.Width, aRectangle.Height);
		}
		#endregion

		#region Clip
		public Rectangle Clip
		{
			get
			{
				System.Drawing.Rectangle clipBounds = System.Drawing.Rectangle.Truncate(_WindowsGraphics.ClipBounds);

				return new Rectangle(clipBounds.Left, clipBounds.Top, clipBounds.Width, clipBounds.Height);
			}
			set
			{
				System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(value.Left, value.Top, value.Width, value.Height);

				_WindowsGraphics.Clip = new System.Drawing.Region(rectangle);
			}
		}
		#endregion
		#region WindowsGraphics
		public System.Drawing.Graphics WindowsGraphics
		{
			get
			{
				return _WindowsGraphics;
			}
		}
		#endregion

		#region IDisposable
		void IDisposable.Dispose()
		{
			((IDisposable)_WindowsGraphics).Dispose();
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Sagerion, LLC
United States United States
I read About Face by Alan Cooper in 1995 and immediately recognized it as a founding document for the future of software. I also recognized we had a long, long way to go - and yes, even with the advent of iOS, we are still not there yet.

At my company, Sagerion (say-jair-ee-on), we can take a look at your planned or existing software and suggest ways of making it better - lots better. We can develop down-to-the-pixel blueprints showing exactly what our suggestions mean. We can help manage on-going development to make sure the top-notch user-experience we've suggested really does get built. Now, honestly, how often have you ever seen all those things happen?

You may or may not already have great development going on - but what does that matter if you don't have great design driving it?

Feel free to contact me at tom@sagerion.com, I would love to hear about your next ground-breaking project.

Written By
Founder Sagerion LLC
United States United States
www.filoshare.com
-It is a fresh and free distributed source control system.

Comments and Discussions