6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Mathematics;
8 using SiliconStudio.Paradox.Input;
9 using SiliconStudio.Paradox.UI.Events;
11 namespace SiliconStudio.
Paradox.UI.Controls
20 private bool shouldSnapToTicks;
81 var slider = (
Slider)propertyowner;
83 slider.InvalidateMeasure();
85 if (propertyoldvalue != null)
86 propertyoldvalue.IdealSizeChanged -= slider.OnIdealSizeChanged;
88 if(slider.TrackBackgroundImage != null)
89 slider.TrackBackgroundImage.IdealSizeChanged += slider.OnIdealSizeChanged;
92 private void OnIdealSizeChanged(
object sender,
EventArgs e)
97 private static void ValidateExtremum(
object propertyowner,
PropertyKey<float> propertykey,
float propertyoldvalue)
99 var slider = (Slider)propertyowner;
101 if (slider.Maximum < slider.Minimum)
103 slider.DependencyProperties.Set(propertykey, propertyoldvalue);
106 throw new ArgumentOutOfRangeException(
"Maximum should be greater or equal than Minimum.");
110 private static void TickFrequencyInvalidated(
object propertyowner,
PropertyKey<float> propertykey,
float propertyoldvalue)
112 var slider = (Slider)propertyowner;
114 if (slider.TickFrequency < 1)
115 slider.TickFrequency = 1;
117 slider.Value = slider.value;
122 EventManager.RegisterClassHandler(typeof(Slider), ValueChangedEvent, ValueChangedClassHandler);
130 CanBeHitByUser =
true;
133 DrawLayerNumber += 4;
139 public UIImage TrackBackgroundImage
141 get {
return DependencyProperties.Get(TrackBackgroundImagePropertyKey); }
142 set { DependencyProperties.Set(TrackBackgroundImagePropertyKey, value); }
148 public UIImage TrackForegroundImage
150 get {
return DependencyProperties.Get(TrackForegroundImagePropertyKey); }
151 set { DependencyProperties.Set(TrackForegroundImagePropertyKey, value); }
159 get {
return DependencyProperties.Get(ThumbImagePropertyKey); }
160 set { DependencyProperties.Set(ThumbImagePropertyKey, value); }
166 public UIImage MouseOverThumbImage
168 get {
return DependencyProperties.Get(MouseOverThumbImagePropertyKey); }
169 set { DependencyProperties.Set(MouseOverThumbImagePropertyKey, value); }
177 get {
return DependencyProperties.Get(TickImagePropertyKey); }
178 set { DependencyProperties.Set(TickImagePropertyKey, value); }
186 get {
return DependencyProperties.Get(MinimumPropertyKey); }
187 set { DependencyProperties.Set(MinimumPropertyKey, value); }
195 get {
return DependencyProperties.Get(MaximumPropertyKey); }
196 set { DependencyProperties.Set(MaximumPropertyKey, value); }
204 get {
return DependencyProperties.Get(StepPropertyKey); }
205 set { DependencyProperties.Set(StepPropertyKey, value); }
214 get {
return value; }
217 var oldValue = Value;
219 this.value = Math.Min(Maximum, Math.Max(Minimum, value));
220 if(ShouldSnapToTicks)
221 this.value = CalculateClosestTick(this.value);
223 if(Math.Abs(oldValue -
this.value) > MathUtil.ZeroTolerance)
232 public float TickFrequency
234 get {
return DependencyProperties.Get(TickFrequencyPropertyKey); }
235 set { DependencyProperties.Set(TickFrequencyPropertyKey, value); }
241 public float TickOffset
243 get {
return DependencyProperties.Get(TickOffsetPropertyKey); }
244 set { DependencyProperties.Set(TickOffsetPropertyKey, value); }
250 public Vector2 TrackStartingOffsets
252 get {
return DependencyProperties.Get(TrackStartingOffsetsrPropertyKey); }
253 set { DependencyProperties.Set(TrackStartingOffsetsrPropertyKey, value); }
259 public bool IsDirectionReversed {
get; set; }
264 public bool AreTicksDisplayed {
get; set; }
269 public bool ShouldSnapToTicks
271 get {
return shouldSnapToTicks; }
274 shouldSnapToTicks = value;
284 get {
return orientation; }
298 Value = CalculateClosestTick(Value);
308 var absoluteValue = rawValue - Minimum;
309 var step = (Maximum - Minimum) / TickFrequency;
310 var times = (float)Math.Round(absoluteValue / step);
320 Value += CalculateIncreamentValue();
329 Value -= CalculateIncreamentValue();
332 private float CalculateIncreamentValue()
334 return shouldSnapToTicks? Math.Max(Step, (Maximum - Minimum) / TickFrequency): Step;
339 var image = TrackBackgroundImage;
341 return base.MeasureOverride(availableSizeWithoutMargins);
343 var idealSize = image.ImageIdealSize.Y;
344 var desiredSize =
new Vector3(idealSize, idealSize, 0);
354 public event EventHandler<RoutedEventArgs> ValueChanged
356 add { AddHandler(ValueChangedEvent, value); }
357 remove { RemoveHandler(ValueChangedEvent, value); }
365 RoutingStrategy.Bubble,
378 private static void ValueChangedClassHandler(
object sender,
RoutedEventArgs args)
380 var slider = (
Slider)sender;
382 slider.OnValueChanged(args);
387 base.OnTouchDown(args);
394 base.OnTouchMove(args);
399 internal override void OnKeyDown(KeyEventArgs args)
401 base.OnKeyDown(args);
403 if(args.Key ==
Keys.Right)
405 if(args.Key ==
Keys.Left)
416 var offsets = TrackStartingOffsets;
417 var elementSize = RenderSize[axis];
418 var touchPosition = touchPostionWorld[axis] - WorldMatrixInternal[12 + axis] + elementSize/2;
419 var ratio = (touchPosition - offsets.X) / (elementSize - offsets.X - offsets.Y);
420 Value = (
Orientation == Orientation.Vertical ^ IsDirectionReversed) ? 1 - ratio : ratio;
Provides a base class for all the User Interface elements in Paradox applications.
SiliconStudio.Paradox.Games.Mathematics.Vector2 Vector2
override void OnTouchMove(TouchEventArgs args)
The class handler of the event TouchMove. This method can be overridden in inherited classes to perfo...
Represents a two dimensional mathematical vector.
Slider()
Create a new instance of slider.
void Increase()
Increase the Value by Step.
VerticalAlignment
Describes how a child element is vertically positioned or stretched within a parent's layout slot...
Orientation
Defines the different orientations that a control or layout can have.
void SnapToClosestTick()
Snap the current Value to the closest tick.
Contains state information and event data associated with a routed event.
Represents a three dimensional mathematical vector.
HorizontalAlignment
Indicates where an element should be displayed on the horizontal axis relative to the allocated layou...
override void OnTouchDown(TouchEventArgs args)
The class handler of the event TouchDown. This method can be overridden in inherited classes to perfo...
Vector3 WorldPosition
Gets the position of the touch in the UI virtual world space.
Represents a slider element.
Provides data for touch input events.
virtual void OnValueChanged(RoutedEventArgs args)
The class handler of the event ValueChanged. This method can be overridden in inherited classes to pe...
void SetValueFromTouchPosition(Vector3 touchPostionWorld)
Set Value from the world position of a touch event.
Represents and identifies a routed event and declares its characteristics.
SiliconStudio.Core.Mathematics.Vector3 Vector3
Class holding all the data required to define an UI image.
float CalculateClosestTick(float rawValue)
Calculate the value of the closest tick to the provided value.
void Decrease()
Decrease the Value by Step.
Android.Widget.Orientation Orientation
A class that represents a tag propety.
override Vector3 MeasureOverride(Vector3 availableSizeWithoutMargins)
When overridden in a derived class, measures the size in layout required for possible child elements ...