#region LGPL License
/*************************************************************************
Crazy Eddie's GUI System (http://crayzedsgui.sourceforge.net)
Copyright (C)2004 Paul D Turner (crayzed@users.sourceforge.net)
C# Port developed by Chris McGuirk (leedgitar@latenitegames.com)
Compatible with the Axiom 3D Engine (http://axiomengine.sf.net)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*************************************************************************/
#endregion LGPL License
#region Using directives
using System;
using System.Text;
#endregion
namespace CrayzEdsGui.Base{
/// <summary>
/// Struct that holds the size (width and height) of something.
/// </summary>
public struct Size {
public float width;
public float height;
public Size(float width, float height) {
this.width = width;
this.height = height;
}
/// <summary>
/// Returns a string representation of this Size object.
/// </summary>
/// <returns>String representation of this object.</returns>
public override string ToString()
{
return string.Format( "w:{0} h:{1}", width, height );
}
/// <summary>
/// Parses the string representation of a Size object, and returns the
/// corresponding object.
/// </summary>
/// <param name="data">String representation of a Size object.</param>
/// <returns>Size object corresponding to the passed in string.</returns>
public static Size Parse( string data )
{
string[] parameters = data.Split( new char[] { ' ', ':' } );
Size size = new Size();
for( int i = 0; i < parameters.Length; i++ )
{
if( 0 == parameters[i].CompareTo( "w" ) )
{
size.width = float.Parse( parameters[++i] );
}
else if( 0 == parameters[i].CompareTo( "h" ) )
{
size.height = float.Parse( parameters[++i] );
}
}
return size;
}
}
}
|