2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
24 public partial class ImageView
26 /// Intenal used, will never be opened.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
30 var imageView = (ImageView)bindable;
32 if (newValue is Selector<string> selector)
34 imageView.ResourceUrlSelector = selector;
38 imageView.resourceUrlSelector?.Reset(imageView);
39 imageView.SetResourceUrl((string)newValue);
42 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
44 var imageView = (ImageView)bindable;
47 imageView._imagePropertyMap?.Find(ImageVisualProperty.URL)?.Get(out ret);
52 /// Intenal used, will never be opened.
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
56 var imageView = (ImageView)bindable;
59 PropertyMap map = (PropertyMap)newValue;
60 if (imageView.IsCreateByXaml)
62 string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
63 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
64 PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
66 if (urlValue != null) ret = urlValue.Get(out url);
67 PropertyMap mmap = new PropertyMap();
68 if (ret && url.StartsWith("*Resource*"))
70 url = url.Replace("*Resource*", resource);
71 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
75 PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
76 if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
77 if (ret && alphaMaskURL.StartsWith("*Resource*"))
79 alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
80 mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
84 PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
85 if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
86 if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
88 auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
89 mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
94 if (imageView._border == null)
96 // Image properties are changed hardly. We should ignore lazy UpdateImage
97 imageView._imagePropertyUpdatedFlag = false;
98 imageView._imagePropertyMap?.Dispose();
99 imageView._imagePropertyMap = null;
102 imageView._imagePropertyMap = new PropertyMap(map);
104 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
108 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
110 var imageView = (ImageView)bindable;
111 if (imageView._border == null)
113 PropertyMap temp = new PropertyMap();
115 // Sync as current properties.
116 imageView.UpdateImage();
117 if(imageView._imagePropertyMap != null)
119 temp.Merge(imageView._imagePropertyMap);
130 /// Intenal used, will never be opened.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
134 var imageView = (ImageView)bindable;
135 if (newValue != null)
137 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
140 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
142 var imageView = (ImageView)bindable;
144 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
148 /// Intenal used, will never be opened.
149 [EditorBrowsable(EditorBrowsableState.Never)]
150 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
152 var imageView = (ImageView)bindable;
153 if (newValue != null)
155 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
158 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
160 var imageView = (ImageView)bindable;
161 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
162 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
163 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
167 /// Intenal used, will never be opened.
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
171 var imageView = (ImageView)bindable;
172 imageView.borderSelector?.Reset(imageView);
174 if (newValue is Selector<Rectangle> selector)
176 if (selector.HasAll()) imageView.SetBorder(selector.All);
177 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
181 imageView.SetBorder((Rectangle)newValue);
184 defaultValueCreator: (bindable) =>
186 var imageView = (ImageView)bindable;
187 return imageView._border;
190 /// Intenal used, will never be opened.
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
194 var imageView = (ImageView)bindable;
195 if (newValue != null)
199 bool oldBool = (bool)oldValue;
200 bool newBool = (bool)newValue;
201 if(oldBool == newBool)
206 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
209 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
211 var imageView = (ImageView)bindable;
214 imageView._imagePropertyMap?.Find(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
219 /// Intenal used, will never be opened.
220 [EditorBrowsable(EditorBrowsableState.Never)]
221 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
223 var imageView = (ImageView)bindable;
224 if (newValue != null)
228 bool oldBool = (bool)oldValue;
229 bool newBool = (bool)newValue;
230 if(oldBool == newBool)
235 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
238 defaultValueCreator: (bindable) =>
240 var imageView = (ImageView)bindable;
243 imageView._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
248 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
249 [EditorBrowsable(EditorBrowsableState.Never)]
250 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
252 var imageView = (ImageView)bindable;
253 if (newValue != null)
257 bool oldBool = (bool)oldValue;
258 bool newBool = (bool)newValue;
259 if(oldBool == newBool)
264 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
267 defaultValueCreator: (bindable) =>
269 var imageView = (ImageView)bindable;
272 imageView._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
277 /// Intenal used, will never be opened.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
281 var imageView = (ImageView)bindable;
282 if (newValue != null)
286 bool oldBool = (bool)oldValue;
287 bool newBool = (bool)newValue;
288 if(oldBool == newBool)
293 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
296 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
298 var imageView = (ImageView)bindable;
302 imageView._imagePropertyMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
313 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
314 if (newValue != null)
316 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
319 defaultValueCreator: (bindable) =>
321 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
322 return instance.InternalImageMap;
326 /// AlphaMaskURLProperty
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
331 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
332 if (newValue != null)
334 instance.InternalAlphaMaskURL = (string)newValue;
337 defaultValueCreator: (bindable) =>
339 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
340 return instance.InternalAlphaMaskURL;
344 /// CropToMaskProperty
346 [EditorBrowsable(EditorBrowsableState.Never)]
347 public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
349 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
350 if (newValue != null)
352 instance.InternalCropToMask = (bool)newValue;
355 defaultValueCreator: (bindable) =>
357 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
358 return instance.InternalCropToMask;
362 /// FittingModeProperty
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
367 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
368 if (newValue != null)
370 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
373 defaultValueCreator: (bindable) =>
375 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
376 return instance.InternalFittingMode;
380 /// DesiredWidthProperty
382 [EditorBrowsable(EditorBrowsableState.Never)]
383 public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
385 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
386 if (newValue != null)
388 instance.InternalDesiredWidth = (int)newValue;
391 defaultValueCreator: (bindable) =>
393 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
394 return instance.InternalDesiredWidth;
398 /// DesiredHeightProperty
400 [EditorBrowsable(EditorBrowsableState.Never)]
401 public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
403 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
404 if (newValue != null)
406 instance.InternalDesiredHeight = (int)newValue;
409 defaultValueCreator: (bindable) =>
411 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
412 return instance.InternalDesiredHeight;
416 /// ReleasePolicyProperty
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
421 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
422 if (newValue != null)
424 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
427 defaultValueCreator: (bindable) =>
429 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
430 return instance.InternalReleasePolicy;
434 /// WrapModeUProperty
436 [EditorBrowsable(EditorBrowsableState.Never)]
437 public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
439 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
440 if (newValue != null)
442 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
445 defaultValueCreator: (bindable) =>
447 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
448 return instance.InternalWrapModeU;
452 /// WrapModeVProperty
454 [EditorBrowsable(EditorBrowsableState.Never)]
455 public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
457 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
458 if (newValue != null)
460 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
463 defaultValueCreator: (bindable) =>
465 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
466 return instance.InternalWrapModeV;
470 /// AdjustViewSizeProperty
472 [EditorBrowsable(EditorBrowsableState.Never)]
473 public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
475 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
476 if (newValue != null)
478 instance.adjustViewSize = (bool)newValue;
481 defaultValueCreator: (bindable) =>
483 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
484 return instance.adjustViewSize;