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