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.ui.geometry.Offset
20
21 /**
22 * Class that represents the corresponding Shader implementation on a platform. This maps to
23 * Gradients or ImageShaders
24 */
25 expect class Shader
26
27 /**
28 * Creates a linear gradient from `from` to `to`.
29 *
30 * If `colorStops` is provided, each value is a number from 0.0 to 1.0 that specifies where the
31 * color at the corresponding index in [colors] begins in the gradient. If `colorStops` is not
32 * provided, then the colors are dispersed evenly
33 *
34 * The behavior before [from] and after [to] is described by the `tileMode` argument. For details,
35 * see the [TileMode] enum. If no [TileMode] is provided the default value of [TileMode.Clamp] is
36 * used
37 */
LinearGradientShadernull38 fun LinearGradientShader(
39 from: Offset,
40 to: Offset,
41 colors: List<Color>,
42 colorStops: List<Float>? = null,
43 tileMode: TileMode = TileMode.Clamp
44 ): Shader = ActualLinearGradientShader(from, to, colors, colorStops, tileMode)
45
46 internal expect fun ActualLinearGradientShader(
47 from: Offset,
48 to: Offset,
49 colors: List<Color>,
50 colorStops: List<Float>?,
51 tileMode: TileMode
52 ): Shader
53
54 /**
55 * Creates a radial gradient centered at `center` that ends at `radius` distance from the center.
56 *
57 * If `colorStops` is provided, each value is a number from 0.0 to 1.0 that specifies where the
58 * color at the corresponding index in [colors] begins in the gradient. If `colorStops` is not
59 * provided, then the colors are dispersed evenly
60 *
61 * The behavior before and after the radius is described by the `tileMode` argument. For details,
62 * see the [TileMode] enum.
63 *
64 * The behavior outside of the bounds of [center] +/- [radius] is described by the `tileMode`
65 * argument. For details, see the [TileMode] enum. If no [TileMode] is provided the default value of
66 * [TileMode.Clamp] is used
67 */
68 fun RadialGradientShader(
69 center: Offset,
70 radius: Float,
71 colors: List<Color>,
72 colorStops: List<Float>? = null,
73 tileMode: TileMode = TileMode.Clamp
74 ): Shader = ActualRadialGradientShader(center, radius, colors, colorStops, tileMode)
75
76 internal expect fun ActualRadialGradientShader(
77 center: Offset,
78 radius: Float,
79 colors: List<Color>,
80 colorStops: List<Float>?,
81 tileMode: TileMode
82 ): Shader
83
84 /**
85 * Creates a circular gradient that sweeps around a provided center point. The sweep begins relative
86 * to 3 o'clock and continues clockwise until it reaches the starting position again.
87 *
88 * If `colorStops` is provided, each value is a number from 0.0 to 1.0 that specifies where the
89 * color at the corresponding index in [colors] begins in the gradient. If `colorStops` is not
90 * provided, then the colors are dispersed evenly
91 *
92 * @param center Position for the gradient to sweep around
93 * @param colors Colors to be rendered as part of the gradient
94 * @param colorStops Placement of the colors along the sweep about the center position
95 */
96 fun SweepGradientShader(
97 center: Offset,
98 colors: List<Color>,
99 colorStops: List<Float>? = null
100 ): Shader = ActualSweepGradientShader(center, colors, colorStops)
101
102 internal expect fun ActualSweepGradientShader(
103 center: Offset,
104 colors: List<Color>,
105 colorStops: List<Float>?,
106 ): Shader
107
108 /**
109 * Creates a Shader using the given [ImageBitmap] as an input texture. If the shader is to be drawn
110 * in an area larger than the size of the [ImageBitmap], the region is filled in the horizontal and
111 * vertical directions based on the [tileModeX] and [tileModeY] parameters.
112 */
113 fun ImageShader(
114 image: ImageBitmap,
115 tileModeX: TileMode = TileMode.Clamp,
116 tileModeY: TileMode = TileMode.Clamp
117 ): Shader = ActualImageShader(image, tileModeX, tileModeY)
118
119 internal expect fun ActualImageShader(
120 image: ImageBitmap,
121 tileModeX: TileMode,
122 tileModeY: TileMode
123 ): Shader
124