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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
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;
namespace Tango.Visuals
{
/// <summary>
/// Interaction logic for Fader.xaml
/// </summary>
public partial class Fader : UserControl
{
public Fader()
{
InitializeComponent();
this.Loaded += Fader_Loaded;
this.SizeChanged += Fader_SizeChanged;
}
private void Fader_SizeChanged(object sender, SizeChangedEventArgs e)
{
SetSize();
}
private void SetSize()
{
border.Margin = new Thickness(0, gridThumb.ActualHeight / 2, 0, gridThumb.ActualHeight / 2);
}
private void Fader_Loaded(object sender, RoutedEventArgs e)
{
SetSize();
OnValueChanged();
}
public Brush TrackBrush
{
get { return (Brush)GetValue(TrackBrushProperty); }
set { SetValue(TrackBrushProperty, value); }
}
public static readonly DependencyProperty TrackBrushProperty =
DependencyProperty.Register("TrackBrush", typeof(Brush), typeof(Fader), new PropertyMetadata(null));
public Brush TrackHighlighBrush
{
get { return (Brush)GetValue(TrackHighlighBrushProperty); }
set { SetValue(TrackHighlighBrushProperty, value); }
}
public static readonly DependencyProperty TrackHighlighBrushProperty =
DependencyProperty.Register("TrackHighlighBrush", typeof(Brush), typeof(Fader), new PropertyMetadata(null));
public bool HighlightTrack
{
get { return (bool)GetValue(HighlightTrackProperty); }
set { SetValue(HighlightTrackProperty, value); }
}
public static readonly DependencyProperty HighlightTrackProperty =
DependencyProperty.Register("HighlightTrack", typeof(bool), typeof(Fader), new PropertyMetadata(false));
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(double), typeof(Fader), new PropertyMetadata(0.0, (d, e) => (d as Fader).OnValueChanged()));
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(double), typeof(Fader), new PropertyMetadata(100.0, (d, e) => (d as Fader).OnValueChanged()));
public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(Fader), new FrameworkPropertyMetadata(0.0, (d, e) => (d as Fader).OnValueChanged(), (d, baseValue) => (d as Fader).OnCoerceValue((double)baseValue)) { BindsTwoWayByDefault = true });
public bool SnapToValues
{
get { return (bool)GetValue(SnapToValuesProperty); }
set { SetValue(SnapToValuesProperty, value); }
}
public static readonly DependencyProperty SnapToValuesProperty =
DependencyProperty.Register("SnapToValues", typeof(bool), typeof(Fader), new PropertyMetadata(false));
public int SnapPercision
{
get { return (int)GetValue(SnapPercisionProperty); }
set { SetValue(SnapPercisionProperty, value); }
}
public static readonly DependencyProperty SnapPercisionProperty =
DependencyProperty.Register("SnapPercision", typeof(int), typeof(Fader), new PropertyMetadata(1));
public int Ticks
{
get { return (int)GetValue(TicksProperty); }
set { SetValue(TicksProperty, value); }
}
public static readonly DependencyProperty TicksProperty =
DependencyProperty.Register("Ticks", typeof(int), typeof(Fader), new PropertyMetadata(50));
public int? BigTicksInterval
{
get { return (int?)GetValue(BigTicksIntervalProperty); }
set { SetValue(BigTicksIntervalProperty, value); }
}
public static readonly DependencyProperty BigTicksIntervalProperty =
DependencyProperty.Register("BigTicksInterval", typeof(int?), typeof(Fader), new PropertyMetadata(5));
public Brush TicksBrush
{
get { return (Brush)GetValue(TicksBrushProperty); }
set { SetValue(TicksBrushProperty, value); }
}
public static readonly DependencyProperty TicksBrushProperty =
DependencyProperty.Register("TicksBrush", typeof(Brush), typeof(Fader), new PropertyMetadata(null));
public Brush BigTicksBrush
{
get { return (Brush)GetValue(BigTicksBrushProperty); }
set { SetValue(BigTicksBrushProperty, value); }
}
public static readonly DependencyProperty BigTicksBrushProperty =
DependencyProperty.Register("BigTicksBrush", typeof(Brush), typeof(Fader), new PropertyMetadata(null));
public double FaderWidth
{
get { return (double)GetValue(FaderWidthProperty); }
set { SetValue(FaderWidthProperty, value); }
}
public static readonly DependencyProperty FaderWidthProperty =
DependencyProperty.Register("FaderWidth", typeof(double), typeof(Fader), new PropertyMetadata(40.0));
public double TrackWidth
{
get { return (double)GetValue(TrackWidthProperty); }
set { SetValue(TrackWidthProperty, value); }
}
public static readonly DependencyProperty TrackWidthProperty =
DependencyProperty.Register("TrackWidth", typeof(double), typeof(Fader), new PropertyMetadata(10.0));
public bool ShowTicks
{
get { return (bool)GetValue(ShowTicksProperty); }
set { SetValue(ShowTicksProperty, value); }
}
public static readonly DependencyProperty ShowTicksProperty =
DependencyProperty.Register("ShowTicks", typeof(bool), typeof(Fader), new PropertyMetadata(true));
public Color? FaderColor
{
get { return (Color?)GetValue(FaderColorProperty); }
set { SetValue(FaderColorProperty, value); }
}
public static readonly DependencyProperty FaderColorProperty =
DependencyProperty.Register("FaderColor", typeof(Color?), typeof(Fader), new PropertyMetadata(null));
public double TicksWidth
{
get { return (double)GetValue(TicksWidthProperty); }
set { SetValue(TicksWidthProperty, value); }
}
public static readonly DependencyProperty TicksWidthProperty =
DependencyProperty.Register("TicksWidth", typeof(double), typeof(Fader), new PropertyMetadata(8.0));
public double BigTicksWidth
{
get { return (double)GetValue(BigTicksWidthProperty); }
set { SetValue(BigTicksWidthProperty, value); }
}
public static readonly DependencyProperty BigTicksWidthProperty =
DependencyProperty.Register("BigTicksWidth", typeof(double), typeof(Fader), new PropertyMetadata(20.0));
public Brush FaderLightBrush
{
get { return (Brush)GetValue(FaderLightBrushProperty); }
set { SetValue(FaderLightBrushProperty, value); }
}
public static readonly DependencyProperty FaderLightBrushProperty =
DependencyProperty.Register("FaderLightBrush", typeof(Brush), typeof(Fader), new PropertyMetadata(null));
public double Change
{
get { return (double)GetValue(ChangeProperty); }
set { SetValue(ChangeProperty, value); }
}
public static readonly DependencyProperty ChangeProperty =
DependencyProperty.Register("Change", typeof(double), typeof(Fader), new PropertyMetadata(0.01));
internal bool IsKeyDown
{
get { return (bool)GetValue(IsKeyDownProperty); }
set { SetValue(IsKeyDownProperty, value); }
}
internal static readonly DependencyProperty IsKeyDownProperty =
DependencyProperty.Register("IsKeyDown", typeof(bool), typeof(Fader), new PropertyMetadata(false));
private object OnCoerceValue(double value)
{
if (value > Maximum) return Maximum;
if (value < Minimum) return Minimum;
return SnapToValues ? Math.Round(value, SnapPercision) : value;
}
private void OnValueChanged()
{
double percentage = (Value - Minimum) / (Maximum - Minimum);
double faderHeight = gridThumb.ActualHeight;
faderTranslate.Y = -((this.ActualHeight - faderHeight) * percentage);
borderHighLight.Height = Math.Abs(faderTranslate.Y);
}
private void OnThumbDrag(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
double value = (faderTranslate.Y + e.VerticalChange);
double faderHeight = gridThumb.ActualHeight;
if (value > 0) value = 0;
if (value < -(this.ActualHeight - faderHeight))
{
value = -(this.ActualHeight - faderHeight);
}
faderTranslate.Y = value;
borderHighLight.Height = Math.Abs(faderTranslate.Y);
double percentage = Math.Abs(value / (this.ActualHeight - faderHeight));
Value = (Minimum + (Maximum - Minimum) * percentage);
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
{
Value -= Change;
}
else if (e.Key == Key.Up)
{
Value += Change;
}
Focus();
IsKeyDown = true;
e.Handled = true;
}
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
Focus();
}
private void OnKeyUp(object sender, KeyEventArgs e)
{
IsKeyDown = false;
}
}
}
|