using System; using System.Drawing; namespace PaintDotNet { public abstract class SnapObstacle { public const int DefaultSnapProximity = 15; public const int DefaultSnapDistance = 3; private string name; protected Rectangle previousBounds; // for BoundsChanged event protected Rectangle bounds; private SnapRegion snapRegion; private bool stickyEdges; private int snapProximity; private int snapDistance; private bool enabled; private bool enableSave; public string Name { get { return this.name; } } /// /// Gets the bounds of this snap obstacle, defined in coordinates relative to its container. /// public Rectangle Bounds { get { return this.bounds; } } protected virtual void OnBoundsChangeRequested(Rectangle newBounds, ref bool handled) { } public bool RequestBoundsChange(Rectangle newBounds) { bool handled = false; OnBoundsChangeRequested(newBounds, ref handled); return handled; } public SnapRegion SnapRegion { get { return this.snapRegion; } } /// /// Gets whether or not this obstacle has "sticky" edges. /// /// /// If an obstacle has sticky edges, than any obstacle that is snapped on /// to it will move with this obstacle. /// public bool StickyEdges { get { return this.stickyEdges; } } /// /// Gets how close another obstacle must be to snap to this one, in pixels /// public int SnapProximity { get { return this.snapProximity; } } /// /// Gets how close another obstacle will be parked when it snaps to this one, in pixels. /// public int SnapDistance { get { return this.snapDistance; } } public bool Enabled { get { return this.enabled; } set { this.enabled = value; } } public bool EnableSave { get { return this.enableSave; } set { this.enableSave = value; } } /// /// Raised before the Bounds is changed. /// /// /// The Data property of the event args is the value that Bounds is being set to. /// public event EventHandler> BoundsChanging; protected virtual void OnBoundsChanging() { if (BoundsChanging != null) { BoundsChanging(this, new EventArgs(this.Bounds)); } } /// /// Raised after the Bounds is changed. /// /// /// The Data property of the event args is the value that Bounds was just changed from. /// public event EventHandler> BoundsChanged; protected virtual void OnBoundsChanged() { if (BoundsChanged != null) { BoundsChanged(this, new EventArgs(this.previousBounds)); } } internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges) : this(name, bounds, snapRegion, stickyEdges, DefaultSnapProximity, DefaultSnapDistance) { } internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance) { this.name = name; this.bounds = bounds; this.previousBounds = bounds; this.snapRegion = snapRegion; this.stickyEdges = stickyEdges; this.snapProximity = snapProximity; this.snapDistance = snapDistance; this.enabled = true; this.enableSave = true; } } }