2 * Copyright(c) 2019 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 Tizen.NUI.BaseComponents;
24 /// A class encapsulating the transform map of the visual.
26 /// <since_tizen> 3 </since_tizen>
27 public class VisualMap : IDisposable
29 private bool disposed = false;
33 /// <since_tizen> 3 </since_tizen>
34 [Obsolete("Deprecated in API9, Will be removed in API11, Please use OutputVisualMap")]
35 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
36 protected PropertyMap _outputVisualMap = null;
39 /// The shader of the visual.
41 /// <since_tizen> 3 </since_tizen>
42 [Obsolete("Deprecated in API9, Will be removed in API11, Please use Shader")]
43 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
44 protected PropertyMap _shader = null;
45 //private PropertyMap _transform = null;
48 /// The premultipliedAlpha of the visual.
50 /// <since_tizen> 3 </since_tizen>
51 [Obsolete("Deprecated in API9, Will be removed in API11, Please use PremultipliedAlpha")]
52 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
53 protected bool? _premultipliedAlpha = null;
56 /// The mixColor of the Visual.
58 /// <since_tizen> 3 </since_tizen>
59 [Obsolete("Deprecated in API9, Will be removed in API11, Please use MixColor")]
60 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
61 protected Color _mixColor = null;
64 /// The opacity of the visual.
66 /// <since_tizen> 3 </since_tizen>
67 [Obsolete("Deprecated in API9, Will be removed in API11, Please use Opacity")]
68 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
69 protected float? _opacity = null;
72 /// The FittingMode of the visual.
74 /// <since_tizen> 5 </since_tizen>
75 [Obsolete("Deprecated in API9, Will be removed in API11, Please use VisualFittingMode")]
76 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
77 protected VisualFittingModeType? _visualFittingMode = null;
80 /// The corner radius value of the visual.
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 private float? cornerRadius = null;
86 /// The map for visual.
88 /// <since_tizen> 3 </since_tizen>
89 [Obsolete("Deprecated in API9, Will be removed in API11, Please not use _comonlyUsedMap")]
90 [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
91 protected PropertyMap _commonlyUsedMap = null;
93 private Vector2 visualSize = null;
94 private Vector2 visualOffset = null;
95 private Vector2 visualOffsetPolicy = null;
96 private Vector2 visualSizePolicy = null;
97 private Visual.AlignType? visualOrigin = null;
98 private Visual.AlignType? visualAnchorPoint = null;
100 private PropertyMap visualTransformMap = null;
102 private int? depthIndex = null;
107 /// <since_tizen> 3 </since_tizen>
113 /// Gets or sets the size of the visual.<br />
114 /// It can be either relative (percentage of the parent)
115 /// or absolute (in world units).<br />
118 /// <since_tizen> 3 </since_tizen>
123 return visualSize ?? (new Size2D(1, 1));
128 if (visualSizePolicy == null)
130 visualSizePolicy = new Vector2(1.0f, 1.0f);
137 /// Gets or sets the offset of the visual.<br />
138 /// It can be either relative (percentage of the parent)
139 /// or absolute (in world units).<br />
142 /// <since_tizen> 3 </since_tizen>
143 public Vector2 Position
147 return visualOffset ?? (new Vector2(0.0f, 0.0f));
151 visualOffset = value;
152 if (visualOffsetPolicy == null)
154 visualOffsetPolicy = new Vector2(1.0f, 1.0f);
161 /// Gets or sets the relative size of the visual<br />
162 /// (percentage [0.0f to 1.0f] of the control).<br />
165 /// <since_tizen> 3 </since_tizen>
166 public RelativeVector2 RelativeSize
170 return visualSize ?? (new RelativeVector2(1.0f, 1.0f));
175 visualSizePolicy = new Vector2(0.0f, 0.0f);
181 /// Gets or sets the relative offset of the visual<br />
182 /// (percentage [0.0f to 1.0f] of the control).<br />
185 /// <since_tizen> 3 </since_tizen>
186 public RelativeVector2 RelativePosition
190 return visualOffset ?? (new RelativeVector2(0.0f, 0.0f));
194 visualOffset = value;
195 visualOffsetPolicy = new Vector2(0.0f, 0.0f);
201 /// Gets or sets whether the x and y offset values are relative<br />
202 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
203 /// By default, both the x and the y offset are relative.<br />
206 /// <since_tizen> 3 </since_tizen>
207 public VisualTransformPolicyType PositionPolicy
211 if (visualOffsetPolicy != null && visualOffsetPolicy.X == 1.0f
212 && visualOffsetPolicy.Y == 1.0f)
214 return VisualTransformPolicyType.Absolute;
216 return VisualTransformPolicyType.Relative;
222 case VisualTransformPolicyType.Relative:
223 visualOffsetPolicy = new Vector2(0.0f, 0.0f);
225 case VisualTransformPolicyType.Absolute:
226 visualOffsetPolicy = new Vector2(1.0f, 1.0f);
229 visualOffsetPolicy = new Vector2(0.0f, 0.0f);
237 /// Gets or sets whether the x offset values are relative<br />
238 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
239 /// By default, the x offset is relative.<br />
242 /// <since_tizen> 3 </since_tizen>
243 public VisualTransformPolicyType PositionPolicyX
247 if (visualOffsetPolicy != null && visualOffsetPolicy.X == 1.0f)
249 return VisualTransformPolicyType.Absolute;
251 return VisualTransformPolicyType.Relative;
259 case VisualTransformPolicyType.Relative:
262 case VisualTransformPolicyType.Absolute:
269 visualOffsetPolicy = new Vector2(x, visualOffsetPolicy?.Y ?? 0);
276 /// Gets or sets whether the y offset values are relative<br />
277 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
278 /// By default, the y offset is relative.<br />
281 /// <since_tizen> 3 </since_tizen>
282 public VisualTransformPolicyType PositionPolicyY
286 if (visualOffsetPolicy != null && visualOffsetPolicy.Y == 1.0f)
288 return VisualTransformPolicyType.Absolute;
290 return VisualTransformPolicyType.Relative;
298 case VisualTransformPolicyType.Relative:
301 case VisualTransformPolicyType.Absolute:
308 visualOffsetPolicy = new Vector2(visualOffsetPolicy?.X ?? 0, y);
314 /// Gets or sets whether the size values of the width or the height are relative<br />
315 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
316 /// By default, offsets of both the width and the height are relative to the control's size.<br />
319 /// <since_tizen> 3 </since_tizen>
320 public VisualTransformPolicyType SizePolicy
324 if (visualSizePolicy != null && visualSizePolicy.X == 1.0f
325 && visualSizePolicy.Y == 1.0f)
327 return VisualTransformPolicyType.Absolute;
329 return VisualTransformPolicyType.Relative;
335 case VisualTransformPolicyType.Relative:
336 visualSizePolicy = new Vector2(0.0f, 0.0f);
338 case VisualTransformPolicyType.Absolute:
339 visualSizePolicy = new Vector2(1.0f, 1.0f);
342 visualSizePolicy = new Vector2(0.0f, 0.0f);
350 /// Gets or sets whether size values of the width are relative.<br />
351 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
352 /// By default, the value of the width is relative to the control's width.<br />
355 /// <since_tizen> 3 </since_tizen>
356 public VisualTransformPolicyType SizePolicyWidth
360 if (visualSizePolicy != null && visualSizePolicy.Width == 1.0f)
362 return VisualTransformPolicyType.Absolute;
364 return VisualTransformPolicyType.Relative;
371 case VisualTransformPolicyType.Relative:
374 case VisualTransformPolicyType.Absolute:
382 visualSizePolicy = new Vector2(width, visualSizePolicy?.Height ?? 0);
388 /// Gets or sets whether size values of the height are relative<br />
389 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
390 /// By default, the height value is relative to the control's height.<br />
393 /// <since_tizen> 3 </since_tizen>
394 public VisualTransformPolicyType SizePolicyHeight
398 if (visualSizePolicy != null && visualSizePolicy.Height == 1.0f)
400 return VisualTransformPolicyType.Absolute;
402 return VisualTransformPolicyType.Relative;
410 case VisualTransformPolicyType.Relative:
413 case VisualTransformPolicyType.Absolute:
420 visualSizePolicy = new Vector2(visualSizePolicy?.Width ?? 0, height);
426 /// Gets or sets the origin of the visual within its control area.<br />
427 /// By default, the origin is center.<br />
430 /// <since_tizen> 3 </since_tizen>
431 public Visual.AlignType Origin
435 return visualOrigin ?? (Visual.AlignType.Center);
439 visualOrigin = value;
445 /// Gets or sets the anchor point of the visual.<br />
446 /// By default, the anchor point is center.<br />
449 /// <since_tizen> 3 </since_tizen>
450 public Visual.AlignType AnchorPoint
454 return visualAnchorPoint ?? (Visual.AlignType.Center);
458 visualAnchorPoint = value;
464 /// Gets or sets the depth index of the visual.<br />
465 /// By default, the depth index is 0.<br />
468 /// <since_tizen> 3 </since_tizen>
469 public int DepthIndex
473 return depthIndex ?? (0);
482 /// Gets the transform map used by the visual.
484 /// <since_tizen> 3 </since_tizen>
485 public PropertyMap OutputTransformMap
489 ComposingTransformMap();
490 return visualTransformMap;
495 /// Gets the property map to create the visual.
497 /// <since_tizen> 3 </since_tizen>
498 public PropertyMap OutputVisualMap
502 ComposingPropertyMap();
503 return _outputVisualMap;
509 /// The shader to use in the visual.
511 /// <since_tizen> 3 </since_tizen>
512 public PropertyMap Shader
526 /// Enables or disables the premultiplied alpha. <br />
527 /// The premultiplied alpha is false by default unless this behavior is modified by the derived visual type.
529 /// <since_tizen> 3 </since_tizen>
530 public bool PremultipliedAlpha
534 return _premultipliedAlpha ?? (false);
538 _premultipliedAlpha = value;
544 /// Mix color is a blend color for any visual.
546 /// <since_tizen> 3 </since_tizen>
547 public Color MixColor
561 /// Opacity is the alpha component of the mix color discussed above.
563 /// <since_tizen> 3 </since_tizen>
568 return _opacity ?? (1.0f);
578 /// The fitting mode of the visual.
579 /// The default is defined by the type of visual (if it is suitable to be stretched or not).
581 /// <since_tizen> 5 </since_tizen>
582 public VisualFittingModeType VisualFittingMode
586 if (_visualFittingMode == null)
588 if (this is AnimatedImageVisual ||
589 this is MeshVisual ||
590 this is PrimitiveVisual ||
593 return VisualFittingModeType.FitKeepAspectRatio;
597 return VisualFittingModeType.Fill;
602 return (VisualFittingModeType)_visualFittingMode;
607 _visualFittingMode = value;
613 /// The corner radius of the visual.
615 [EditorBrowsable(EditorBrowsableState.Never)]
616 public float CornerRadius
620 return cornerRadius ?? (0.0f);
624 cornerRadius = value;
635 internal int VisualIndex
641 internal VisualView Parent
648 /// Suppress UpdateVisual() to update properties to Parent.
649 /// If it is set to true, UpdateVisual() is ignored unless it is called with force.
651 internal bool SuppressUpdateVisual { get; set; } = false;
653 internal void UpdateVisual(bool force = false)
655 if (VisualIndex > 0 && (!SuppressUpdateVisual || force))
657 NUILog.Debug("UpdateVisual()! VisualIndex=" + VisualIndex);
658 Parent.UpdateVisual(VisualIndex, Name, this);
662 NUILog.Debug("VisualIndex was not set");
667 /// Compose the out visual map.
669 /// <since_tizen> 3 </since_tizen>
670 protected virtual void ComposingPropertyMap()
672 if (null == _outputVisualMap)
674 _outputVisualMap = new PropertyMap();
679 PropertyValue temp = new PropertyValue(_shader);
680 _outputVisualMap.Add(Visual.Property.Shader, temp);
683 if (_premultipliedAlpha != null)
685 PropertyValue temp = new PropertyValue((bool)_premultipliedAlpha);
686 _outputVisualMap.Add(Visual.Property.PremultipliedAlpha, temp);
689 if (_mixColor != null)
691 PropertyValue temp = new PropertyValue(_mixColor);
692 _outputVisualMap.Add(Visual.Property.MixColor, temp);
695 if (_opacity != null)
697 PropertyValue temp = new PropertyValue((float)_opacity);
698 _outputVisualMap.Add(Visual.Property.Opacity, temp);
701 if (_visualFittingMode != null)
703 PropertyValue temp = new PropertyValue((int)_visualFittingMode);
704 _outputVisualMap.Add(Visual.Property.VisualFittingMode, temp);
707 if (cornerRadius != null)
709 PropertyValue temp = new PropertyValue((int)cornerRadius);
710 _outputVisualMap.Add(Visual.Property.CornerRadius, temp);
715 private void ComposingTransformMap()
717 visualTransformMap = new PropertyMap();
718 if (visualSize != null)
720 PropertyValue temp = new PropertyValue(visualSize);
721 visualTransformMap.Add((int)VisualTransformPropertyType.Size, temp);
724 if (visualOffset != null)
726 PropertyValue temp = new PropertyValue(visualOffset);
727 visualTransformMap.Add((int)VisualTransformPropertyType.Offset, temp);
730 if (visualOffsetPolicy != null)
732 PropertyValue temp = new PropertyValue(visualOffsetPolicy);
733 visualTransformMap.Add((int)VisualTransformPropertyType.OffsetPolicy, temp);
736 if (visualSizePolicy != null)
738 PropertyValue temp = new PropertyValue(visualSizePolicy);
739 visualTransformMap.Add((int)VisualTransformPropertyType.SizePolicy, temp);
742 if (visualOrigin != null)
744 PropertyValue temp = new PropertyValue((int)visualOrigin);
745 visualTransformMap.Add((int)VisualTransformPropertyType.Origin, temp);
748 if (visualAnchorPoint != null)
750 PropertyValue temp = new PropertyValue((int)visualAnchorPoint);
751 visualTransformMap.Add((int)VisualTransformPropertyType.AnchorPoint, temp);
756 [EditorBrowsable(EditorBrowsableState.Never)]
757 protected virtual void Dispose(bool disposing)
765 _commonlyUsedMap?.Dispose();
766 _mixColor?.Dispose();
767 _outputVisualMap?.Dispose();
769 visualOffset?.Dispose();
770 visualOffsetPolicy?.Dispose();
771 visualSize?.Dispose();
772 visualSizePolicy?.Dispose();
773 visualTransformMap?.Dispose();
778 [EditorBrowsable(EditorBrowsableState.Never)]
779 public void Dispose()
782 global::System.GC.SuppressFinalize(this);