2 * Copyright(c) 2020 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;
24 /// Represents a shadow with color and blur radius for a View.
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public class Shadow : ShadowBase
29 private static readonly Color noColor = new Color(0, 0, 0, 0);
31 private static readonly Color defaultColor = new Color(0, 0, 0, 0.5f);
34 /// Create a Shadow with default values.
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public Shadow() : base()
44 /// Create a Shadow with custom values.
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public Shadow(float blurRadius, Vector2 offset, Color color, Vector2 extents) : base(offset, extents)
49 BlurRadius = blurRadius;
56 [EditorBrowsable(EditorBrowsableState.Never)]
57 public Shadow(Shadow other) : this(other.BlurRadius, other.Offset, other.Color, other.Extents)
62 /// Create a Shadow from a propertyMap.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 internal Shadow(PropertyMap propertyMap) : base(propertyMap)
70 /// The color for the shadow.
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public Color Color { get; set; }
76 /// The blur radius value for the shadow. Bigger value, much blurry.
79 /// Negative value is ignored. (no blur)
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 public float BlurRadius { get; set; }
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public override bool Equals(object other)
88 if (!base.Equals(other))
93 var otherShadow = (Shadow)other;
95 if (!((Color == null) ? otherShadow.Color == null : Color.Equals(otherShadow.Color)))
100 return BlurRadius.Equals(otherShadow.BlurRadius);
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public override int GetHashCode()
109 int hash = base.GetHashCode();
110 hash = (hash * 7) + (Color == null ? 0 : Color.GetHashCode());
111 hash = (hash * 7) + (BlurRadius.GetHashCode());
116 internal override bool IsEmpty()
118 return (Color == null || Color.A == 0);
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 protected override PropertyMap GetPropertyMap()
125 var map = base.GetPropertyMap();
127 map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.Color);
129 map[ColorVisualProperty.MixColor] = new PropertyValue(Color ?? noColor);
131 map[ColorVisualProperty.BlurRadius] = new PropertyValue(BlurRadius < 0 ? 0 : BlurRadius);
137 [EditorBrowsable(EditorBrowsableState.Never)]
138 protected override bool SetPropertyMap(PropertyMap propertyMap)
140 if (!base.SetPropertyMap(propertyMap))
146 propertyMap.Find(ColorVisualProperty.MixColor)?.Get(Color);
148 float blurRadius = 0;
149 propertyMap.Find(ColorVisualProperty.BlurRadius)?.Get(out blurRadius);
150 BlurRadius = blurRadius;