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 Object.InternalSetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, (bool)newValue);
150 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
152 var imageView = (ImageView)bindable;
155 if (imageView.imagePropertyUpdatedFlag)
157 // If imageView Property still not send to the dali, just get cached property.
158 imageView.GetCachedImageVisualProperty(Visual.Property.PremultipliedAlpha)?.Get(out temp);
162 // Else, PremultipliedAlpha may not setuped in cached property. Get value from current ImageView.
163 temp = Object.InternalGetPropertyBool(imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha);
168 /// Intenal used, will never be opened.
169 [EditorBrowsable(EditorBrowsableState.Never)]
170 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
172 var imageView = (ImageView)bindable;
173 if (newValue != null)
176 Object.InternalSetPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, ((RelativeVector4)newValue).SwigCPtr);
179 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
181 var imageView = (ImageView)bindable;
183 if (imageView.internalPixelArea == null)
185 imageView.internalPixelArea = new RelativeVector4(imageView.OnPixelAreaChanged, 0, 0, 0, 0);
187 Object.InternalRetrievingPropertyVector4(imageView.SwigCPtr, ImageView.Property.PixelArea, imageView.internalPixelArea.SwigCPtr);
188 return imageView.internalPixelArea;
191 /// Intenal used, will never be opened.
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
195 var imageView = (ImageView)bindable;
196 imageView.borderSelector?.Reset(imageView);
198 if (newValue is Selector<Rectangle> selector)
200 if (selector.HasAll()) imageView.SetBorder(selector.All);
201 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
205 imageView.SetBorder((Rectangle)newValue);
208 defaultValueCreator: (bindable) =>
210 var imageView = (ImageView)bindable;
211 return imageView._border;
214 /// Intenal used, will never be opened.
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
218 var imageView = (ImageView)bindable;
219 if (newValue != null)
221 if (oldValue != null)
223 bool oldBool = (bool)oldValue;
224 bool newBool = (bool)newValue;
225 if (oldBool == newBool)
230 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
233 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
235 var imageView = (ImageView)bindable;
238 imageView.GetCachedImageVisualProperty(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
243 /// Intenal used, will never be opened.
244 [EditorBrowsable(EditorBrowsableState.Never)]
245 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
247 var imageView = (ImageView)bindable;
248 if (newValue != null)
250 if (oldValue != null)
252 bool oldBool = (bool)oldValue;
253 bool newBool = (bool)newValue;
254 if (oldBool == newBool)
259 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
262 defaultValueCreator: (bindable) =>
264 var imageView = (ImageView)bindable;
267 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
272 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
276 var imageView = (ImageView)bindable;
277 if (newValue != null)
279 if (oldValue != null)
281 bool oldBool = (bool)oldValue;
282 bool newBool = (bool)newValue;
283 if (oldBool == newBool)
288 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
291 defaultValueCreator: (bindable) =>
293 var imageView = (ImageView)bindable;
296 imageView.GetCachedImageVisualProperty(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
301 /// Intenal used, will never be opened.
302 [EditorBrowsable(EditorBrowsableState.Never)]
303 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
305 var imageView = (ImageView)bindable;
306 if (newValue != null)
308 if (oldValue != null)
310 bool oldBool = (bool)oldValue;
311 bool newBool = (bool)newValue;
312 if (oldBool == newBool)
317 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
320 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
322 var imageView = (ImageView)bindable;
326 imageView.GetCachedImageVisualProperty(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
332 /// MaskingModeProperty
334 [EditorBrowsable(EditorBrowsableState.Never)]
335 public static readonly BindableProperty MaskingModeProperty = BindableProperty.Create(nameof(MaskingMode), typeof(MaskingModeType), typeof(ImageView), default(MaskingModeType), propertyChanged: (bindable, oldValue, newValue) =>
337 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
338 if (newValue != null)
340 instance.InternalMaskingMode = (ImageView.MaskingModeType)newValue;
343 defaultValueCreator: (bindable) =>
345 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
346 return instance.InternalMaskingMode;
352 [EditorBrowsable(EditorBrowsableState.Never)]
353 public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
355 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
356 if (newValue != null)
358 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
361 defaultValueCreator: (bindable) =>
363 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
364 return instance.InternalImageMap;
368 /// AlphaMaskURLProperty
370 [EditorBrowsable(EditorBrowsableState.Never)]
371 public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
373 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
374 if (newValue != null)
376 instance.InternalAlphaMaskURL = (string)newValue;
379 defaultValueCreator: (bindable) =>
381 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
382 return instance.InternalAlphaMaskURL;
386 /// CropToMaskProperty
388 [EditorBrowsable(EditorBrowsableState.Never)]
389 public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
391 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
392 if (newValue != null)
394 instance.InternalCropToMask = (bool)newValue;
397 defaultValueCreator: (bindable) =>
399 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
400 return instance.InternalCropToMask;
404 /// FittingModeProperty
406 [EditorBrowsable(EditorBrowsableState.Never)]
407 public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
409 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
410 if (newValue != null)
412 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
415 defaultValueCreator: (bindable) =>
417 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
418 return instance.InternalFittingMode;
422 /// DesiredWidthProperty
424 [EditorBrowsable(EditorBrowsableState.Never)]
425 public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
427 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
428 if (newValue != null)
430 instance.InternalDesiredWidth = (int)newValue;
433 defaultValueCreator: (bindable) =>
435 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
436 return instance.InternalDesiredWidth;
440 /// DesiredHeightProperty
442 [EditorBrowsable(EditorBrowsableState.Never)]
443 public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
445 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
446 if (newValue != null)
448 instance.InternalDesiredHeight = (int)newValue;
451 defaultValueCreator: (bindable) =>
453 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
454 return instance.InternalDesiredHeight;
458 /// ReleasePolicyProperty
460 [EditorBrowsable(EditorBrowsableState.Never)]
461 public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
463 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
464 if (newValue != null)
466 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
469 defaultValueCreator: (bindable) =>
471 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
472 return instance.InternalReleasePolicy;
476 /// WrapModeUProperty
478 [EditorBrowsable(EditorBrowsableState.Never)]
479 public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
481 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
482 if (newValue != null)
484 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
487 defaultValueCreator: (bindable) =>
489 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
490 return instance.InternalWrapModeU;
494 /// WrapModeVProperty
496 [EditorBrowsable(EditorBrowsableState.Never)]
497 public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
499 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
500 if (newValue != null)
502 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
505 defaultValueCreator: (bindable) =>
507 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
508 return instance.InternalWrapModeV;
512 /// AdjustViewSizeProperty
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
517 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
518 if (newValue != null)
520 instance.adjustViewSize = (bool)newValue;
523 defaultValueCreator: (bindable) =>
525 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
526 return instance.adjustViewSize;