*
*/
- using System.ComponentModel;
+using System.ComponentModel;
namespace Tizen.NUI
{
/// This class can be used to convert visual properties to map.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- abstract public class ShadowBase
+ public abstract class ShadowBase
{
- internal delegate void PropertyChangedCallback(ShadowBase instance);
-
- internal PropertyChangedCallback OnPropertyChanged = null;
-
private static readonly Vector2 noOffset = new Vector2(0, 0);
- private static readonly Vector2 noScale = new Vector2(1, 1);
-
- private static readonly Vector2 absoluteTransformPolicy = new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute);
-
-
- /// <summary>
- /// The location offset value from the View
- /// </summary>
- protected internal Vector2 offset;
-
- /// <summary>
- /// The size value in scale
- /// </summary>
- protected internal Vector2 scale;
+ private static readonly Vector2 noExtents = new Vector2(0, 0);
/// <summary>
- /// The output property map
+ /// Constructor
/// </summary>
- protected internal PropertyMap propertyMap;
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected ShadowBase() : this(noOffset, noExtents)
+ {
+ }
/// <summary>
/// Constructor
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public ShadowBase() : this(noOffset, noScale)
+ protected ShadowBase(Vector2 offset, Vector2 extents)
{
+ Offset = new Vector2(offset);
+ Extents = new Vector2(extents);
+ }
+
+ /// <summary></summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ internal protected ShadowBase(PropertyMap propertyMap)
+ {
+ Offset = noOffset;
+ Extents = noExtents;
+
+ if (propertyMap == null)
+ {
+ return;
+ }
+
+ SetPropertyMap(propertyMap);
}
/// <summary>
/// Copy Constructor
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public ShadowBase(ShadowBase other) : this(other.offset, other.scale)
+ protected ShadowBase(ShadowBase other) : this(other.Offset, other.Extents)
{
}
/// <summary>
- /// Constructor
+ /// The position offset value (x, y) from the top left corner.
/// </summary>
- protected internal ShadowBase(Vector2 offset, Vector2 scale)
- {
- propertyMap = new PropertyMap();
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Vector2 Offset { get; set; }
- Offset = offset;
- Scale = scale;
+ /// <summary>
+ /// The shadow will extend its size by specified amount of length.<br />
+ /// If the value is negative then the shadow will shrink.
+ /// For example, when View's size is (100, 100) and the Shadow's Extents is (5, -5),
+ /// the output shadow will have size (105, 95).
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public Vector2 Extents { get; set; }
+
+ /// <summary></summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static bool operator ==(ShadowBase shadow1, ShadowBase shadow2)
+ {
+ return object.ReferenceEquals(shadow1, null) ? object.ReferenceEquals(shadow2, null) : shadow1.Equals(shadow2);
}
- private void OnOffsetChanged(float x, float y)
+ /// <summary></summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public static bool operator !=(ShadowBase shadow1, ShadowBase shadow2)
{
- OnPropertyChanged?.Invoke(this);
+ return !(shadow1 == shadow2);
}
- private void OnScaleChanged(float widht, float height)
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool Equals(object other)
{
- OnPropertyChanged?.Invoke(this);
+ if ((other == null) || ! this.GetType().Equals(other.GetType()))
+ {
+ return false;
+ }
+
+ var otherShadow = (ShadowBase)other;
+
+ if (!((Offset == null) ? otherShadow.Offset == null : Offset.Equals(otherShadow.Offset)))
+ {
+ return false;
+ }
+
+ return ((Extents == null) ? otherShadow.Extents == null : Extents.Equals(otherShadow.Extents));
}
- /// <summary>
- /// The position offset value (x, y) from the top left corner.
- /// </summary>
+ /// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
- public Vector2 Offset
+ public override int GetHashCode()
{
- get
+ unchecked
{
- return offset;
+ int hash = Offset == null ? 0 : Offset.GetHashCode();
+ hash = (hash * 7) + (Extents == null ? 0 : Extents.GetHashCode());
+ return hash;
}
- set
+ }
+
+ internal abstract bool IsEmpty();
+
+ internal PropertyValue ToPropertyValue(BaseComponents.View attachedView)
+ {
+ if (IsEmpty())
{
- offset = new Vector2(OnOffsetChanged, value ?? noOffset);
- OnPropertyChanged?.Invoke(this);
+ return new PropertyValue();
}
+
+ var map = GetPropertyMap();
+
+ if (attachedView.CornerRadius > 0)
+ {
+ map[Visual.Property.CornerRadius] = new PropertyValue(attachedView.CornerRadius);
+ }
+
+ map[Visual.Property.Transform] = GetTransformMap();
+
+ return new PropertyValue(map);
+ }
+
+ /// <summary>
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected virtual PropertyMap GetPropertyMap()
+ {
+ PropertyMap map = new PropertyMap();
+
+ return map;
}
/// <summary>
- /// The value indicates percentage of the container size. <br />
- /// e.g. (0.5f, 1.0f) means 50% of the container's width and 100% of container's height.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
- public Vector2 Scale
+ protected virtual bool SetPropertyMap(PropertyMap propertyMap)
{
- get
+ if (propertyMap == null)
{
- return scale;
+ return false;
}
- set
+
+ var transformProperty = propertyMap.Find(Visual.Property.Transform);
+
+ if (transformProperty == null)
{
- scale = new Vector2(OnScaleChanged, value ?? noScale);
- OnPropertyChanged?.Invoke(this);
+ // No transform map
+ return true;
}
+
+ var transformMap = new PropertyMap();
+
+ if (transformProperty.Get(transformMap))
+ {
+ SetTransformMap(transformMap);
+ }
+
+ return true;
}
private PropertyValue GetTransformMap()
{
var transformMap = new PropertyMap();
- if (!offset.Equals(noOffset))
+ if (!Offset.Equals(noOffset))
{
- transformMap[(int)VisualTransformPropertyType.OffsetPolicy] = new PropertyValue(absoluteTransformPolicy);
- transformMap[(int)VisualTransformPropertyType.Offset] = PropertyValue.CreateWithGuard(offset);
+ transformMap[(int)VisualTransformPropertyType.OffsetPolicy] = new PropertyValue(new Vector2((int)VisualTransformPolicyType.Absolute, (int)VisualTransformPolicyType.Absolute));
+ transformMap[(int)VisualTransformPropertyType.Offset] = PropertyValue.CreateWithGuard(Offset);
}
- if (!scale.Equals(noScale))
+ if (!Extents.Equals(noExtents))
{
- transformMap[(int)VisualTransformPropertyType.Size] = PropertyValue.CreateWithGuard(scale);
+ transformMap[(int)VisualTransformPropertyType.ExtraSize] = PropertyValue.CreateWithGuard(Extents);
}
- return transformMap.Count() == 0 ? new PropertyValue() : new PropertyValue(transformMap);
- }
+ transformMap[(int)VisualTransformPropertyType.Origin] = new PropertyValue((int)Visual.AlignType.Center);
+ transformMap[(int)VisualTransformPropertyType.AnchorPoint] = new PropertyValue((int)Visual.AlignType.Center);
- abstract internal bool IsValid();
+ return new PropertyValue(transformMap);
+ }
- static internal PropertyValue ToPropertyValue(ShadowBase instance)
+ /// <summary>
+ /// </summary>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ private void SetTransformMap(PropertyMap transformMap)
{
- if (instance == null || !instance.IsValid())
+ if (transformMap == null)
{
- return new PropertyValue();
+ return;
}
- instance.propertyMap[Visual.Property.Transform] = instance.GetTransformMap();
-
- return new PropertyValue(instance.propertyMap);
+ transformMap.Find((int)VisualTransformPropertyType.Offset)?.Get(Offset);
+ transformMap.Find((int)VisualTransformPropertyType.ExtraSize)?.Get(Extents);
}
}
}