aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BrushPicker/Implementation/GradientStopSlider.cs
blob: 7105944159f9596fca852b34e0cccbd4f391f0e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*****************   NCore Softwares Pvt. Ltd., India   **************************

   ColorBox

   Copyright (C) 2013 NCore Softwares Pvt. Ltd.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://colorbox.codeplex.com/license

***********************************************************************************/

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Linq;
using System.Collections;

namespace Tango.BrushPicker
{
    class GradientStopSlider : Slider
    {
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);

            if (this.ColorBox != null)
            {
                this.ColorBox._BrushSetInternally = true;
                this.ColorBox._UpdateBrush = false;        

                this.ColorBox.SelectedGradient = this.SelectedGradient;
                this.ColorBox.Color = this.SelectedGradient.Color;
                
                this.ColorBox._UpdateBrush = true;
            }
        }

        protected override void OnValueChanged(double oldValue, double newValue)
        {
            if (ColorBox != null && ColorBox.Gradients != null)
            {
                if (ColorBox.Gradients.FirstOrDefault() == SelectedGradient)
                {
                    Value = 0;
                    return;
                }
                else if (ColorBox.Gradients.LastOrDefault() == SelectedGradient)
                {
                    Value = 1;
                    return;
                }
            }

            base.OnValueChanged(oldValue, newValue);

            if (this.ColorBox != null)
            {
                //this.ColorBox._HSBSetInternally = true;
                //this.ColorBox._RGBSetInternally = true;
                this.ColorBox._BrushSetInternally = true;
                this.ColorBox.SetBrush();
                this.ColorBox._HSBSetInternally = false;
                //this.ColorBox._RGBSetInternally = false;
                //this.ColorBox._BrushSetInternally = false;
            }            
        }

        public BrushPicker ColorBox
        {
            get { return (BrushPicker)GetValue(ColorBoxProperty); }
            set { SetValue(ColorBoxProperty, value); }
        }
        public static readonly DependencyProperty ColorBoxProperty =
            DependencyProperty.Register("ColorBox", typeof(BrushPicker), typeof(GradientStopSlider));

        public GradientStop SelectedGradient
        {
            get { return (GradientStop)GetValue(SelectedGradientProperty); }
            set { SetValue(SelectedGradientProperty, value); }
        }
        public static readonly DependencyProperty SelectedGradientProperty =
            DependencyProperty.Register("SelectedGradient", typeof(GradientStop), typeof(GradientStopSlider));
    }
}