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