1 /*
2 * Copyright 2019 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package androidx.compose.ui.graphics
18
19 import androidx.compose.runtime.Immutable
20 import androidx.compose.runtime.Stable
21 import androidx.compose.ui.geometry.Offset
22 import androidx.compose.ui.geometry.lerp
23 import androidx.compose.ui.util.lerp
24
25 /** A single shadow. */
26 @Immutable
27 class Shadow(
28 @Stable val color: Color = Color(0xFF000000),
29 @Stable val offset: Offset = Offset.Zero,
30 @Stable val blurRadius: Float = 0.0f
31 ) {
32 companion object {
33 /** Constant for no shadow. */
34 @Stable val None = Shadow()
35 }
36
equalsnull37 override fun equals(other: Any?): Boolean {
38 if (this === other) return true
39 if (other !is Shadow) return false
40
41 if (color != other.color) return false
42 if (offset != other.offset) return false
43 if (blurRadius != other.blurRadius) return false
44
45 return true
46 }
47
hashCodenull48 override fun hashCode(): Int {
49 var result = color.hashCode()
50 result = 31 * result + offset.hashCode()
51 result = 31 * result + blurRadius.hashCode()
52 return result
53 }
54
toStringnull55 override fun toString(): String {
56 return "Shadow(color=$color, offset=$offset, blurRadius=$blurRadius)"
57 }
58
copynull59 fun copy(
60 color: Color = this.color,
61 offset: Offset = this.offset,
62 blurRadius: Float = this.blurRadius
63 ): Shadow {
64 return Shadow(color = color, offset = offset, blurRadius = blurRadius)
65 }
66 }
67
68 /** Linearly interpolate two [Shadow]s. */
69 @Stable
lerpnull70 fun lerp(start: Shadow, stop: Shadow, fraction: Float): Shadow {
71 return Shadow(
72 lerp(start.color, stop.color, fraction),
73 lerp(start.offset, stop.offset, fraction),
74 lerp(start.blurRadius, stop.blurRadius, fraction)
75 )
76 }
77