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 // Get current properties force.
114 // TODO: Need to make some flag that we only need cached property map.
115 PropertyMap temp = new PropertyMap();
116 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
125 /// Intenal used, will never be opened.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
129 var imageView = (ImageView)bindable;
130 if (newValue != null)
132 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
135 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
137 var imageView = (ImageView)bindable;
139 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
143 /// Intenal used, will never be opened.
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
147 var imageView = (ImageView)bindable;
148 if (newValue != null)
150 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
153 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
155 var imageView = (ImageView)bindable;
156 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
157 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
158 RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
162 /// Intenal used, will never be opened.
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
166 var imageView = (ImageView)bindable;
167 imageView.borderSelector?.Reset(imageView);
169 if (newValue is Selector<Rectangle> selector)
171 if (selector.HasAll()) imageView.SetBorder(selector.All);
172 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
176 imageView.SetBorder((Rectangle)newValue);
179 defaultValueCreator: (bindable) =>
181 var imageView = (ImageView)bindable;
182 return imageView._border;
185 /// Intenal used, will never be opened.
186 [EditorBrowsable(EditorBrowsableState.Never)]
187 public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
189 var imageView = (ImageView)bindable;
190 if (newValue != null)
194 bool oldBool = (bool)oldValue;
195 bool newBool = (bool)newValue;
196 if(oldBool == newBool)
201 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
204 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
206 var imageView = (ImageView)bindable;
209 imageView._imagePropertyMap?.Find(NpatchImageVisualProperty.BorderOnly)?.Get(out ret);
214 /// Intenal used, will never be opened.
215 [EditorBrowsable(EditorBrowsableState.Never)]
216 public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
218 var imageView = (ImageView)bindable;
219 if (newValue != null)
223 bool oldBool = (bool)oldValue;
224 bool newBool = (bool)newValue;
225 if(oldBool == newBool)
230 imageView.UpdateImage(ImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
233 defaultValueCreator: (bindable) =>
235 var imageView = (ImageView)bindable;
238 imageView._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
243 /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
244 [EditorBrowsable(EditorBrowsableState.Never)]
245 public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
247 var imageView = (ImageView)bindable;
248 if (newValue != 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._imagePropertyMap?.Find(ImageVisualProperty.SynchronousLoading)?.Get(out ret);
272 /// Intenal used, will never be opened.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
276 var imageView = (ImageView)bindable;
277 if (newValue != null)
281 bool oldBool = (bool)oldValue;
282 bool newBool = (bool)newValue;
283 if(oldBool == newBool)
288 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
291 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
293 var imageView = (ImageView)bindable;
297 imageView._imagePropertyMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public static readonly BindableProperty ImageMapProperty = BindableProperty.Create(nameof(ImageMap), typeof(Tizen.NUI.PropertyMap), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
308 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
309 if (newValue != null)
311 instance.InternalImageMap = (Tizen.NUI.PropertyMap)newValue;
314 defaultValueCreator: (bindable) =>
316 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
317 return instance.InternalImageMap;
321 /// AlphaMaskURLProperty
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public static readonly BindableProperty AlphaMaskURLProperty = BindableProperty.Create(nameof(AlphaMaskURL), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
326 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
327 if (newValue != null)
329 instance.InternalAlphaMaskURL = (string)newValue;
332 defaultValueCreator: (bindable) =>
334 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
335 return instance.InternalAlphaMaskURL;
339 /// CropToMaskProperty
341 [EditorBrowsable(EditorBrowsableState.Never)]
342 public static readonly BindableProperty CropToMaskProperty = BindableProperty.Create(nameof(CropToMask), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
344 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
345 if (newValue != null)
347 instance.InternalCropToMask = (bool)newValue;
350 defaultValueCreator: (bindable) =>
352 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
353 return instance.InternalCropToMask;
357 /// FittingModeProperty
359 [EditorBrowsable(EditorBrowsableState.Never)]
360 public static readonly BindableProperty FittingModeProperty = BindableProperty.Create(nameof(FittingMode), typeof(FittingModeType), typeof(ImageView), default(FittingModeType), propertyChanged: (bindable, oldValue, newValue) =>
362 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
363 if (newValue != null)
365 instance.InternalFittingMode = (Tizen.NUI.FittingModeType)newValue;
368 defaultValueCreator: (bindable) =>
370 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
371 return instance.InternalFittingMode;
375 /// DesiredWidthProperty
377 [EditorBrowsable(EditorBrowsableState.Never)]
378 public static readonly BindableProperty DesiredWidthProperty = BindableProperty.Create(nameof(DesiredWidth), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
380 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
381 if (newValue != null)
383 instance.InternalDesiredWidth = (int)newValue;
386 defaultValueCreator: (bindable) =>
388 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
389 return instance.InternalDesiredWidth;
393 /// DesiredHeightProperty
395 [EditorBrowsable(EditorBrowsableState.Never)]
396 public static readonly BindableProperty DesiredHeightProperty = BindableProperty.Create(nameof(DesiredHeight), typeof(int), typeof(ImageView), 0, propertyChanged: (bindable, oldValue, newValue) =>
398 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
399 if (newValue != null)
401 instance.InternalDesiredHeight = (int)newValue;
404 defaultValueCreator: (bindable) =>
406 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
407 return instance.InternalDesiredHeight;
411 /// ReleasePolicyProperty
413 [EditorBrowsable(EditorBrowsableState.Never)]
414 public static readonly BindableProperty ReleasePolicyProperty = BindableProperty.Create(nameof(ReleasePolicy), typeof(ReleasePolicyType), typeof(ImageView), default(ReleasePolicyType), propertyChanged: (bindable, oldValue, newValue) =>
416 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
417 if (newValue != null)
419 instance.InternalReleasePolicy = (Tizen.NUI.ReleasePolicyType)newValue;
422 defaultValueCreator: (bindable) =>
424 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
425 return instance.InternalReleasePolicy;
429 /// WrapModeUProperty
431 [EditorBrowsable(EditorBrowsableState.Never)]
432 public static readonly BindableProperty WrapModeUProperty = BindableProperty.Create(nameof(WrapModeU), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
434 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
435 if (newValue != null)
437 instance.InternalWrapModeU = (Tizen.NUI.WrapModeType)newValue;
440 defaultValueCreator: (bindable) =>
442 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
443 return instance.InternalWrapModeU;
447 /// WrapModeVProperty
449 [EditorBrowsable(EditorBrowsableState.Never)]
450 public static readonly BindableProperty WrapModeVProperty = BindableProperty.Create(nameof(WrapModeV), typeof(Tizen.NUI.WrapModeType), typeof(ImageView), default(WrapModeType), propertyChanged: (bindable, oldValue, newValue) =>
452 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
453 if (newValue != null)
455 instance.InternalWrapModeV = (Tizen.NUI.WrapModeType)newValue;
458 defaultValueCreator: (bindable) =>
460 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
461 return instance.InternalWrapModeV;
465 /// AdjustViewSizeProperty
467 [EditorBrowsable(EditorBrowsableState.Never)]
468 public static readonly BindableProperty AdjustViewSizeProperty = BindableProperty.Create(nameof(AdjustViewSize), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
470 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
471 if (newValue != null)
473 instance.adjustViewSize = (bool)newValue;
476 defaultValueCreator: (bindable) =>
478 var instance = (Tizen.NUI.BaseComponents.ImageView)bindable;
479 return instance.adjustViewSize;