dali ver 1.2.27 devel-master branch code sync
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / devel-src / visual-high-level / ImageVisual.cs
1 /*\r
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 using System;\r
19 using System.Runtime.InteropServices;\r
20 using System.Collections.Generic;\r
21 using System.Linq;\r
22 using Tizen.NUI;\r
23 \r
24 namespace Tizen.NUI\r
25 {\r
26 public class ImageVisual : VisualBase\r
27 {\r
28     private VisualBase _imageVisual;\r
29     private Property.Map _imageProperty;\r
30     private string _imageUrl;\r
31     private string _fittingMode;\r
32     private string _samplingMode;\r
33     private int _desiredWidth;\r
34     private int _desiredHeight;\r
35     private bool _synchronousLoading;\r
36     private bool _borderOnly;\r
37     private Vector4 _pixelArea;\r
38     private string _wrapModeU;\r
39     private string _wrapModeV;\r
40 \r
41     private Vector2 _imageVisualSize;\r
42     private Vector2 _imageVisualPosition;\r
43     private Vector4 _offsetSizeMode;\r
44     private Vector2 _parentSize;\r
45     private Tizen.NUI.AlignType _origin;\r
46     private Tizen.NUI.AlignType _anchorPoint;\r
47 \r
48     public ImageVisual() : base()\r
49     {\r
50         //Initial the default transform map.\r
51         _offsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f ); //absolute\r
52         _origin = AlignType.TOP_BEGIN;\r
53         _anchorPoint = AlignType.TOP_BEGIN;\r
54 \r
55         //Initial the image property map.\r
56         _imageProperty = new Property.Map();\r
57         _imageProperty.Insert( NDalic.VISUAL_PROPERTY_TYPE, new Property.Value( (int)VisualType.IMAGE ) );\r
58     }\r
59 \r
60     public ImageVisual(string imageUrl)\r
61     {\r
62         //Initial the default transform map.\r
63         _offsetSizeMode = new Vector4( 1.0f, 1.0f, 1.0f, 1.0f ); //absolute\r
64         _origin = AlignType.TOP_BEGIN;\r
65         _anchorPoint = AlignType.TOP_BEGIN;\r
66 \r
67         //Initial the image property map.\r
68         _imageUrl = imageUrl;\r
69         _imageProperty = new Property.Map();\r
70         _imageProperty.Insert( NDalic.VISUAL_PROPERTY_TYPE, new Property.Value( (int)VisualType.IMAGE ) );\r
71         _imageProperty.Insert( NDalic.IMAGE_VISUAL_URL, new Property.Value( _imageUrl ) );\r
72     }\r
73 \r
74     public string Url\r
75     {\r
76         get\r
77         {\r
78             return _imageUrl;\r
79         }\r
80         set\r
81         {\r
82             _imageUrl = value;\r
83             _imageProperty.Insert( NDalic.IMAGE_VISUAL_URL, new Property.Value( _imageUrl ) );\r
84         }\r
85     }\r
86 \r
87     public string FittingMode\r
88     {\r
89         get\r
90         {\r
91             return _fittingMode;\r
92         }\r
93         set\r
94         {\r
95             _fittingMode = value;\r
96             _imageProperty.Insert( NDalic.IMAGE_VISUAL_FITTING_MODE, new Property.Value( _fittingMode ) );\r
97         }\r
98     }\r
99 \r
100     public string SamplingMode\r
101     {\r
102         get\r
103         {\r
104             return _samplingMode;\r
105         }\r
106         set\r
107         {\r
108             _samplingMode = value;\r
109             _imageProperty.Insert( NDalic.IMAGE_VISUAL_SAMPLING_MODE, new Property.Value( _samplingMode ) );\r
110         }\r
111     }\r
112 \r
113     public int DesiredWidth\r
114     {\r
115         get\r
116         {\r
117             return _desiredWidth;\r
118         }\r
119         set\r
120         {\r
121             _desiredWidth = value;\r
122             _imageProperty.Insert( NDalic.IMAGE_VISUAL_DESIRED_WIDTH, new Property.Value( _desiredWidth ) );\r
123         }\r
124     }\r
125 \r
126     public int DesiredHeight\r
127     {\r
128         get\r
129         {\r
130             return _desiredHeight;\r
131         }\r
132         set\r
133         {\r
134             _desiredHeight = value;\r
135             _imageProperty.Insert( NDalic.IMAGE_VISUAL_DESIRED_HEIGHT, new Property.Value( _desiredHeight ) );\r
136         }\r
137     }\r
138 \r
139     public bool SynchronousLoading\r
140     {\r
141         get\r
142         {\r
143             return _synchronousLoading;\r
144         }\r
145         set\r
146         {\r
147             _synchronousLoading = value;\r
148             _imageProperty.Insert( NDalic.IMAGE_VISUAL_SYNCHRONOUS_LOADING, new Property.Value( _synchronousLoading ) );\r
149         }\r
150     }\r
151 \r
152     public bool BorderOnly\r
153     {\r
154         get\r
155         {\r
156             return _borderOnly;\r
157         }\r
158         set\r
159         {\r
160             _borderOnly = value;\r
161              _imageProperty.Insert( NDalic.IMAGE_VISUAL_BORDER_ONLY, new Property.Value( _borderOnly ) );\r
162         }\r
163     }\r
164 \r
165     public Vector4 PixelArea\r
166     {\r
167         get\r
168         {\r
169             return _pixelArea;\r
170         }\r
171         set\r
172         {\r
173             _pixelArea = value;\r
174              _imageProperty.Insert( NDalic.IMAGE_VISUAL_PIXEL_AREA, new Property.Value( _pixelArea ) );\r
175         }\r
176     }\r
177 \r
178     public string WrapModeU\r
179     {\r
180         get\r
181         {\r
182             return _wrapModeU;\r
183         }\r
184         set\r
185         {\r
186             _wrapModeU = value;\r
187              _imageProperty.Insert( NDalic.IMAGE_VISUAL_WRAP_MODE_U, new Property.Value( _wrapModeU ) );\r
188         }\r
189     }\r
190 \r
191     public string WrapModeV\r
192     {\r
193         get\r
194         {\r
195             return _wrapModeV;\r
196         }\r
197         set\r
198         {\r
199             _wrapModeV = value;\r
200              _imageProperty.Insert( NDalic.IMAGE_VISUAL_WRAP_MODE_V, new Property.Value( _wrapModeV ) );\r
201         }\r
202     }\r
203 \r
204     public Vector2 Size\r
205     {\r
206         get\r
207         {\r
208             return _imageVisualSize;\r
209         }\r
210         set\r
211         {\r
212             _imageVisualSize = value;\r
213         }\r
214     }\r
215 \r
216     public Vector2 Position\r
217     {\r
218         get\r
219         {\r
220             return _imageVisualPosition;\r
221         }\r
222         set\r
223         {\r
224             _imageVisualPosition = value;\r
225         }\r
226     }\r
227 \r
228     public Vector4 OffsetSizeMode\r
229     {\r
230         get\r
231         {\r
232             return _offsetSizeMode;\r
233         }\r
234         set\r
235         {\r
236             _offsetSizeMode = value;\r
237         }\r
238     }\r
239 \r
240     public Vector2 ParentSize\r
241     {\r
242         get\r
243         {\r
244             return _parentSize;\r
245         }\r
246         set\r
247         {\r
248             _parentSize = value;\r
249         }\r
250     }\r
251 \r
252     public AlignType Origin\r
253     {\r
254         get\r
255         {\r
256             return _origin;\r
257         }\r
258         set\r
259         {\r
260             _origin = value;\r
261         }\r
262     }\r
263 \r
264     public AlignType AnchorPoint\r
265     {\r
266         get\r
267         {\r
268             return _anchorPoint;\r
269         }\r
270         set\r
271         {\r
272             _anchorPoint = value;\r
273         }\r
274     }\r
275 \r
276     public void Instantiate()\r
277     {\r
278         //\r
279         _imageVisual = VisualFactory.Get().CreateVisual( _imageProperty );\r
280 \r
281         Property.Map imageVisualTransform = new Property.Map();\r
282         imageVisualTransform.Add( (int)VisualTransformPropertyType.SIZE, new Property.Value(_imageVisualSize) );\r
283         imageVisualTransform.Add( (int)VisualTransformPropertyType.OFFSET, new Property.Value(_imageVisualPosition) );\r
284         imageVisualTransform.Add( (int)VisualTransformPropertyType.OFFSET_SIZE_MODE, new Property.Value(_offsetSizeMode) );\r
285         imageVisualTransform.Add( (int)VisualTransformPropertyType.ORIGIN, new Property.Value((int)_origin) );\r
286         imageVisualTransform.Add( (int)VisualTransformPropertyType.ANCHOR_POINT, new Property.Value((int)_anchorPoint) );\r
287         _imageVisual.SetTransformAndSize( imageVisualTransform, _parentSize );\r
288     }\r
289 }\r
290 }