123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- 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;
- }
- }
- /// <summary>
- /// Gets the bounds of this snap obstacle, defined in coordinates relative to its container.
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// Gets whether or not this obstacle has "sticky" edges.
- /// </summary>
- /// <remarks>
- /// If an obstacle has sticky edges, than any obstacle that is snapped on
- /// to it will move with this obstacle.
- /// </remarks>
- public bool StickyEdges
- {
- get
- {
- return this.stickyEdges;
- }
- }
- /// <summary>
- /// Gets how close another obstacle must be to snap to this one, in pixels
- /// </summary>
- public int SnapProximity
- {
- get
- {
- return this.snapProximity;
- }
- }
- /// <summary>
- /// Gets how close another obstacle will be parked when it snaps to this one, in pixels.
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// Raised before the Bounds is changed.
- /// </summary>
- /// <remarks>
- /// The Data property of the event args is the value that Bounds is being set to.
- /// </remarks>
- public event EventHandler<EventArgs<Rectangle>> BoundsChanging;
- protected virtual void OnBoundsChanging()
- {
- if (BoundsChanging != null)
- {
- BoundsChanging(this, new EventArgs<Rectangle>(this.Bounds));
- }
- }
- /// <summary>
- /// Raised after the Bounds is changed.
- /// </summary>
- /// <remarks>
- /// The Data property of the event args is the value that Bounds was just changed from.
- /// </remarks>
- public event EventHandler<EventArgs<Rectangle>> BoundsChanged;
- protected virtual void OnBoundsChanged()
- {
- if (BoundsChanged != null)
- {
- BoundsChanged(this, new EventArgs<Rectangle>(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;
- }
- }
- }
|