SnapObstacle.cs :  » GUI » Paint.net » PaintDotNet » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » Paint.net 
Paint.net » PaintDotNet » SnapObstacle.cs
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) dotPDN LLC, Rick Brewster, Tom Jackson, and contributors.     //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See src/Resources/Files/License.txt for full licensing and attribution      //
// details.                                                                    //
// .                                                                           //
/////////////////////////////////////////////////////////////////////////////////

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

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;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.