/* * Locators - A factory to create useful locators * * Author: Phillip Piper * Date: 19/10/2009 1:02 AM * * Change log: * 2010-01-18 JPP - Split out PointLocator.cs and RectangleFromCornersLocator.cs * 2009-10-19 JPP - Initial version * * To do: * * Copyright (C) 20009-2014 Phillip Piper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * If you wish to use this code in a closed source application, please contact phillip_piper@bigfoot.com. */ using System.Drawing; namespace BrightIdeasSoftware { /// /// Locators is a Factory that simplifies the creation of common locators. /// /// Obviously, locators can still be created directly, but this class /// makes the creation of common locators easy. public static class Locators { /// /// Create a PointLocator for the given fixed point /// public static IPointLocator At(int x, int y) { return new FixedPointLocator(new Point(x, y)); } public static IPointLocator At(Point pt) { return new FixedPointLocator(pt); } /// /// Create a PointLocator that will align the given corner of a sprite /// at the corresponding corner of the animation. /// /// For example, /// Locators.SpriteAligned(Corners.BottomRight) means the bottom right corner /// of the sprite will be placed at the bottom right corner of the animation. /// /// The corner to be aligned AND the corner at which it will be aligned /// A point locator public static IPointLocator SpriteAligned(Corner corner) { return Locators.SpriteAligned(corner, corner, Point.Empty); } /// /// The same as SpriteAligned(Corner) but offset by a constant amount. /// /// /// /// public static IPointLocator SpriteAligned(Corner corner, Point offset) { return Locators.SpriteAligned(corner, corner, offset); } /// /// Create a PointLocator that will align the given corner of a sprite /// at the given corner of the animation. /// /// For example, /// Locators.SpriteAligned(Corners.MiddleCenter, Corner.BottomRight) means the center /// of the sprite will be placed at the bottom right corner of the animation. /// /// The corner of the sprite to be aligned /// The corner at which it will be aligned /// A point locator public static IPointLocator SpriteAligned(Corner spriteCorner, Corner animationCorner) { return Locators.SpriteAligned(spriteCorner, animationCorner, Point.Empty); } /// /// The same as SpriteAligned(Corner, Corner) but offset by a constant amount. /// /// /// /// /// public static IPointLocator SpriteAligned(Corner spriteCorner, Corner animationCorner, Point offset) { return new AlignedSpriteLocator( Locators.AnimationBoundsPoint(animationCorner), Locators.SpriteBoundsPoint(spriteCorner), offset); } /// /// Create a PointLocator that will align the given corner of a sprite /// at the proportional location of bounds of the animation. /// /// For example, /// Locators.SpriteAligned(Corners.MiddleCenter, 0.6f, 0.7f) means the center /// of the sprite will be placed 60% across and 70% down the animation. /// /// The corner of the sprite to be aligned /// The x axis proportion /// The y axis proportion /// A point locator public static IPointLocator SpriteAligned(Corner spriteCorner, float proportionX, float proportionY) { return Locators.SpriteAligned(spriteCorner, proportionX, proportionY, Point.Empty); } /// /// The same as SpriteAligned(Corner, float, float) but offset by a constant amount. /// /// /// /// /// /// public static IPointLocator SpriteAligned(Corner spriteCorner, float proportionX, float proportionY, Point offset) { return new AlignedSpriteLocator( Locators.AnimationBoundsPoint(proportionX, proportionY), Locators.SpriteBoundsPoint(spriteCorner), offset); } /// /// Create a FixedRectangleLocator for the given fixed co-ordinates. /// public static IRectangleLocator At(int x, int y, int width, int height) { return new FixedRectangleLocator(new Rectangle(x, y, width, height)); } public static IRectangleLocator At(Rectangle r) { return new FixedRectangleLocator(r); } /// /// Create a Locator that gives the bounds of the animation /// /// public static IRectangleLocator AnimationBounds() { return new AnimationBoundsLocator(); } /// /// Create a Locator that gives the bounds of the animation inset by a fixed amount /// /// /// /// public static IRectangleLocator AnimationBounds(int x, int y) { return new AnimationBoundsLocator(x, y); } /// /// Create a Locator that gives the bounds of the sprite /// /// public static IRectangleLocator SpriteBounds() { return new SpriteBoundsLocator(); } /// /// Create a Locator that gives the bounds of the sprite inset by a fixed amount /// /// /// /// public static IRectangleLocator SpriteBounds(int x, int y) { return new SpriteBoundsLocator(x, y); } /// /// Returns a Locator that gives a point on the bounds of a sprite /// /// /// public static IPointLocator SpriteBoundsPoint(Corner corner) { return new PointOnRectangleLocator(new SpriteBoundsLocator(), corner); } /// /// Returns a Locator that gives a point proportional to the bounds of a sprite /// /// /// /// public static IPointLocator SpriteBoundsPoint(float proportionX, float proportionY) { return new PointOnRectangleLocator(new SpriteBoundsLocator(), proportionX, proportionY); } /// /// Returns a Locator which gives a corner of the bounds of the animation /// /// /// public static IPointLocator AnimationBoundsPoint(Corner corner) { return new PointOnRectangleLocator(new AnimationBoundsLocator(), corner); } /// /// Returns a Locator which gives a corner of the bounds of the animation inset by a fixed amount /// /// /// /// /// public static IPointLocator AnimationBoundsPoint(Corner corner, int xOffset, int yOffset) { return new PointOnRectangleLocator(new AnimationBoundsLocator(), corner, new Point(xOffset, yOffset)); } /// /// Returns a Locator that gives a point proportional to the bounds of the animation. /// /// /// /// public static IPointLocator AnimationBoundsPoint(float proportionX, float proportionY) { return new PointOnRectangleLocator(new AnimationBoundsLocator(), proportionX, proportionY); } } }