Skip to content

Commit

Permalink
[MapleLib] InfoTool - added GetLtRbRectangle() and SetLtRbRectangle()…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
lastbattle committed Mar 1, 2022
1 parent 6470095 commit c169162
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions MapleLib/WzLib/WzStructure/InfoTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
along with this program. If not, see <http://www.gnu.org/licenses/>.*/

using System;
using System.Drawing;
using MapleLib.WzLib.WzProperties;

namespace MapleLib.WzLib.WzStructure
Expand Down Expand Up @@ -100,7 +101,47 @@ public static WzStringProperty SetOptionalTranslatedInt(int? value)
}
#endregion

#region Rectangle
/// <summary>
/// Gets System.Drawing.Rectangle from "lt" and "rb"
/// </summary>
/// <param name="parentSource"></param>
/// <returns></returns>
public static Rectangle GetLtRbRectangle(this WzImageProperty parentSource)
{
WzVectorProperty lt = InfoTool.GetOptionalVector(parentSource["lt"]);
WzVectorProperty rb = InfoTool.GetOptionalVector(parentSource["rb"]);

int width = rb.X.Value - lt.X.Value;
int height = rb.Y.Value - lt.Y.Value;

Rectangle rectangle = new Rectangle(
lt.X.Value,
lt.Y.Value,
width,
height);
return rectangle;
}

/// <summary>
/// Sets the "lt" and "rb" value in a WzImageProperty parentSource
/// derived from Rectangle
/// </summary>
/// <param name="parentSource"></param>
/// <param name="rect"></param>
public static void SetLtRbRectangle(this WzImageProperty parentSource, Rectangle rect)
{
parentSource["lt"] = InfoTool.SetVector(rect.X, rect.Y);
parentSource["rb"] = InfoTool.SetVector(rect.X + rect.Width, rect.Y + rect.Height);
}
#endregion

#region Vector
/// <summary>
/// Gets the vector value of the WzImageProperty
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static WzVectorProperty GetVector(this WzImageProperty source)
{
return (WzVectorProperty)source;
Expand Down

0 comments on commit c169162

Please sign in to comment.