[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / ColorSelector.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// Enumeration for the modes of ColorSelector.
23     /// </summary>
24     /// <since_tizen> preview </since_tizen>
25     public enum ColorSelectorMode
26     {
27         /// <summary>
28         /// Only the color palette is displayed, by default.
29         /// </summary>
30         Palette,
31         /// <summary>
32         /// Only the color selector is displayed.
33         /// </summary>
34         [Obsolete("Components is obsolete as of version 1.2.3 and is no longer supported.")]
35         Components,
36         /// <summary>
37         /// Both the palette and the selector is displayed.
38         /// </summary>
39         [Obsolete("Both is obsolete as of version 1.2.3 and is no longer supported.")]
40         Both,
41         /// <summary>
42         /// Only the color picker is displayed.
43         /// </summary>
44         [Obsolete("Picker is obsolete as of version 1.2.3 and is no longer supported.")]
45         Picker,
46         /// <summary>
47         /// This mode is not supported. If you use this, nothing will be shown.
48         /// </summary>
49         [Obsolete("Plane is obsolete as of version 1.2.3 and is no longer supported.")]
50         Plane,
51         /// <summary>
52         /// This mode is not supported. If you use this, it will be shown same with the Palette mode.
53         /// </summary>
54         [Obsolete("PallettePlane is obsolete as of version 1.2.3 and is no longer supported.")]
55         PallettePlane,
56         /// <summary>
57         /// This mode is not supported. If you use this, it will be shown same with the Palette mode.
58         /// </summary>
59         [Obsolete("All is obsolete as of version 1.2.3 and is no longer supported.")]
60         All
61     }
62
63     /// <summary>
64     /// The ColorSelector is a widget to set a series of colors.
65     /// It also allows to load/save colors from/to the configuration with a unique identifier.
66     /// </summary>
67     /// <remarks>
68     /// By default, the colors are loaded/saved from/to configuration using the "default" identifier.
69     /// The colors can be picked by the user from the color set by clicking on individual
70     /// color items on the palette, or by selecting it from the selector.
71     /// </remarks>
72     /// <since_tizen> preview </since_tizen>
73     public class ColorSelector : Layout
74     {
75         private readonly SmartEvent<ColorChangedEventArgs> _changed;
76         private Color _currentColor;
77
78         /// <summary>
79         /// Creates and initializes a new instance of the ColorSelector class.
80         /// </summary>
81         /// <param name="parent"></param>
82         /// <since_tizen> preview </since_tizen>
83         public ColorSelector(EvasObject parent) : base(parent)
84         {
85             _changed = new SmartEvent<ColorChangedEventArgs>(this, "changed", (data, obj, info) =>
86             {
87                 return new ColorChangedEventArgs(_currentColor, SelectedColor);
88             });
89         }
90
91         /// <summary>
92         /// ColorChanged will be triggered when the SelectedColor is changed.
93         /// </summary>
94         /// <since_tizen> preview </since_tizen>
95         public event EventHandler<ColorChangedEventArgs> ColorChanged
96         {
97             add { _changed.On += value; }
98             remove { _changed.On -= value; }
99         }
100
101         /// <summary>
102         /// Gets or sets the color of colorselector.
103         /// </summary>
104         /// <since_tizen> preview </since_tizen>
105         public Color SelectedColor
106         {
107             get
108             {
109                 int r, g, b, a;
110                 Interop.Elementary.elm_colorselector_color_get(Handle, out r, out g, out b, out a);
111                 _currentColor = new Color(r, g, b, a);
112                 return _currentColor;
113             }
114             set
115             {
116                 Interop.Elementary.elm_colorselector_color_set(Handle, value.R, value.G, value.B, value.A);
117                 _currentColor = new Color(value.R, value.G, value.B, value.A);
118             }
119         }
120
121         /// <summary>
122         /// Gets the Alpha of a default Color class (value is -1).
123         /// </summary>
124         /// <since_tizen> preview </since_tizen>
125         public override int Opacity
126         {
127             get
128             {
129                 return Color.Default.A;
130             }
131             set
132             {
133                 Console.WriteLine("ColorSelector instance doesn't support to set Opacity.");
134             }
135         }
136
137         /// <summary>
138         /// Gets or sets the Colorselector's mode.
139         /// </summary>
140         /// <since_tizen> preview </since_tizen>
141         public ColorSelectorMode Mode
142         {
143             get
144             {
145                 return (ColorSelectorMode)Interop.Elementary.elm_colorselector_mode_get(Handle);
146             }
147             set
148             {
149                 if (ColorSelectorMode.Palette == value)
150                 {
151                     Interop.Elementary.elm_colorselector_mode_set(Handle, (Interop.Elementary.Elm_Colorselector_Mode)value);
152                 }
153             }
154         }
155
156         /// <summary>
157         /// Gets or sets the current palette's name.
158         /// </summary>
159         /// <since_tizen> preview </since_tizen>
160         public string PaletteName
161         {
162             get
163             {
164                 return Interop.Elementary.elm_colorselector_palette_name_get(Handle);
165             }
166             set
167             {
168                 Interop.Elementary.elm_colorselector_palette_name_set(Handle, value);
169             }
170         }
171
172         /// <summary>
173         /// Adds a new color item to the palette.
174         /// </summary>
175         /// <param name="color">The color item to add.</param>
176         /// <returns>A new color palette Item.</returns>
177         /// <since_tizen> preview </since_tizen>
178         public ColorSelectorItem AddPaletteColor(Color color)
179         {
180             ColorSelectorItem item = new ColorSelectorItem(this);
181             item.Handle = Interop.Elementary.elm_colorselector_palette_color_add(Handle, color.R, color.G, color.B, color.A);
182             return item;
183         }
184
185         /// <summary>
186         /// Clears the palette items.
187         /// </summary>
188         /// <since_tizen> preview </since_tizen>
189         public void ClearPalette()
190         {
191             Interop.Elementary.elm_colorselector_palette_clear(Handle);
192         }
193
194         /// <summary>
195         /// Creates a widget handle.
196         /// </summary>
197         /// <param name="parent">Parent EvasObject.</param>
198         /// <returns>Handle IntPtr.</returns>
199         /// <since_tizen> preview </since_tizen>
200         protected override IntPtr CreateHandle(EvasObject parent)
201         {
202             return Interop.Elementary.elm_colorselector_add(parent.Handle);
203         }
204     }
205 }