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.
19 using System.ComponentModel;
25 /// Represents a shadow with color and blur radius for a View.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class Shadow : ShadowBase, ICloneable
30 private static readonly Color noColor = new Color(0, 0, 0, 0);
32 private static readonly Color defaultColor = new Color(0, 0, 0, 0.5f);
35 /// Create a Shadow with default values.
37 [EditorBrowsable(EditorBrowsableState.Never)]
38 public Shadow() : base()
45 /// Create a Shadow with custom values.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public Shadow(float blurRadius, Vector2 offset, Color color, Vector2 extents) : base(offset, extents)
50 BlurRadius = blurRadius;
51 Color = new Color(color);
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public Shadow(Shadow other) : this(other.BlurRadius, other.Offset, other.Color, other.Extents)
63 /// Create a Shadow from a propertyMap.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 internal Shadow(PropertyMap propertyMap) : base(propertyMap)
71 /// The color for the shadow.
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 public Color Color { get; set; }
77 /// The blur radius value for the shadow. Bigger value, much blurry.
80 /// Negative value is ignored. (no blur)
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public float BlurRadius { get; set; }
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public override bool Equals(object other)
89 if (!base.Equals(other))
94 var otherShadow = (Shadow)other;
96 if (!((Color == null) ? otherShadow.Color == null : Color.Equals(otherShadow.Color)))
101 return BlurRadius.Equals(otherShadow.BlurRadius);
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public override int GetHashCode()
110 int hash = base.GetHashCode();
111 hash = (hash * 7) + (Color == null ? 0 : Color.GetHashCode());
112 hash = (hash * 7) + (BlurRadius.GetHashCode());
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public object Clone() => new Shadow(this);
121 internal override bool IsEmpty()
123 return (Color == null || Color.A == 0);
127 [EditorBrowsable(EditorBrowsableState.Never)]
128 protected override PropertyMap GetPropertyMap()
130 var map = base.GetPropertyMap();
132 map[Visual.Property.Type] = new PropertyValue((int)Visual.Type.Color);
134 map[ColorVisualProperty.MixColor] = new PropertyValue(Color ?? noColor);
136 map[ColorVisualProperty.BlurRadius] = new PropertyValue(BlurRadius < 0 ? 0 : BlurRadius);
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 protected override bool SetPropertyMap(PropertyMap propertyMap)
145 if (!base.SetPropertyMap(propertyMap))
151 propertyMap.Find(ColorVisualProperty.MixColor)?.Get(Color);
153 float blurRadius = 0;
154 propertyMap.Find(ColorVisualProperty.BlurRadius)?.Get(out blurRadius);
155 BlurRadius = blurRadius;