[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Wearable / src / public / CircularSlider.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using Tizen.NUI.BaseComponents;
19 using Tizen.NUI.Binding;
20 using Tizen.NUI.Components;
21 using System.ComponentModel;
22
23 namespace Tizen.NUI.Wearable
24 {
25     /// <summary>
26     /// Value Changed event data.
27     /// </summary>
28     [Obsolete("This has been deprecated in API12")]
29     [EditorBrowsable(EditorBrowsableState.Never)]
30     public class CircularSliderValueChangedEventArgs : EventArgs
31     {
32         private float currentValue = 0.0f;
33
34         /// <summary>
35         /// Current value
36         /// </summary>
37         [Obsolete("This has been deprecated in API12")]
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public float CurrentValue
40         {
41             get { return currentValue; }
42             set { currentValue = value; }
43         }
44     }
45
46     /// <summary>
47     /// The CircularSlider class of Wearable is used to let users select a value from a continuous or discrete range of values by moving the slider thumb.
48     /// CircularSlider shows the current value with the length of the line.
49     /// </summary>
50     [Obsolete("This has been deprecated in API12")]
51     [EditorBrowsable(EditorBrowsableState.Never)]
52     public class CircularSlider : Control
53     {
54         #region Fields
55
56         /// <summary>Bindable property of Thickness</summary>
57         [EditorBrowsable(EditorBrowsableState.Never)]
58         public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(nameof(Thickness), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
59         {
60             var instance = ((CircularSlider)bindable);
61             instance.CurrentStyle.Thickness = (float)newValue;
62             instance.UpdateVisualThickness((float)newValue);
63         },
64         defaultValueCreator: (bindable) =>
65         {
66             return ((CircularSlider)bindable).CurrentStyle.Thickness;
67         });
68
69         /// <summary>Bindable property of MaxValue</summary>
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public static readonly BindableProperty MaxValueProperty = BindableProperty.Create(nameof(MaxValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
72         {
73             var instance = (CircularSlider)bindable;
74             if (newValue != null)
75             {
76                 instance.maxValue = (float)newValue;
77                 instance.UpdateValue();
78             }
79         },
80         defaultValueCreator: (bindable) =>
81         {
82             var instance = (CircularSlider)bindable;
83             return instance.maxValue;
84         });
85
86         /// <summary>Bindable property of MinValue</summary>
87         [EditorBrowsable(EditorBrowsableState.Never)]
88         public static readonly BindableProperty MinValueProperty = BindableProperty.Create(nameof(MinValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
89         {
90             var instance = (CircularSlider)bindable;
91             if (newValue != null)
92             {
93                 instance.minValue = (float)newValue;
94                 instance.UpdateValue();
95             }
96         },
97         defaultValueCreator: (bindable) =>
98         {
99             var instance = (CircularSlider)bindable;
100             return instance.minValue;
101         });
102
103         /// <summary>Bindable property of CurrentValue</summary>
104         [EditorBrowsable(EditorBrowsableState.Never)]
105         public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(CircularSlider), default(float), propertyChanged: (bindable, oldValue, newValue) =>
106         {
107             var instance = (CircularSlider)bindable;
108             if (newValue != null)
109             {
110                 if ((float)newValue > instance.maxValue || (float)newValue < instance.minValue)
111                 {
112                     return;
113                 }
114                 instance.currentValue = (float)newValue;
115                 instance.UpdateValue();
116             }
117         },
118         defaultValueCreator: (bindable) =>
119         {
120             var instance = (CircularSlider)bindable;
121             return instance.currentValue;
122         });
123
124         /// <summary>Bindable property of TrackColor</summary>
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         public static readonly BindableProperty TrackColorProperty = BindableProperty.Create(nameof(TrackColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
127         {
128             var instance = (CircularSlider)bindable;
129             instance.CurrentStyle.TrackColor = (Color)newValue;
130             instance.UpdateTrackVisualColor((Color)newValue);
131         },
132         defaultValueCreator: (bindable) =>
133         {
134             return ((CircularSlider)bindable).CurrentStyle.TrackColor;
135         });
136
137         /// <summary>Bindable property of ProgressColor</summary>
138         [EditorBrowsable(EditorBrowsableState.Never)]
139         public static readonly BindableProperty ProgressColorProperty = BindableProperty.Create(nameof(ProgressColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
140         {
141             var instance = (CircularSlider)bindable;
142             instance.CurrentStyle.ProgressColor = (Color)newValue;
143             instance.UpdateProgressVisualColor((Color)newValue);
144         },
145         defaultValueCreator: (bindable) =>
146         {
147             return ((CircularSlider)bindable).CurrentStyle.ProgressColor;
148         });
149
150         /// <summary>Bindable property of ThumbSize</summary>
151         [EditorBrowsable(EditorBrowsableState.Never)]
152         public static readonly BindableProperty ThumbSizeProperty = BindableProperty.Create(nameof(ThumbSize), typeof(Size), typeof(CircularSlider), new Size(0, 0), propertyChanged: (bindable, oldValue, newValue) =>
153         {
154             var instance = (CircularSlider)bindable;
155             if (newValue != null)
156             {
157                 instance.thumbSize = (Size)newValue;
158                 instance.UpdateThumbVisualSize((Size)newValue);
159             }
160         },
161         defaultValueCreator: (bindable) =>
162         {
163             var instance = (CircularSlider)bindable;
164             return instance.thumbSize;
165         });
166
167         /// <summary>Bindable property of ThumbColor</summary>
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public static readonly BindableProperty ThumbColorProperty = BindableProperty.Create(nameof(ThumbColor), typeof(Color), typeof(CircularSlider), null, propertyChanged: (bindable, oldValue, newValue) =>
170         {
171             var instance = (CircularSlider)bindable;
172             instance.CurrentStyle.ThumbColor = (Color)newValue;
173             instance.UpdateThumbVisualColor((Color)newValue);
174         },
175         defaultValueCreator: (bindable) =>
176         {
177             return ((CircularSlider)bindable).CurrentStyle.ThumbColor;
178         });
179
180         /// <summary>Bindable property of IsEnabled</summary>
181         [EditorBrowsable(EditorBrowsableState.Never)]
182         public new static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(CircularSlider), true, propertyChanged: (bindable, oldValue, newValue) =>
183         {
184             var instance = (CircularSlider)bindable;
185             if (newValue != null)
186             {
187                 instance.privateIsEnabled = (bool)newValue;
188             }
189         },
190         defaultValueCreator: (bindable) =>
191         {
192             var instance = (CircularSlider)bindable;
193             return instance.privateIsEnabled;
194         });
195
196         private const string TrackVisualName = "Track";
197         private const string ProgressVisualName = "Progress";
198         private const string ThumbVisualName = "Thumb";
199         private ArcVisual trackVisual;
200         private ArcVisual progressVisual;
201         private ArcVisual thumbVisual;
202
203         private float maxValue = 100;
204         private float minValue = 0;
205         private float currentValue = 0;
206         private Size thumbSize;
207         private bool isEnabled = true;
208
209         float sliderPadding = 6.0f;
210
211         private Animation sweepAngleAnimation;
212         private Animation thumbAnimation;
213
214         #endregion Fields
215
216
217         #region Constructors
218
219         static CircularSlider()
220         {
221             ThemeManager.AddPackageTheme(DefaultThemeCreator.Instance);
222         }
223
224         /// <summary>
225         /// The constructor of CircularSlider.
226         /// </summary>
227         [Obsolete("This has been deprecated in API12")]
228         [EditorBrowsable(EditorBrowsableState.Never)]
229         public CircularSlider() : base()
230         {
231             Initialize();
232         }
233
234         /// <summary>
235         /// The constructor of the CircularSlider class with specific style.
236         /// </summary>
237         /// <param name="progressStyle">The style object to initialize the CircularSlider.</param>
238         [Obsolete("This has been deprecated in API12")]
239         [EditorBrowsable(EditorBrowsableState.Never)]
240         public CircularSlider(CircularSliderStyle progressStyle) : base(progressStyle)
241         {
242             Initialize();
243         }
244
245         #endregion Constructors
246
247         #region Events
248
249         /// <summary>
250         /// The value changed event handler.
251         /// </summary>
252         [Obsolete("This has been deprecated in API12")]
253         [EditorBrowsable(EditorBrowsableState.Never)]
254         public event EventHandler<CircularSliderValueChangedEventArgs> ValueChanged;
255
256         #endregion Events
257
258         #region Properties
259
260         /// <summary>
261         /// The thickness of the track and progress.
262         /// </summary>
263         [Obsolete("This has been deprecated in API12")]
264         [EditorBrowsable(EditorBrowsableState.Never)]
265         public float Thickness
266         {
267             get
268             {
269                 return (float)GetValue(ThicknessProperty);
270             }
271             set
272             {
273                 SetValue(ThicknessProperty, value);
274             }
275         }
276
277         /// <summary>
278         /// The property to get/set the maximum value of the CircularSlider.
279         /// The default value is 100.
280         /// </summary>
281         [Obsolete("This has been deprecated in API12")]
282         [EditorBrowsable(EditorBrowsableState.Never)]
283         public float MaxValue
284         {
285             get
286             {
287                 return (float)GetValue(MaxValueProperty);
288             }
289             set
290             {
291                 SetValue(MaxValueProperty, value);
292             }
293         }
294
295         /// <summary>
296         /// The property to get/set the minimum value of the CircularSlider.
297         /// The default value is 0.
298         /// </summary>
299         [Obsolete("This has been deprecated in API12")]
300         [EditorBrowsable(EditorBrowsableState.Never)]
301         public float MinValue
302         {
303             get
304             {
305                 return (float)GetValue(MinValueProperty);
306             }
307             set
308             {
309                 SetValue(MinValueProperty, value);
310             }
311         }
312
313         /// <summary>
314         /// The property to get/set the current value of the CircularSlider.
315         /// The default value is 0.
316         /// </summary>
317         [Obsolete("This has been deprecated in API12")]
318         [EditorBrowsable(EditorBrowsableState.Never)]
319         public float CurrentValue
320         {
321             get
322             {
323                 return (float)GetValue(CurrentValueProperty);
324             }
325             set
326             {
327                 if (sweepAngleAnimation)
328                 {
329                     sweepAngleAnimation.Stop();
330                 }
331                 // For the first Animation effect
332                 sweepAngleAnimation = AnimateVisual(progressVisual, "sweepAngle", progressVisual.SweepAngle, 0, 100, AlphaFunction.BuiltinFunctions.EaseIn);
333
334                 SetValue(CurrentValueProperty, value);
335
336                 UpdateAnimation();
337             }
338         }
339
340         /// <summary>
341         /// The property to get/set Track object color of the CircularSlider.
342         /// </summary>
343         [Obsolete("This has been deprecated in API12")]
344         [EditorBrowsable(EditorBrowsableState.Never)]
345         public Color TrackColor
346         {
347             get
348             {
349                 return (Color)GetValue(TrackColorProperty);
350             }
351             set
352             {
353                 SetValue(TrackColorProperty, value);
354             }
355         }
356
357         /// <summary>
358         /// The property to get/set Progress object color of the CircularSlider.
359         /// </summary>
360         [Obsolete("This has been deprecated in API12")]
361         [EditorBrowsable(EditorBrowsableState.Never)]
362         public Color ProgressColor
363         {
364             get
365             {
366                 return (Color)GetValue(ProgressColorProperty);
367             }
368             set
369             {
370                 SetValue(ProgressColorProperty, value);
371             }
372         }
373
374         /// <summary>
375         /// Gets or sets the size of the thumb of Slider.
376         /// </summary>
377         [Obsolete("This has been deprecated in API12")]
378         [EditorBrowsable(EditorBrowsableState.Never)]
379         public Size ThumbSize
380         {
381             get
382             {
383                 return (Size)GetValue(ThumbSizeProperty);
384             }
385             set
386             {
387                 SetValue(ThumbSizeProperty, value);
388             }
389         }
390
391         /// <summary>
392         /// The property to get/set Thumb object color of the CircularSlider.
393         /// </summary>
394         [Obsolete("This has been deprecated in API12")]
395         [EditorBrowsable(EditorBrowsableState.Never)]
396         public Color ThumbColor
397         {
398             get
399             {
400                 return (Color)GetValue(ThumbColorProperty);
401             }
402             set
403             {
404                 SetValue(ThumbColorProperty, value);
405             }
406         }
407
408         /// <summary>
409         /// Flag to be enabled or disabled in CircularSlider.
410         /// </summary>
411         [Obsolete("This has been deprecated in API12")]
412         [EditorBrowsable(EditorBrowsableState.Never)]
413         public new bool IsEnabled
414         {
415             get
416             {
417                 return (bool)GetValue(IsEnabledProperty);
418             }
419             set
420             {
421                 SetValue(IsEnabledProperty, value);
422             }
423         }
424         private bool privateIsEnabled
425         {
426             get
427             {
428                 return isEnabled;
429             }
430             set
431             {
432                 isEnabled = value;
433                 if (isEnabled)
434                 {
435                     UpdateTrackVisualColor(new Color(0.0f, 0.16f, 0.30f, 1.0f)); // #002A4D
436                 }
437                 else
438                 {
439                     UpdateTrackVisualColor(new Color(0.25f, 0.25f, 0.25f, 1.0f)); // #404040
440                 }
441             }
442         }
443
444         private CircularSliderStyle CurrentStyle => ViewStyle as CircularSliderStyle;
445
446         #endregion Properties
447
448
449         #region Methods
450
451         /// <summary>
452         /// Dispose Progress and all children on it.
453         /// </summary>
454         /// <param name="type">Dispose type.</param>
455         [Obsolete("This has been deprecated in API12")]
456         [EditorBrowsable(EditorBrowsableState.Never)]
457         protected override void Dispose(DisposeTypes type)
458         {
459             if (disposed)
460             {
461                 return;
462             }
463
464             if (type == DisposeTypes.Explicit)
465             {
466                 trackVisual = null;
467                 progressVisual = null;
468                 thumbVisual = null;
469             }
470
471             base.Dispose(type);
472         }
473
474         /// <summary>
475         /// Update progress value
476         /// </summary>
477         [Obsolete("This has been deprecated in API12")]
478         [EditorBrowsable(EditorBrowsableState.Never)]
479         protected virtual void UpdateValue()
480         {
481             if (null == trackVisual || null == progressVisual || null == thumbVisual)
482             {
483                 return;
484             }
485
486             if (minValue >= maxValue || currentValue < minValue || currentValue > maxValue)
487             {
488                 return;
489             }
490
491             HandleProgressVisualVisibility();
492
493             UpdateProgressVisualSweepAngle();
494         }
495
496         /// <summary>
497         /// Get Progress style.
498         /// </summary>
499         /// <returns>The default progress style.</returns>
500         [Obsolete("This has been deprecated in API12")]
501         [EditorBrowsable(EditorBrowsableState.Never)]
502         protected override ViewStyle CreateViewStyle()
503         {
504             return new CircularSliderStyle();
505         }
506
507         private void Initialize()
508         {
509             Size = new Size(360.0f, 360.0f);
510
511             sweepAngleAnimation?.Stop();
512             sweepAngleAnimation = null;
513
514             thumbAnimation?.Stop();
515             thumbAnimation = null;
516
517             trackVisual = new ArcVisual
518             {
519                 SuppressUpdateVisual = true,
520                 Size = new Size(this.Size.Width - sliderPadding, this.Size.Height - sliderPadding),
521                 SizePolicy = VisualTransformPolicyType.Absolute,
522                 Thickness = this.Thickness,
523                 Cap = ArcVisual.CapType.Butt,
524                 MixColor = TrackColor,
525                 StartAngle = 0.0f,
526                 SweepAngle = 360.0f
527             };
528             this.AddVisual(TrackVisualName, trackVisual);
529
530             progressVisual = new ArcVisual
531             {
532                 SuppressUpdateVisual = true,
533                 Size = new Size(this.Size.Width - sliderPadding, this.Size.Height - sliderPadding),
534                 SizePolicy = VisualTransformPolicyType.Absolute,
535                 Thickness = this.Thickness,
536                 Cap = ArcVisual.CapType.Butt,
537                 MixColor = ProgressColor,
538                 StartAngle = 0.0f,
539                 SweepAngle = 0.0f
540             };
541             this.AddVisual(ProgressVisualName, progressVisual);
542
543             thumbVisual = new ArcVisual
544             {
545                 SuppressUpdateVisual = true,
546                 Size = new Size(this.Size.Width + sliderPadding, this.Size.Height + sliderPadding),
547                 SizePolicy = VisualTransformPolicyType.Absolute,
548                 Thickness = this.ThumbSize.Width,
549                 Cap = ArcVisual.CapType.Round,
550                 MixColor = this.ThumbColor,
551                 StartAngle = 0.0f,
552                 SweepAngle = 0.0f
553             };
554             this.AddVisual(ThumbVisualName, thumbVisual);
555
556             HandleProgressVisualVisibility();
557
558             UpdateProgressVisualSweepAngle();
559         }
560
561         private void HandleProgressVisualVisibility()
562         {
563             if (isEnabled)
564             {
565                 progressVisual.Opacity = 1.0f;
566             }
567             else if (!isEnabled)
568             {
569                 progressVisual.Opacity = 0.6f;
570             }
571         }
572
573         private void UpdateVisualThickness(float thickness)
574         {
575             if (trackVisual == null)
576             {
577                 return;
578             }
579
580             trackVisual.Thickness = thickness;
581             progressVisual.Thickness = thickness;
582
583             trackVisual.UpdateVisual(true);
584             progressVisual.UpdateVisual(true);
585         }
586
587         private void UpdateProgressVisualSweepAngle()
588         {
589             float progressRatio = (float)(currentValue - minValue) / (float)(maxValue - minValue);
590             float progressWidth = 360.0f * progressRatio; // Circle
591
592             progressVisual.SweepAngle = progressWidth;
593             thumbVisual.StartAngle = progressWidth;
594
595             if (!sweepAngleAnimation)
596             {
597                 progressVisual.UpdateVisual(true);
598                 thumbVisual.UpdateVisual(true);
599             }
600         }
601
602         private void UpdateAnimation()
603         {
604             // TODO : Currently not sure which effect is needed.
605             AlphaFunction.BuiltinFunctions builtinAlphaFunction = AlphaFunction.BuiltinFunctions.EaseOut;
606
607             if (sweepAngleAnimation)
608             {
609                 sweepAngleAnimation.Stop();
610             }
611             if (thumbAnimation)
612             {
613                 thumbAnimation.Stop();
614             }
615
616             sweepAngleAnimation = AnimateVisual(progressVisual, "sweepAngle", progressVisual.SweepAngle, 0, 500, builtinAlphaFunction);
617             thumbAnimation = AnimateVisual(thumbVisual, "startAngle", thumbVisual.StartAngle, 0, 500, builtinAlphaFunction);
618
619             if (sweepAngleAnimation)
620             {
621                 sweepAngleAnimation.Play();
622                 thumbAnimation.Play();
623             }
624
625             ValueChanged?.Invoke(this, new CircularSliderValueChangedEventArgs() { CurrentValue = currentValue });
626         }
627
628         private void UpdateTrackVisualColor(Color trackColor)
629         {
630             if (trackVisual == null)
631             {
632                 return;
633             }
634
635             trackVisual.MixColor = trackColor;
636             trackVisual.UpdateVisual(true);
637         }
638
639         private void UpdateProgressVisualColor(Color progressColor)
640         {
641             if (progressVisual == null)
642             {
643                 return;
644             }
645
646             progressVisual.MixColor = progressColor;
647             if (!isEnabled) // Dim state
648             {
649                 progressVisual.Opacity = 0.6f;
650             }
651
652             progressVisual.UpdateVisual(true);
653         }
654
655         private void UpdateThumbVisualSize(Size thumbSize)
656         {
657             if (thumbVisual == null)
658             {
659                 return;
660             }
661
662             thumbVisual.Thickness = thumbSize.Width;
663             thumbVisual.UpdateVisual(true);
664         }
665
666         private void UpdateThumbVisualColor(Color thumbColor)
667         {
668             if (thumbVisual == null)
669             {
670                 return;
671             }
672
673             thumbVisual.MixColor = thumbColor;
674             thumbVisual.UpdateVisual(true);
675         }
676
677
678         #endregion Methods
679     }
680 }