@@ -28,40 +28,34 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
28
28
29
29
setCanvas(drawContext, density)
30
30
31
- /* Saturation Shader */
31
+ /* Saturation Shader with Alpha */
32
+ val alpha: Int = getAlpha().times(255 ).toInt()
33
+ val color: Int = HSVToColor (alpha, floatArrayOf(getHue(), 1.0F , 1.0F ))
32
34
val mSaturationShader = LinearGradientShader (
33
35
from = Offset (rect.right, rect.top),
34
36
to = Offset (rect.left, rect.top),
35
37
tileMode = TileMode .Clamp ,
36
- colors = listOf (
37
- Color (color = HSVToColor (getAlpha().times(255 ).toInt(), floatArrayOf(getHue(), 1.0F , 1.0F ))),
38
- Color .White
39
- )
38
+ colors = listOf (Color (color), Color .White )
40
39
)
41
40
42
41
/* Value Shader */
43
42
val mContrastShader = LinearGradientShader (
44
43
from = Offset (rect.left, rect.bottom),
45
44
to = Offset (rect.left, rect.top),
46
45
tileMode = TileMode .Clamp ,
47
- colors = listOf (
48
- Color .Black ,
49
- Color .White
50
- )
46
+ colors = listOf (Color .Black , Color .White )
51
47
)
52
48
53
49
/* Compose Shader */
54
- val paint = Paint ()
55
- paint .shader = ComposeShader (mContrastShader, mSaturationShader, PorterDuff .Mode .MULTIPLY )
56
- canvas.drawRect(rect, paint )
50
+ val compose = Paint ()
51
+ compose .shader = ComposeShader (mContrastShader, mSaturationShader, PorterDuff .Mode .MULTIPLY )
52
+ canvas.drawRect(rect, compose )
57
53
58
- /* Borderline Paint */
54
+ /* Borderline */
59
55
val border = Paint ()
60
56
border.style = Paint .Style .STROKE
61
57
border.strokeWidth = borderStrokeWidth
62
58
border.color = borderStrokeColor
63
-
64
- /* Borderline */
65
59
canvas.drawRect(rect, border)
66
60
67
61
/* Tracker Paint */
@@ -76,35 +70,36 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
76
70
canvas.drawCircle(p.x.toFloat(), p.y.toFloat(), satValTrackerRadius, tracker)
77
71
}
78
72
79
- private fun getHue () : Float {
73
+ private fun getAlpha () : Float {
80
74
return this .value[0 ]
81
75
}
82
76
83
- private fun getSat () : Float {
77
+ private fun getHue () : Float {
84
78
return this .value[1 ]
85
79
}
86
80
87
- private fun getValue () : Float {
81
+ private fun getSat () : Float {
88
82
return this .value[2 ]
89
83
}
90
84
91
- private fun getAlpha () : Float {
85
+ private fun getValue () : Float {
92
86
return this .value[3 ]
93
87
}
94
88
95
- fun setHue (value : Float ) {
89
+ fun setAlpha (value : Float ) {
96
90
this .value[0 ] = value
97
91
}
98
92
99
- fun setSat (value : Float ) {
93
+ fun setHue (value : Float ) {
100
94
this .value[1 ] = value
101
95
}
102
96
103
- fun setValue (value : Float ) {
97
+ fun setSat (value : Float ) {
104
98
this .value[2 ] = value
105
99
}
106
100
107
- fun setAlpha (value : Float ) {
101
+ fun setValue (value : Float ) {
108
102
this .value[3 ] = value
109
103
}
104
+
110
105
}
0 commit comments