/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Diagnostics;
namespace ElmSharp.Wearable
{
///
/// Circle slider is circular designed widget to select a value in a range by rotary event.
///
public class CircleSlider : Widget, IRotaryActionWidget
{
SmartEvent _changedEvent;
CircleSurface _surface;
///
/// Creates and initializes a new instance of the CircleSlider class.
///
/// The EvasObject to which the new CircleSlider will be attached as a child.
/// The surface for drawing circle features for this widget.
public CircleSlider(EvasObject parent, CircleSurface surface) : base()
{
Debug.Assert(parent == null || surface == null || parent.IsRealized);
_surface = surface;
Realize(parent);
}
///
/// Changed will be triggered when the circle slider value changes.
///
public event EventHandler ValueChanged;
///
/// Gets the handle for Circle Widget.
///
public virtual IntPtr CircleHandle => RealHandle;
///
/// Gets the handle for Circle Surface used in this widget
///
public virtual CircleSurface CircleSurface => _surface;
///
/// Sets or gets the step by which the circle slider bar moves.
///
///
/// This value is used when circle slider value is changed by an drag or rotary event
/// The value of the slider is increased/decreased by the step value.
///
public double Step
{
get
{
return Interop.Eext.eext_circle_object_slider_step_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_slider_step_set(CircleHandle, (double)value);
}
}
///
/// Sets or gets the state of the widget, which might be enabled or disabled.
///
public override bool IsEnabled
{
get
{
return !Interop.Eext.eext_circle_object_disabled_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_disabled_set(CircleHandle, !value);
}
}
///
/// Sets or gets color of the circle slider bar.
///
public Color BarColor
{
get
{
int r = 0;
int g = 0;
int b = 0;
int a = 0;
Interop.Eext.eext_circle_object_color_get(CircleHandle, out r, out g, out b, out a);
return Color.FromRgba(r, g, b, a);
}
set
{
Interop.Eext.eext_circle_object_color_set(CircleHandle, value.R, value.G, value.B, value.A);
}
}
///
/// Sets or gets color of the circle slider background.
///
public override Color BackgroundColor
{
get
{
int r = 0;
int g = 0;
int b = 0;
int a = 0;
Interop.Eext.eext_circle_object_item_color_get(CircleHandle, "bg", out r, out g, out b, out a);
return Color.FromRgba(r, g, b, a);
}
set
{
Interop.Eext.eext_circle_object_item_color_set(CircleHandle, "bg", value.R, value.G, value.B, value.A);
}
}
///
/// Sets or gets the line with of the circle slider bar.
///
public int BarLineWidth
{
get
{
return Interop.Eext.eext_circle_object_line_width_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_line_width_set(CircleHandle, value);
}
}
///
/// Sets or gets the line with of the circle slider background.
///
public int BackgroundLineWidth
{
get
{
return Interop.Eext.eext_circle_object_item_line_width_get(CircleHandle, "bg");
}
set
{
Interop.Eext.eext_circle_object_item_line_width_set(CircleHandle, "bg", value);
}
}
///
/// Sets or gets the angle in degree of the circle slider bar.
///
public double BarAngle
{
get
{
return Interop.Eext.eext_circle_object_angle_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_angle_set(CircleHandle, value);
}
}
///
/// Sets or gets the angle in degree of the circle slider background.
///
public double BackgroundAngle
{
get
{
return Interop.Eext.eext_circle_object_item_angle_get(CircleHandle, "bg");
}
set
{
Interop.Eext.eext_circle_object_item_angle_set(CircleHandle, "bg", value);
}
}
///
/// Sets or gets the angle offset for the slider bar.
/// offset value means start position of the slider bar.
///
public double BarAngleOffset
{
get
{
return Interop.Eext.eext_circle_object_angle_offset_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_angle_offset_set(CircleHandle, value);
}
}
///
/// Sets or gets the angle offset for the circle slider background.
/// offset value means start position of the slider background.
///
public double BackgroundAngleOffset
{
get
{
return Interop.Eext.eext_circle_object_item_angle_offset_get(CircleHandle, "bg");
}
set
{
Interop.Eext.eext_circle_object_item_angle_offset_set(CircleHandle, "bg", value);
}
}
///
/// Sets or gets the minimum angle of the circle slider bar.
///
public double BarAngleMinimum
{
get
{
double min;
double max;
Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
return min;
}
set
{
double max = BarAngleMaximum;
Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, (double)value, max);
}
}
///
/// Sets or gets the maximum angle of the circle slider bar.
///
public double BarAngleMaximum
{
get
{
double min;
double max;
Interop.Eext.eext_circle_object_angle_min_max_get(CircleHandle, out min, out max);
return max;
}
set
{
double min = BarAngleMinimum;
Interop.Eext.eext_circle_object_angle_min_max_set(CircleHandle, min, (double)value);
}
}
///
/// Sets or gets the minimum values for the circle slider.
///
///
/// This defines the allowed minimum values to be selected by the user.
/// If the actual value is less than min, it is updated to min.
/// Actual value can be obtained with Value.By default, min is equal to 0.0.
///
public double Minimum
{
get
{
double min;
double max;
Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
return min;
}
set
{
double max = Maximum;
Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, (double)value, max);
}
}
///
/// Sets or gets the maximum values for the circle slider.
///
///
/// This defines the allowed maximum values to be selected by the user.
/// If the actual value is bigger then max, it is updated to max.
/// Actual value can be obtained with Value.By default, min is equal to 0.0, and max is equal to 1.0.
/// Maximum must be greater than minimum, otherwise the behavior is undefined.
///
public double Maximum
{
get
{
double min;
double max;
Interop.Eext.eext_circle_object_value_min_max_get(CircleHandle, out min, out max);
return max;
}
set
{
double min = Minimum;
Interop.Eext.eext_circle_object_value_min_max_set(CircleHandle, min, (double)value);
}
}
///
/// Gets or sets the value displayed by the circle slider.
///
///
/// The value must to be between Minimum and Maximum values.
///
public double Value
{
get
{
return Interop.Eext.eext_circle_object_value_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_value_set(CircleHandle, (double)value);
}
}
///
/// Gets or sets the radius value for the circle slider bar.
///
public double BarRadius
{
get
{
return Interop.Eext.eext_circle_object_radius_get(CircleHandle);
}
set
{
Interop.Eext.eext_circle_object_radius_set(CircleHandle, value);
}
}
///
/// Gets or sets the radius value for the circle slider background.
///
public double BackgroundRadius
{
get
{
return Interop.Eext.eext_circle_object_item_radius_get(CircleHandle, "bg");
}
set
{
Interop.Eext.eext_circle_object_item_radius_set(CircleHandle, "bg", value);
}
}
///
/// The callback of Realized Event
///
protected override void OnRealized()
{
base.OnRealized();
_changedEvent = new SmartEvent(this, "value,changed");
_changedEvent.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
}
///
/// Creates a widget handle.
///
/// Parent EvasObject
/// Handle IntPtr
protected override IntPtr CreateHandle(EvasObject parent)
{
return Interop.Eext.eext_circle_object_slider_add(parent, CircleSurface.Handle);
}
}
}