1 /*
2  * Copyright 2018 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 /** Default alpha value used on [Paint]. This value will draw source content fully opaque. */
20 const val DefaultAlpha: Float = 1.0f
21 
22 expect class NativePaint
23 
Paintnull24 expect fun Paint(): Paint
25 
26 interface Paint {
27     fun asFrameworkPaint(): NativePaint
28 
29     /**
30      * Configures the alpha value between 0f to 1f representing fully transparent to fully opaque
31      * for the color drawn with this Paint
32      */
33     var alpha: Float
34 
35     /** Whether to apply anti-aliasing to lines and images drawn on the canvas. Defaults to true. */
36     var isAntiAlias: Boolean
37 
38     /**
39      * The color to use when stroking or filling a shape. Defaults to opaque black. See also:
40      * [style], which controls whether to stroke or fill (or both). [colorFilter], which overrides
41      * [color]. [shader], which overrides [color] with more elaborate effects. This color is not
42      * used when compositing. To colorize a layer, use [colorFilter].
43      */
44     var color: Color
45 
46     /**
47      * A blend mode to apply when a shape is drawn or a layer is composited. The source colors are
48      * from the shape being drawn (e.g. from [Canvas.drawPath]) or layer being composited (the
49      * graphics that were drawn between the [Canvas.saveLayer] and [Canvas.restore] calls), after
50      * applying the [colorFilter], if any. The destination colors are from the background onto which
51      * the shape or layer is being composited. Defaults to [BlendMode.SrcOver]. See also:
52      * [Canvas.saveLayer], which uses its [Paint]'s [blendMode] to composite the layer when
53      * [Canvas.restore] is called. [BlendMode], which discusses the user of [Canvas.saveLayer] with
54      * [blendMode].
55      */
56     var blendMode: BlendMode
57 
58     /**
59      * Whether to paint inside shapes, the edges of shapes, or both. Defaults to
60      * [PaintingStyle.Fill].
61      */
62     var style: PaintingStyle
63 
64     /**
65      * How wide to make edges drawn when [style] is set to [PaintingStyle.Stroke]. The width is
66      * given in logical pixels measured in the direction orthogonal to the direction of the path.
67      * Defaults to 0.0, which correspond to a hairline width.
68      */
69     var strokeWidth: Float
70 
71     /**
72      * The kind of finish to place on the end of lines drawn when [style] is set to
73      * [PaintingStyle.Stroke]. Defaults to [StrokeCap.Butt], i.e. no caps.
74      */
75     var strokeCap: StrokeCap
76 
77     /**
78      * The kind of finish to place on the joins between segments. This applies to paths drawn when
79      * [style] is set to [PaintingStyle.Stroke], It does not apply to points drawn as lines with
80      * [Canvas.drawPoints]. Defaults to [StrokeJoin.Miter], i.e. sharp corners. See also
81      * [strokeMiterLimit] to control when miters are replaced by bevels.
82      */
83     var strokeJoin: StrokeJoin
84 
85     /**
86      * The limit for miters to be drawn on segments when the join is set to [StrokeJoin.Miter] and
87      * the [style] is set to [PaintingStyle.Stroke]. If this limit is exceeded, then a
88      * [StrokeJoin.Bevel] join will be drawn instead. This may cause some 'popping' of the corners
89      * of a path if the angle between line segments is animated. This limit is expressed as a limit
90      * on the length of the miter. Defaults to 4.0. Using zero as a limit will cause a
91      * [StrokeJoin.Bevel] join to be used all the time.
92      */
93     var strokeMiterLimit: Float
94 
95     /**
96      * Controls the performance vs quality trade-off to use when applying when drawing images, as
97      * with [Canvas.drawImageRect] Defaults to [FilterQuality.Low].
98      */
99     var filterQuality: FilterQuality
100 
101     /**
102      * The shader to use when stroking or filling a shape.
103      *
104      * When this is null, the [color] is used instead.
105      *
106      * See also: [LinearGradientShader], [RadialGradientShader], or [SweepGradientShader] shaders
107      * that paint a color gradient. [ImageShader], a shader that tiles an [ImageBitmap].
108      * [colorFilter], which overrides [shader]. [color], which is used if [shader] and [colorFilter]
109      * are null.
110      */
111     var shader: Shader?
112 
113     /**
114      * A color filter to apply when a shape is drawn or when a layer is composited. See
115      * [ColorFilter] for details. When a shape is being drawn, [colorFilter] overrides [color] and
116      * [shader].
117      */
118     var colorFilter: ColorFilter?
119 
120     /** Specifies the [PathEffect] applied to the geometry of the shape that is drawn */
121     var pathEffect: PathEffect?
122 }
123