sync ElmSharp source code latest
[platform/core/csapi/tizenfx.git] / src / ElmSharp.Wearable / ElmSharp.Wearable / RotarySelectorItem.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 using System.Collections.Generic;
19 using System.Text;
20
21 namespace ElmSharp.Wearable
22 {
23     /// <summary>
24     /// A instance to the Rotary Selector Item added. And an item can be selected by rotary event or user item click.
25     /// </summary>
26     public class RotarySelectorItem
27     {
28         const string MainTextPartName = "selector,main_text";
29         const string SubTextPartName = "selector,sub_text";
30         const string IconPartName = "item,icon";
31         const string BgPartName = "item,bg_image";
32         const string SelectorIconPartName = "selector,icon";
33
34         string _mainText;
35         string _subText;
36
37         Color _mainTextColor;
38         Color _subTextColor;
39
40         Image _normalIconImage;
41         Image _pressedIconImage;
42         Image _disabledIconImage;
43         Image _selectedIconImage;
44
45         Image _normalBgImage;
46         Image _pressedBgImage;
47         Image _disabledBgImage;
48         Image _selectedBgImage;
49
50         Color _normalBgColor;
51         Color _pressedBgColor;
52         Color _disabledBgColor;
53         Color _selectedBgColor;
54
55         Image _selectorIconImage;
56
57         IntPtr _handle;
58
59         /// <summary>
60         /// Sets or gets the handle of a rotary selector item object.
61         /// </summary>
62         public IntPtr Handle
63         {
64             set
65             {
66                 if (_handle == value) return;
67                 _handle = value;
68
69                 if (_handle == null) return;
70
71                 setPart(ref _mainText, MainTextPartName);
72                 setPart(ref _subText, SubTextPartName);
73                 setPart(ref _mainTextColor, MainTextPartName, ItemState.Normal);
74                 setPart(ref _subTextColor, SubTextPartName, ItemState.Normal);
75
76                 setPart(ref _normalIconImage, IconPartName, ItemState.Normal);
77                 setPart(ref _pressedIconImage, IconPartName, ItemState.Pressed);
78                 setPart(ref _disabledIconImage, IconPartName, ItemState.Disabled);
79                 setPart(ref _selectedIconImage, IconPartName, ItemState.Selected);
80
81                 setPart(ref _normalBgImage, BgPartName, ItemState.Normal);
82                 setPart(ref _pressedBgImage, BgPartName, ItemState.Pressed);
83                 setPart(ref _disabledBgImage, BgPartName, ItemState.Disabled);
84                 setPart(ref _selectedBgImage, BgPartName, ItemState.Selected);
85
86                 setPart(ref _normalBgColor, BgPartName, ItemState.Normal);
87                 setPart(ref _pressedBgColor, BgPartName, ItemState.Pressed);
88                 setPart(ref _disabledBgColor, BgPartName, ItemState.Disabled);
89                 setPart(ref _selectedBgColor, BgPartName, ItemState.Selected);
90
91                 setPart(ref _selectorIconImage, SelectorIconPartName, ItemState.Normal);
92             }
93
94             get
95             {
96                 return _handle;
97             }
98         }
99
100         void setPart(ref Image prop, string partName, ItemState state)
101         {
102             if (prop != null)
103             {
104                 Interop.Eext.eext_rotary_selector_item_part_content_set(Handle, partName, (int)state, prop);
105             }
106         }
107         void setPart(ref Color prop, string partName, ItemState state)
108         {
109             if (prop != default(Color))
110             {
111                 Interop.Eext.eext_rotary_selector_item_part_color_set(Handle, partName, (int)state, prop.R, prop.G, prop.B, prop.A);
112             }
113         }
114
115         void setPart(ref string prop, string partName)
116         {
117             if (prop != null)
118             {
119                 Interop.Eext.eext_rotary_selector_item_part_text_set(Handle, partName, prop);
120             }
121         }
122
123         void setPart(ref Image prop, string partName, ItemState state, Image img)
124         {
125             if (prop == img) return;
126             prop = img;
127             if (Handle != null)
128             {
129                 Interop.Eext.eext_rotary_selector_item_part_content_set(Handle, partName, (int)state, img);
130             }
131         }
132
133         void setPart(ref Color prop, string partName, ItemState state, Color color)
134         {
135             if (prop == color) return;
136             prop = color;
137             if (Handle != null)
138             {
139                 Interop.Eext.eext_rotary_selector_item_part_color_set(Handle, partName, (int)state, color.R, color.G, color.B, color.A);
140             }
141         }
142
143         void setPart(ref string prop, string partName, string txt)
144         {
145             if (prop == txt) return;
146             prop = txt;
147             if (Handle != null)
148             {
149                 Interop.Eext.eext_rotary_selector_item_part_text_set(Handle, partName, txt);
150             }
151         }
152
153         /// <summary>
154         /// Sets or gets the main text of a rotary selector item object.
155         /// </summary>
156         public string MainText { set => setPart(ref _mainText, MainTextPartName, value); get => _mainText; }
157
158         /// <summary>
159         /// Sets or gets the sub text of a rotary selector item object.
160         /// </summary>
161         public string SubText { set => setPart(ref _subText, SubTextPartName, value); get => _subText; }
162
163         /// <summary>
164         /// Sets or gets the sub text color of a rotary selector item object.
165         /// </summary>
166         public Color MainTextColor { set => setPart(ref _mainTextColor, MainTextPartName, ItemState.Normal, value); get => _mainTextColor; }
167
168         /// <summary>
169         /// Sets or gets the sub text color of a rotary selector item object.
170         /// </summary>
171         public Color SubTextColor { set => setPart(ref _subTextColor, SubTextPartName, ItemState.Normal, value); get => _subTextColor; }
172
173         /// <summary>
174         /// Sets or gets the normal icon image of a rotary selector item object.
175         /// </summary>
176         public Image NormalIconImage { set => setPart(ref _normalIconImage, IconPartName, ItemState.Normal, value); get => _normalIconImage; }
177
178         /// <summary>
179         /// Sets or gets the press icon image of a rotary selector item object.
180         /// </summary>
181         public Image PressedIconImage { set => setPart(ref _pressedIconImage, IconPartName, ItemState.Pressed, value); get => _pressedIconImage; }
182
183         /// <summary>
184         /// Sets or gets the disable icon image of a rotary selector item object.
185         /// </summary>
186         public Image DisabledIconImage { set => setPart(ref _disabledIconImage, IconPartName, ItemState.Disabled, value); get => _disabledIconImage; }
187
188         /// <summary>
189         /// Sets or gets the selected icon image of a rotary selector item object.
190         /// </summary>
191         public Image SelectedIconImage { set => setPart(ref _selectedIconImage, IconPartName, ItemState.Selected, value); get => _selectedIconImage; }
192
193         /// <summary>
194         /// Sets or gets the normal background image of a rotary selector item object.
195         /// </summary>
196         public Image NormalBackgroundImage { set => setPart(ref _normalBgImage, BgPartName, ItemState.Normal, value); get => _normalBgImage; }
197
198         /// <summary>
199         /// Sets or gets the pressed background image of a rotary selector item object.
200         /// </summary>
201         public Image PressedBackgroundImage { set => setPart(ref _pressedBgImage, BgPartName, ItemState.Pressed, value); get => _pressedBgImage; }
202
203         /// <summary>
204         /// Sets or gets the disabled background image of a rotary selector item object.
205         /// </summary>
206         public Image DisabledBackgroundImage { set => setPart(ref _disabledBgImage, BgPartName, ItemState.Disabled, value); get => _disabledBgImage; }
207
208         /// <summary>
209         /// Sets or gets the selected background image of a rotary selector item object.
210         /// </summary>
211         public Image SelectedBackgroundImage { set => setPart(ref _selectedBgImage, BgPartName, ItemState.Selected, value); get => _selectedBgImage; }
212
213         /// <summary>
214         /// Sets or gets the normal background color of a rotary selector item object.
215         /// </summary>
216         public Color NormalBackgroundColor { set => setPart(ref _normalBgColor, BgPartName, ItemState.Normal, value); get => _normalBgColor; }
217
218         /// <summary>
219         /// Sets or gets the pressed background color of a rotary selector item object.
220         /// </summary>
221         public Color PressedBackgroundColor { set => setPart(ref _pressedBgColor, BgPartName, ItemState.Pressed, value); get => _pressedBgColor; }
222
223         /// <summary>
224         /// Sets or gets the disabled background color of a rotary selector item object.
225         /// </summary>
226         public Color DisabledBackgroundColor { set => setPart(ref _disabledBgColor, BgPartName, ItemState.Disabled, value); get => _disabledBgColor; }
227
228         /// <summary>
229         /// Sets or gets the selected background color of a rotary selector item object.
230         /// </summary>
231         public Color SelectedBackgroundColor { set => setPart(ref _selectedBgColor, BgPartName, ItemState.Selected, value); get => _selectedBgColor; }
232
233         /// <summary>
234         /// Sets or gets the selector icon image of a rotary selector item object.
235         /// </summary>
236         public Image SelectorIconImage { set => setPart(ref _selectorIconImage, SelectorIconPartName, ItemState.Normal, value); get => _selectorIconImage; }
237
238         internal enum ItemState
239         {
240             Normal,
241             Pressed,
242             Disabled,
243             Selected
244         }
245     }
246 }