DoubleVectorPanAndSliderPropertyControl.cs :  » GUI » Paint.net » PaintDotNet » IndirectUI » 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 » IndirectUI » DoubleVectorPanAndSliderPropertyControl.cs
/////////////////////////////////////////////////////////////////////////////////
// Paint.NET                                                                   //
// Copyright (C) Rick Brewster, Tom Jackson, and past contributors.            //
// Portions Copyright (C) Microsoft Corporation. All Rights Reserved.          //
// See src/Resources/Files/License.txt for full licensing and attribution      //
// details.                                                                    //
// .                                                                           //
/////////////////////////////////////////////////////////////////////////////////

using PaintDotNet;
using PaintDotNet.PropertySystem;
using PaintDotNet.SystemLayer;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace PaintDotNet.IndirectUI{
    [PropertyControlInfo(typeof(DoubleVectorProperty), PropertyControlType.PanAndSlider, IsDefault = true)]
    internal sealed class DoubleVectorPanAndSliderPropertyControl
         : PropertyControl<Pair<double, double>, VectorProperty<double>>
    {
        private HeaderLabel header;
        private PaintDotNet.Core.PanControl panControl;
        private DoubleVectorSliderPropertyControl sliders;
        private Label textDescription;

        [PropertyControlProperty(DefaultValue = (object)true)]
        public bool ShowResetButton
        {
            get
            {
                return this.sliders.ShowResetButton;
            }

            set
            {
                this.sliders.ShowResetButton = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)2)]
        public int DecimalPlaces
        {
            get
            {
                return this.sliders.DecimalPlaces;
            }

            set
            {
                this.sliders.DecimalPlaces = value;
            }
        }


        [PropertyControlProperty(DefaultValue = (object)false)]
        public bool UseExponentialScale
        {
            get
            {
                return this.sliders.UseExponentialScale;
            }

            set
            {
                this.sliders.UseExponentialScale = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)1.0)]
        public double SliderSmallChangeX
        {
            get
            {
                return this.sliders.SliderSmallChangeX;
            }

            set
            {
                this.sliders.SliderSmallChangeX = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)5.0)]
        public double SliderLargeChangeX
        {
            get
            {
                return this.sliders.SliderLargeChangeX;
            }

            set
            {
                this.sliders.SliderLargeChangeX = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)1.0)]
        public double UpDownIncrementX
        {
            get
            {
                return this.sliders.UpDownIncrementX;
            }

            set
            {
                this.sliders.UpDownIncrementX = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)1.0)]
        public double SliderSmallChangeY
        {
            get
            {
                return this.sliders.SliderSmallChangeY;
            }

            set
            {
                this.sliders.SliderSmallChangeY = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)5.0)]
        public double SliderLargeChangeY
        {
            get
            {
                return this.sliders.SliderLargeChangeY;
            }

            set
            {
                this.sliders.SliderLargeChangeY = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)1.0)]
        public double UpDownIncrementY
        {
            get
            {
                return this.sliders.UpDownIncrementY;
            }

            set
            {
                this.sliders.UpDownIncrementY = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)false)]
        public bool SliderShowTickMarksX
        {
            get
            {
                return this.sliders.SliderShowTickMarksX;
            }

            set
            {
                this.sliders.SliderShowTickMarksX = value;
            }
        }

        [PropertyControlProperty(DefaultValue = (object)false)]
        public bool SliderShowTickMarksY
        {
            get
            {
                return this.sliders.SliderShowTickMarksY;
            }

            set
            {
                this.sliders.SliderShowTickMarksY = value;
            }
        }

        [PropertyControlProperty(DefaultValue = null)]
        public ImageResource StaticImageUnderlay
        {
            get
            {
                return this.panControl.StaticImageUnderlay;
            }

            set
            {
                this.panControl.StaticImageUnderlay = value;

                if (value == null)
                {
                    this.panControl.BorderStyle = BorderStyle.FixedSingle;
                }
                else
                {
                    this.panControl.BorderStyle = BorderStyle.None;
                }
            }
        }

        protected override void OnPropertyReadOnlyChanged()
        {
            this.panControl.Enabled = !this.Property.ReadOnly;
            this.textDescription.Enabled = !this.Property.ReadOnly;
        }

        protected override void OnPropertyValueChanged()
        {
            PointF newPos = new PointF((float)this.Property.ValueX, (float)this.Property.ValueY);
            this.panControl.Position = newPos;
        }

        private void PanControl_PositionChanged(object sender, EventArgs e)
        {
            PointF pos = this.panControl.Position;

            PointF clampedPos = new PointF(
                Utility.Clamp(pos.X, (float)this.Property.MinValueX, (float)this.Property.MaxValueX),
                Utility.Clamp(pos.Y, (float)this.Property.MinValueY, (float)this.Property.MaxValueY));

            this.panControl.Position = clampedPos;

            Pair<double, double> pairValue = Pair.Create((double)clampedPos.X, (double)clampedPos.Y);

            this.Property.Value = pairValue;
        }

        protected override void OnDisplayNameChanged()
        {
            this.header.Text = this.DisplayName;
            base.OnDisplayNameChanged();
        }

        protected override void OnDescriptionChanged()
        {
            this.textDescription.Text = this.Description;
            base.OnDescriptionChanged();
        }

        protected override void OnLayout(LayoutEventArgs levent)
        {
            int vMargin = UI.ScaleHeight(4);
            int hMargin = UI.ScaleWidth(4);

            this.header.Location = new Point(0, 0);
            this.header.Size = 
                string.IsNullOrEmpty(DisplayName) ? 
                    new Size(ClientSize.Width, 0) : 
                    this.header.GetPreferredSize(new Size(ClientSize.Width, 0));

            int panControlLength = Math.Min(this.panControl.Width, this.panControl.Height);
            int tries = 2;

            while (tries > 0)
            {
                --tries;

                this.panControl.Location = new Point(0, this.header.Bottom + vMargin);
                this.panControl.Size = new Size(panControlLength, panControlLength);
                this.panControl.PerformLayout();

                this.sliders.Location = new Point(this.panControl.Right + hMargin, this.header.Bottom + vMargin);
                this.sliders.Width = ClientSize.Width - this.sliders.Left;
                this.sliders.PerformLayout();

                // put some padding to ensure the thumbnail is a little larger
                int sliderBottomPlusReserve = this.sliders.Bottom + UI.ScaleHeight(20 + (SliderShowTickMarksX ? 0 : 4) + (SliderShowTickMarksY ? 0 : 4));

                this.textDescription.Location = new Point(
                    0,
                    (string.IsNullOrEmpty(this.Description) ? 0 : vMargin) + 
                        Math.Max(this.panControl.Bottom, /*this.sliders.Bottom*/ sliderBottomPlusReserve));

                this.textDescription.Width = ClientSize.Width;
                this.textDescription.Height = string.IsNullOrEmpty(this.Description) ? 0 :
                    this.textDescription.GetPreferredSize(new Size(this.textDescription.Width, 1)).Height;

                ClientSize = new Size(ClientSize.Width, this.textDescription.Bottom);

                panControlLength = (this.textDescription.Top - this.panControl.Top - vMargin);
                panControlLength |= 1;
            }

            base.OnLayout(levent);
        }

        public DoubleVectorPanAndSliderPropertyControl(PropertyControlInfo propInfo)
            : base(propInfo)
        {
            SuspendLayout();

            this.header = new HeaderLabel();
            this.header.Name = "header";
            this.header.RightMargin = 0;
            this.header.Text = this.DisplayName;

            this.panControl = new PaintDotNet.Core.PanControl();
            this.panControl.Name = "panControl";
            this.panControl.StaticImageUnderlay = (ImageResource)propInfo.ControlProperties[ControlInfoPropertyNames.StaticImageUnderlay].Value;
            this.panControl.PositionChanged += new EventHandler(PanControl_PositionChanged);
            this.panControl.Size = new Size(1, 1);

            this.sliders = new DoubleVectorSliderPropertyControl(propInfo);
            this.sliders.Name = "sliders";
            this.sliders.DisplayName = "";
            this.sliders.Description = "";

            this.textDescription = new Label();
            this.textDescription.Name = "textDescription";
            this.textDescription.Text = Description;

            this.Controls.AddRange(
                new Control[]
                {
                    this.header,
                    this.panControl,
                    this.sliders,
                    this.textDescription
                });

            ResumeLayout(false);
        }

        protected override bool OnFirstSelect()
        {
            return ((IFirstSelection)this.sliders).FirstSelect();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.