@@ -7,6 +7,7 @@ import androidx.compose.ui.geometry.Offset
7
7
import androidx.compose.ui.geometry.Size
8
8
import androidx.compose.ui.graphics.Color
9
9
import androidx.compose.ui.graphics.LinearGradientShader
10
+ import androidx.compose.ui.graphics.TileMode
10
11
import androidx.compose.ui.graphics.drawscope.DrawScope
11
12
import androidx.compose.ui.graphics.painter.Painter
12
13
@@ -17,8 +18,7 @@ import androidx.compose.ui.graphics.painter.Painter
17
18
*/
18
19
class SatValPainter (intrinsicSize : Size ) : BasePainter(intrinsicSize) {
19
20
20
- private var value: FloatArray = FloatArray (2 )
21
- private var hue: Float = 360F
21
+ private var value: FloatArray = FloatArray (4 )
22
22
23
23
/* *
24
24
* Implementation of drawing logic for instances of [Painter].
@@ -29,19 +29,25 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
29
29
setCanvas(drawContext, density)
30
30
31
31
/* Saturation Shader */
32
- val mSaturationShader = LinearGradientShader (
33
- from = Offset (rect.right, rect.top),
34
- to = Offset (rect.left, rect.top),
35
- tileMode = androidx.compose.ui.graphics.TileMode .Clamp ,
36
- colors = listOf (Color (HSVToColor (floatArrayOf(hue, 1f , 1f ))), Color .White )
32
+ val mSaturationShader = LinearGradientShader (
33
+ from = Offset (rect.right, rect.top),
34
+ to = Offset (rect.left, rect.top),
35
+ tileMode = TileMode .Clamp ,
36
+ colors = listOf (
37
+ Color (color = HSVToColor (getAlpha().times(255 ).toInt(), floatArrayOf(getHue(), 1.0F , 1.0F ))),
38
+ Color .White
39
+ )
37
40
)
38
41
39
- /* Contrast Shader */
42
+ /* Value Shader */
40
43
val mContrastShader = LinearGradientShader (
41
- from = Offset (rect.left, rect.bottom),
42
- to = Offset (rect.left, rect.top),
43
- tileMode = androidx.compose.ui.graphics.TileMode .Clamp ,
44
- colors = listOf (Color .Black , Color .White )
44
+ from = Offset (rect.left, rect.bottom),
45
+ to = Offset (rect.left, rect.top),
46
+ tileMode = TileMode .Clamp ,
47
+ colors = listOf (
48
+ Color .Black ,
49
+ Color .White
50
+ )
45
51
)
46
52
47
53
/* Compose Shader */
@@ -66,16 +72,39 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
66
72
tracker.isAntiAlias = true
67
73
68
74
/* Circular Tracker */
69
- val p: Point = satValToPoint(value[ 0 ], value[ 1 ] )
75
+ val p: Point = satValToPoint(getSat(), getValue() )
70
76
canvas.drawCircle(p.x.toFloat(), p.y.toFloat(), satValTrackerRadius, tracker)
71
77
}
72
78
73
- fun setValue (saturation : Float , value : Float ) {
74
- this .value[0 ] = saturation
75
- this .value[1 ] = value
79
+ private fun getHue () : Float {
80
+ return this .value[0 ]
81
+ }
82
+
83
+ private fun getSat () : Float {
84
+ return this .value[1 ]
85
+ }
86
+
87
+ private fun getValue () : Float {
88
+ return this .value[2 ]
89
+ }
90
+
91
+ private fun getAlpha () : Float {
92
+ return this .value[3 ]
76
93
}
77
94
78
95
fun setHue (value : Float ) {
79
- this .hue = value
96
+ this .value[0 ] = value
97
+ }
98
+
99
+ fun setSat (value : Float ) {
100
+ this .value[1 ] = value
101
+ }
102
+
103
+ fun setValue (value : Float ) {
104
+ this .value[2 ] = value
105
+ }
106
+
107
+ fun setAlpha (value : Float ) {
108
+ this .value[3 ] = value
80
109
}
81
110
}
0 commit comments