aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.IDE/Images/NewFileCollection_16x.png
blob: bc5cef8284c18f29239d85481d544ecc0a6a842f (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 10 00 00 00 10 08 06 00 00 00 1f f3 ff .PNG........IHDR................
0020 61 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 00 09 70 48 59 73 00 00 0e c2 00 00 0e a....gAMA......a.....pHYs.......
0040 c2 01 15 28 4a 80 00 00 00 18 74 45 58 74 53 6f 66 74 77 61 72 65 00 70 61 69 6e 74 2e 6e 65 74 ...(J.....tEXtSoftware.paint.net
0060 20 34 2e 31 2e 36 fd 4e 09 e8 00 00 00 89 49 44 41 54 38 4f ad 90 d1 0d 80 20 0c 44 9d c3 29 9c .4.1.6.N......IDAT8O.......D..).
0080 cf c4 e1 74 21 ff f8 ad 1c e6 6a 69 04 c1 d0 e4 49 2d bd 67 e2 64 4b 44 94 96 d2 3d 1b 3c b6 39 ...t!.....ji....I-.g.dKD...=.<.9
00a0 1e cf fb 1b 21 84 85 b9 54 68 18 f4 e7 ba 8b 78 a2 e0 84 04 f7 99 19 21 62 e7 c4 4a 38 4b 0f 1b ....!...Th.....x.......!b..J8K..
00c0 8c 66 ed 01 17 41 51 40 4a 41 4f 26 e8 fd 07 9c e1 04 2a 20 a5 af 7b 09 51 81 bf f0 74 09 6a b2 .f...AQ@JAO&......*...{.Q...t.j.
00e0 61 02 e6 b4 19 22 e0 e5 2f 81 a5 5b 60 8b 4b 35 3e 05 2d dc bb 32 5d 2a 18 8e 90 87 65 b7 00 00 a...."../..[`.K5>.-..2]*....e...
0100 00 00 00 49 45 4e 44 ae 42 60 82 ...IEND.B`.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.SharedUI;

namespace Tango.SharedUI.Editors
{
    /// <summary>
    /// Represents a simple numeric up down editor.
    /// </summary>
    public partial class ParameterItemNumericUpDownEditor : ParameterItemEditor
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterItemNumericUpDownEditor"/> class.
        /// </summary>
        public ParameterItemNumericUpDownEditor()
        {
            InitializeComponent();

            this.Loaded += ParameterItemNumericUpDownEditor_Loaded;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        public double Value
        {
            get { return (double)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(double), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata(0.0, null, (d, value) => { return (d as ParameterItemNumericUpDownEditor).OnCoerceValue((double)value); }));

        /// <summary>
        /// Gets or sets the minimum value.
        /// </summary>
        public double Minimum
        {
            get { return (double)GetValue(MinimumProperty); }
            set { SetValue(MinimumProperty, value); }
        }
        public static readonly DependencyProperty MinimumProperty =
            DependencyProperty.Register("Minimum", typeof(double), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata(0.0));

        /// <summary>
        /// Gets or sets the maximum value.
        /// </summary>
        public double Maximum
        {
            get { return (double)GetValue(MaximumProperty); }
            set { SetValue(MaximumProperty, value); }
        }
        public static readonly DependencyProperty MaximumProperty =
            DependencyProperty.Register("Maximum", typeof(double), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata(100.0));

        /// <summary>
        /// Gets or sets the tick frequency for the up/down buttons.
        /// </summary>
        public double Tick
        {
            get { return (double)GetValue(TickProperty); }
            set { SetValue(TickProperty, value); }
        }
        public static readonly DependencyProperty TickProperty =
            DependencyProperty.Register("Tick", typeof(double), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata(1.0));

        /// <summary>
        /// Gets or sets the value display format.
        /// </summary>
        public String Format
        {
            get { return (String)GetValue(FormatProperty); }
            set { SetValue(FormatProperty, value); }
        }
        public static readonly DependencyProperty FormatProperty =
            DependencyProperty.Register("Format", typeof(String), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata("0.0"));

        /// <summary>
        /// Gets or sets a value indicating whether the value is editable through keyboard.
        /// </summary>
        public bool IsReadOnly
        {
            get { return (bool)GetValue(IsReadOnlyProperty); }
            set { SetValue(IsReadOnlyProperty, value); }
        }
        public static readonly DependencyProperty IsReadOnlyProperty =
            DependencyProperty.Register("IsReadOnly", typeof(bool), typeof(ParameterItemNumericUpDownEditor), new PropertyMetadata(false));

        #endregion

        #region Virtual Methods

        /// <summary>
        /// Invoked before the value has changed.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        protected virtual object OnCoerceValue(double value)
        {
            if (value > Maximum) return Maximum;
            if (value < Minimum) return Minimum;

            return value;
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Handles the Click event of the btnUp control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnUp_Click(object sender, RoutedEventArgs e)
        {
            Value += Tick;
        }

        /// <summary>
        /// Handles the Click event of the btnDown control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnDown_Click(object sender, RoutedEventArgs e)
        {
            Value -= Tick;
        }

        /// <summary>
        /// Handles the KeyDown event of the txtValue control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
        private void txtValue_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter || e.Key == Key.Escape)
            {
                BindingOperations.GetBindingExpressionBase((TextBox)txtValue, TextBox.TextProperty).UpdateSource();
            }
        }

        /// <summary>
        /// Handles the Loaded event of the ParameterItemNumericUpDownEditor control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void ParameterItemNumericUpDownEditor_Loaded(object sender, RoutedEventArgs e)
        {
            if (ParameterItem != null)
            {
                Minimum = Convert.ToDouble(ParameterItem.Minimum);
                Maximum = Convert.ToDouble(ParameterItem.Maximum);
                this.Bind(ValueProperty, ParameterItem, Tango.Core.ParameterItem.ValueProperty, BindingMode.TwoWay);
            }
        }

        #endregion
    }
}