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.GetCachedImageVisualProperty(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.cachedImagePropertyMap?.Dispose();
99 imageView.cachedImagePropertyMap = null;
100 imageView.MergeCachedImageVisualProperty(map);
102 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
106 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
108 var imageView = (ImageView)bindable;
109 if (imageView._border == null)
111 // Sync as current properties
112 imageView.UpdateImage();
114 // Get current properties force.
115 PropertyMap returnValue = new PropertyMap();
116 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(returnValue);
118 // Update cached property map
119 if (returnValue != null)
121 imageView.MergeCachedImageVisualProperty(returnValue);
131 /// Intenal used, will never be opened.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
135 var imageView = (ImageView)bindable;
136 if (newValue != null)
138 if (imageView.imagePropertyUpdatedFlag)
140 // If imageView Property still not send to the dali, Append cached property.
141 imageView.UpdateImage(Visual.Property.PremultipliedAlpha, new PropertyValue((bool)newValue));
145 // Else, we don't need to re-create view. Get value from current ImageView.
146 #if NUI_PROPERTY_CHANGE_2
147 Object.InternalSetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, (bool)newValue);
149 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
154 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
156 var imageView = (ImageView)bindable;
159 if (imageView.imagePropertyUpdatedFlag)
161 // If imageView Property still not send to the dali, just get cached property.
162 imageView.GetCachedImageVisualProperty(Visual.Property.PremultipliedAlpha)?.Get(out temp);
166 // Else, PremultipliedAlpha may not setuped in cached property. Get value from current ImageView.
167 #if NUI_PROPERTY_CHANGE_2
168 temp = Object.InternalGetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha);
170 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
176 /// Intenal used, will never be opened.
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
180 var imageView = (ImageView)bindable;
181 if (newValue != null)
183 #if NUI_PROPERTY_CHANGE_2
184 Object.InternalSetPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, ((RelativeVector4)newValue).SwigCPtr);
186 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
190 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
192 var imageView = (ImageView)bindable;
193 #if NUI_PROPERTY_CHANGE_2
194 if (imageView.internalPixelArea == null)
196 imageView.internalPixelArea = new RelativeVector4(imageView.OnPixelAreaChanged, 0, 0, 0, 0);
198 Object.InternalRetrievingPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, imageView.internalPixelArea.SwigCPtr);
199 return imageView.internalPixelArea;
201 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
202 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
203 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
208 /// Intenal used, will never be opened.
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
212 var imageView = (ImageView)bindable;
213 imageView.borderSelector?.Reset(imageView);
215 if (newValue is Selector<Rectangle> selector)
217 if (selector.HasAll()) imageView.SetBorder(selector.All);
218 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
222 imageView.SetBorder((Rectangle)newValue);
225 defaultValueCreator: (bindable) =>
227 var imageView = (ImageView)bindable;
228 return imageView._border;
231 /// Intenal used, will never be opened.
232 [EditorBrowsable(EditorBrowsableState.Never)]
233 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
235 var imageView = (ImageView)bindable;
236 if (newValue != null)
238 if (oldValue != null)
240 bool oldBool = (bool)oldValue;
241 bool newBool = (bool)newValue;
242 if (oldBool == newBool)
247 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
250 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
252 var imageView = (ImageView)bindable;
255 imageView.GetCachedImageVisualProperty(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
260 /// Intenal used, will never be opened.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
264 var imageView = (ImageView)bindable;
265 if (newValue != null)
267 if (oldValue != null)
269 bool oldBool = (bool)oldValue;
270 bool newBool = (bool)newValue;
271 if (oldBool == newBool)
276 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
279 defaultValueCreator: (bindable) =>
281 var imageView = (ImageView)bindable;
284 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
289 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
290 [EditorBrowsable(EditorBrowsableState.Never)]
291 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
293 var imageView = (ImageView)bindable;
294 if (newValue != null)
296 if (oldValue != null)
298 bool oldBool = (bool)oldValue;
299 bool newBool = (bool)newValue;
300 if (oldBool == newBool)
305 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
308 defaultValueCreator: (bindable) =>
310 var imageView = (ImageView)bindable;
313 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
318 /// Intenal used, will never be opened.
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
322 var imageView = (ImageView)bindable;
323 if (newValue != null)
325 if (oldValue != null)
327 bool oldBool = (bool)oldValue;
328 bool newBool = (bool)newValue;
329 if (oldBool == newBool)
334 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
337 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
339 var imageView = (ImageView)bindable;
343 imageView.GetCachedImageVisualProperty(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
349 /// MaskingModeProperty
351 [EditorBrowsable(EditorBrowsableState.Never)]
352 public static readonly BindableProperty MaskingModeProperty = BindableProperty.Create(nameof(MaskingMode), typeof(MaskingModeType), typeof(ImageView), default(MaskingModeType), propertyChanged: (bindable, oldValue, newValue) =>
354 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
355 if (newValue != null)
357 instance.InternalMaskingMode = (ImageView.MaskingModeType)newValue;
360 defaultValueCreator: (bindable) =>
362 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
363 return instance.InternalMaskingMode;
369 [EditorBrowsable(EditorBrowsableState.Never)]
370 public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
372 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
373 if (newValue != null)
375 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
378 defaultValueCreator: (bindable) =>
380 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
381 return instance.InternalImageMap;
385 /// AlphaMaskURLProperty
387 [EditorBrowsable(EditorBrowsableState.Never)]
388 public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
390 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
391 if (newValue != null)
393 instance.InternalAlphaMaskURL = (string)newValue;
396 defaultValueCreator: (bindable) =>
398 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
399 return instance.InternalAlphaMaskURL;
403 /// CropToMaskProperty
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
408 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
409 if (newValue != null)
411 instance.InternalCropToMask = (bool)newValue;
414 defaultValueCreator: (bindable) =>
416 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
417 return instance.InternalCropToMask;
421 /// FittingModeProperty
423 [EditorBrowsable(EditorBrowsableState.Never)]
424 public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
426 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
427 if (newValue != null)
429 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
432 defaultValueCreator: (bindable) =>
434 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
435 return instance.InternalFittingMode;
439 /// DesiredWidthProperty
441 [EditorBrowsable(EditorBrowsableState.Never)]
442 public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
444 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
445 if (newValue != null)
447 instance.InternalDesiredWidth = (int)newValue;
450 defaultValueCreator: (bindable) =>
452 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
453 return instance.InternalDesiredWidth;
457 /// DesiredHeightProperty
459 [EditorBrowsable(EditorBrowsableState.Never)]
460 public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
462 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
463 if (newValue != null)
465 instance.InternalDesiredHeight = (int)newValue;
468 defaultValueCreator: (bindable) =>
470 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
471 return instance.InternalDesiredHeight;
475 /// ReleasePolicyProperty
477 [EditorBrowsable(EditorBrowsableState.Never)]
478 public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
480 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
481 if (newValue != null)
483 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
486 defaultValueCreator: (bindable) =>
488 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
489 return instance.InternalReleasePolicy;
493 /// WrapModeUProperty
495 [EditorBrowsable(EditorBrowsableState.Never)]
496 public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
498 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
499 if (newValue != null)
501 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
504 defaultValueCreator: (bindable) =>
506 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
507 return instance.InternalWrapModeU;
511 /// WrapModeVProperty
513 [EditorBrowsable(EditorBrowsableState.Never)]
514 public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
516 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
517 if (newValue != null)
519 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
522 defaultValueCreator: (bindable) =>
524 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
525 return instance.InternalWrapModeV;
529 /// AdjustViewSizeProperty
531 [EditorBrowsable(EditorBrowsableState.Never)]
532 public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
534 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
535 if (newValue != null)
537 instance.adjustViewSize = (bool)newValue;
540 defaultValueCreator: (bindable) =>
542 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
543 return instance.adjustViewSize;