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.
17 using System.ComponentModel;
18 using Tizen.NUI.BaseComponents;
23 /// A class encapsulating the transform map of the visual.
25 /// <since_tizen> 3 </since_tizen>
26 public class VisualMap
31 /// <since_tizen> 3 </since_tizen>
32 protected PropertyMap _outputVisualMap = null;
35 /// The shader of the visual.
37 /// <since_tizen> 3 </since_tizen>
38 protected PropertyMap _shader = null;
39 //private PropertyMap _transform = null;
42 /// The premultipliedAlpha of the visual.
44 /// <since_tizen> 3 </since_tizen>
45 protected bool? _premultipliedAlpha = null;
48 /// The mixColor of the Visual.
50 /// <since_tizen> 3 </since_tizen>
51 protected Color _mixColor = null;
54 /// The opacity of the visual.
56 /// <since_tizen> 3 </since_tizen>
57 protected float? _opacity = null;
60 /// The FittingMode of the visual.
62 /// <since_tizen> 5 </since_tizen>
63 protected VisualFittingModeType? _visualFittingMode = null;
66 /// The corner radius value of the visual.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 private float? cornerRadius = null;
72 /// The map for visual.
74 /// <since_tizen> 3 </since_tizen>
75 protected PropertyMap _commonlyUsedMap = null;
77 private Vector2 _visualSize = null;
78 private Vector2 _visualOffset = null;
79 private Vector2 _visualOffsetPolicy = null;
80 private Vector2 _visualSizePolicy = null;
81 private Visual.AlignType? _visualOrigin = null;
82 private Visual.AlignType? _visualAnchorPoint = null;
84 private PropertyMap _visualTransformMap = null;
86 private int? _depthIndex = null;
91 /// <since_tizen> 3 </since_tizen>
97 /// Gets or sets the size of the visual.<br />
98 /// It can be either relative (percentage of the parent)
99 /// or absolute (in world units).<br />
102 /// <since_tizen> 3 </since_tizen>
107 return _visualSize ?? (new Size2D(1, 1));
112 if (_visualSizePolicy == null)
114 _visualSizePolicy = new Vector2(1.0f, 1.0f);
121 /// Gets or sets the offset of the visual.<br />
122 /// It can be either relative (percentage of the parent)
123 /// or absolute (in world units).<br />
126 /// <since_tizen> 3 </since_tizen>
127 public Vector2 Position
131 return _visualOffset ?? (new Vector2(0.0f, 0.0f));
135 _visualOffset = value;
136 if (_visualOffsetPolicy == null)
138 _visualOffsetPolicy = new Vector2(1.0f, 1.0f);
145 /// Gets or sets the relative size of the visual<br />
146 /// (percentage [0.0f to 1.0f] of the control).<br />
149 /// <since_tizen> 3 </since_tizen>
150 public RelativeVector2 RelativeSize
154 return _visualSize ?? (new RelativeVector2(1.0f, 1.0f));
159 _visualSizePolicy = new Vector2(0.0f, 0.0f);
165 /// Gets or sets the relative offset of the visual<br />
166 /// (percentage [0.0f to 1.0f] of the control).<br />
169 /// <since_tizen> 3 </since_tizen>
170 public RelativeVector2 RelativePosition
174 return _visualOffset ?? (new RelativeVector2(0.0f, 0.0f));
178 _visualOffset = value;
179 _visualOffsetPolicy = new Vector2(0.0f, 0.0f);
185 /// Gets or sets whether the x and y offset values are relative<br />
186 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
187 /// By default, both the x and the y offset are relative.<br />
190 /// <since_tizen> 3 </since_tizen>
191 public VisualTransformPolicyType PositionPolicy
195 if (_visualOffsetPolicy != null && _visualOffsetPolicy.X == 1.0f
196 && _visualOffsetPolicy.Y == 1.0f)
198 return VisualTransformPolicyType.Absolute;
200 return VisualTransformPolicyType.Relative;
206 case VisualTransformPolicyType.Relative:
207 _visualOffsetPolicy = new Vector2(0.0f, 0.0f);
209 case VisualTransformPolicyType.Absolute:
210 _visualOffsetPolicy = new Vector2(1.0f, 1.0f);
213 _visualOffsetPolicy = new Vector2(0.0f, 0.0f);
221 /// Gets or sets whether the x offset values are relative<br />
222 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
223 /// By default, the x offset is relative.<br />
226 /// <since_tizen> 3 </since_tizen>
227 public VisualTransformPolicyType PositionPolicyX
231 if (_visualOffsetPolicy != null && _visualOffsetPolicy.X == 1.0f)
233 return VisualTransformPolicyType.Absolute;
235 return VisualTransformPolicyType.Relative;
243 case VisualTransformPolicyType.Relative:
246 case VisualTransformPolicyType.Absolute:
253 _visualOffsetPolicy = new Vector2(x, _visualOffsetPolicy?.Y ?? 0);
260 /// Gets or sets whether the y offset values are relative<br />
261 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
262 /// By default, the y offset is relative.<br />
265 /// <since_tizen> 3 </since_tizen>
266 public VisualTransformPolicyType PositionPolicyY
270 if (_visualOffsetPolicy != null && _visualOffsetPolicy.Y == 1.0f)
272 return VisualTransformPolicyType.Absolute;
274 return VisualTransformPolicyType.Relative;
282 case VisualTransformPolicyType.Relative:
285 case VisualTransformPolicyType.Absolute:
292 _visualOffsetPolicy = new Vector2(_visualOffsetPolicy?.X ?? 0, y);
298 /// Gets or sets whether the size values of the width or the height are relative<br />
299 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
300 /// By default, offsets of both the width and the height are relative to the control's size.<br />
303 /// <since_tizen> 3 </since_tizen>
304 public VisualTransformPolicyType SizePolicy
308 if (_visualSizePolicy != null && _visualSizePolicy.X == 1.0f
309 && _visualSizePolicy.Y == 1.0f)
311 return VisualTransformPolicyType.Absolute;
313 return VisualTransformPolicyType.Relative;
319 case VisualTransformPolicyType.Relative:
320 _visualSizePolicy = new Vector2(0.0f, 0.0f);
322 case VisualTransformPolicyType.Absolute:
323 _visualSizePolicy = new Vector2(1.0f, 1.0f);
326 _visualSizePolicy = new Vector2(0.0f, 0.0f);
334 /// Gets or sets whether size values of the width are relative.<br />
335 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
336 /// By default, the value of the width is relative to the control's width.<br />
339 /// <since_tizen> 3 </since_tizen>
340 public VisualTransformPolicyType SizePolicyWidth
344 if (_visualSizePolicy != null && _visualSizePolicy.Width == 1.0f)
346 return VisualTransformPolicyType.Absolute;
348 return VisualTransformPolicyType.Relative;
355 case VisualTransformPolicyType.Relative:
358 case VisualTransformPolicyType.Absolute:
366 _visualSizePolicy = new Vector2(width, _visualSizePolicy?.Height ?? 0);
372 /// Gets or sets whether size values of the height are relative<br />
373 /// (percentage [0.0f to 1.0f] of the control) or absolute (in world units).<br />
374 /// By default, the height value is relative to the control's height.<br />
377 /// <since_tizen> 3 </since_tizen>
378 public VisualTransformPolicyType SizePolicyHeight
382 if (_visualSizePolicy != null && _visualSizePolicy.Height == 1.0f)
384 return VisualTransformPolicyType.Absolute;
386 return VisualTransformPolicyType.Relative;
394 case VisualTransformPolicyType.Relative:
397 case VisualTransformPolicyType.Absolute:
404 _visualSizePolicy = new Vector2(_visualSizePolicy?.Width ?? 0, height);
410 /// Gets or sets the origin of the visual within its control area.<br />
411 /// By default, the origin is center.<br />
414 /// <since_tizen> 3 </since_tizen>
415 public Visual.AlignType Origin
419 return _visualOrigin ?? (Visual.AlignType.Center);
423 _visualOrigin = value;
429 /// Gets or sets the anchor point of the visual.<br />
430 /// By default, the anchor point is center.<br />
433 /// <since_tizen> 3 </since_tizen>
434 public Visual.AlignType AnchorPoint
438 return _visualAnchorPoint ?? (Visual.AlignType.Center);
442 _visualAnchorPoint = value;
448 /// Gets or sets the depth index of the visual.<br />
449 /// By default, the depth index is 0.<br />
452 /// <since_tizen> 3 </since_tizen>
453 public int DepthIndex
457 return _depthIndex ?? (0);
466 /// Gets the transform map used by the visual.
468 /// <since_tizen> 3 </since_tizen>
469 public PropertyMap OutputTransformMap
473 ComposingTransformMap();
474 return _visualTransformMap;
479 /// Gets the property map to create the visual.
481 /// <since_tizen> 3 </since_tizen>
482 public PropertyMap OutputVisualMap
486 ComposingPropertyMap();
487 return _outputVisualMap;
493 /// The shader to use in the visual.
495 /// <since_tizen> 3 </since_tizen>
496 public PropertyMap Shader
510 /// Enables or disables the premultiplied alpha. <br />
511 /// The premultiplied alpha is false by default unless this behavior is modified by the derived visual type.
513 /// <since_tizen> 3 </since_tizen>
514 public bool PremultipliedAlpha
518 return _premultipliedAlpha ?? (false);
522 _premultipliedAlpha = value;
528 /// Mix color is a blend color for any visual.
530 /// <since_tizen> 3 </since_tizen>
531 public Color MixColor
545 /// Opacity is the alpha component of the mix color discussed above.
547 /// <since_tizen> 3 </since_tizen>
552 return _opacity ?? (1.0f);
562 /// The fitting mode of the visual.
563 /// The default is defined by the type of visual (if it is suitable to be stretched or not).
565 /// <since_tizen> 5 </since_tizen>
566 public VisualFittingModeType VisualFittingMode
570 if (_visualFittingMode == null)
572 if (this is AnimatedImageVisual ||
573 this is MeshVisual ||
574 this is PrimitiveVisual ||
577 return VisualFittingModeType.FitKeepAspectRatio;
581 return VisualFittingModeType.Fill;
586 return (VisualFittingModeType)_visualFittingMode;
591 _visualFittingMode = value;
597 /// The corner radius of the visual.
599 [EditorBrowsable(EditorBrowsableState.Never)]
600 public float CornerRadius
604 return cornerRadius ?? (0.0f);
608 cornerRadius = value;
619 internal int VisualIndex
625 internal VisualView Parent
632 /// Suppress UpdateVisual() to update properties to Parent.
633 /// If it is set to true, UpdateVisual() is ignored unless it is called with force.
635 internal bool SuppressUpdateVisual { get; set; } = false;
637 internal void UpdateVisual(bool force = false)
639 if (VisualIndex > 0 && (!SuppressUpdateVisual || force))
641 NUILog.Debug("UpdateVisual()! VisualIndex=" + VisualIndex);
642 Parent.UpdateVisual(VisualIndex, Name, this);
646 NUILog.Debug("VisualIndex was not set");
651 /// Compose the out visual map.
653 /// <since_tizen> 3 </since_tizen>
654 protected virtual void ComposingPropertyMap()
656 if (null == _outputVisualMap)
658 _outputVisualMap = new PropertyMap();
661 if (_shader != null) { _outputVisualMap.Add(Visual.Property.Shader, new PropertyValue(_shader)); }
662 if (_premultipliedAlpha != null) { _outputVisualMap.Add(Visual.Property.PremultipliedAlpha, new PropertyValue((bool)_premultipliedAlpha)); }
663 if (_mixColor != null) { _outputVisualMap.Add(Visual.Property.MixColor, new PropertyValue(_mixColor)); }
664 if (_opacity != null) { _outputVisualMap.Add(Visual.Property.Opacity, new PropertyValue((float)_opacity)); }
665 if (_visualFittingMode != null) { _outputVisualMap.Add(Visual.Property.VisualFittingMode, new PropertyValue((int)_visualFittingMode)); }
666 if (cornerRadius != null) { _outputVisualMap.Add(Visual.Property.CornerRadius, new PropertyValue((int)cornerRadius)); }
669 private void ComposingTransformMap()
671 _visualTransformMap = new PropertyMap();
672 if (_visualSize != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.Size, new PropertyValue(_visualSize)); }
673 if (_visualOffset != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.Offset, new PropertyValue(_visualOffset)); }
674 if (_visualOffsetPolicy != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.OffsetPolicy, new PropertyValue(_visualOffsetPolicy)); }
675 if (_visualSizePolicy != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.SizePolicy, new PropertyValue(_visualSizePolicy)); }
676 if (_visualOrigin != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.Origin, new PropertyValue((int)_visualOrigin)); }
677 if (_visualAnchorPoint != null) { _visualTransformMap.Add((int)VisualTransformPropertyType.AnchorPoint, new PropertyValue((int)_visualAnchorPoint)); }