Skip to content

Commit 48a5e9b

Browse files
committed
border fixed; second circle added for contrast.
1 parent 41afdd0 commit 48a5e9b

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ buildscript {
1111
kotlin_version = '1.7.0'
1212
compose_compiler_version = '1.2.0'
1313
compose_version = '1.2.0-rc01'
14-
version_name = '1.0.9'
15-
version_code = 9
14+
version_name = '1.1.0'
15+
version_code = 10
1616
}
1717
}
1818

library/src/main/java/io/syslogic/colorpicker/compose/AlphaPainter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class AlphaPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
2121
private var value: Float = 1.0F
2222

2323
/**
24-
* Implementation of drawing logic for instances of [Painter]. This is invoked
25-
* internally within [draw] after the positioning and configuring the [Painter]
24+
* Implementation of drawing logic for instances of [Painter].
25+
* This is invoked internally within [draw] after the positioning and configuring the [Painter].
2626
*/
2727
override fun DrawScope.onDraw() {
2828

@@ -39,7 +39,7 @@ class AlphaPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
3939
drawRect(
4040
size = size,
4141
color = Color(borderStrokeColor),
42-
topLeft = Offset(rect.left, rect.top),
42+
topLeft = Offset(outline.left, outline.top),
4343
style = Stroke(width = borderStrokeWidth,
4444
pathEffect = PathEffect.cornerPathEffect(borderCornerRadius)
4545
)

library/src/main/java/io/syslogic/colorpicker/compose/BasePainter.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.graphics.Rect
55
import android.graphics.RectF
66

77
import androidx.compose.ui.geometry.Size
8+
import androidx.compose.ui.graphics.Color
89
import androidx.compose.ui.graphics.NativeCanvas
910
import androidx.compose.ui.graphics.drawscope.DrawContext
1011
import androidx.compose.ui.graphics.nativeCanvas
@@ -29,7 +30,8 @@ abstract class BasePainter(override val intrinsicSize: Size) : Painter() {
2930
var borderStrokeColor by Delegates.notNull<Int>()
3031

3132
/** Tracker Dimension: Sat/Val Tracker Radius */
32-
var satValTrackerRadius by Delegates.notNull<Float>()
33+
var satValTrackerRadius1 by Delegates.notNull<Float>()
34+
var satValTrackerRadius2 by Delegates.notNull<Float>()
3335

3436
/** Tracker Dimension: Alpha Tracker Width */
3537
var alphaTrackerWidth by Delegates.notNull<Float>()
@@ -50,35 +52,43 @@ abstract class BasePainter(override val intrinsicSize: Size) : Painter() {
5052
protected lateinit var canvas: NativeCanvas
5153

5254
/** Boundaries */
55+
protected lateinit var outline: RectF
5356
protected lateinit var rect: RectF
5457

5558
/** Being called by all implementations onDraw. */
5659
fun setCanvas(drawContext: DrawContext, density: Float) {
5760

5861
/* Tracker Dimensions */
59-
satValTrackerRadius = 8F * density
62+
satValTrackerRadius1 = 9F * density
63+
satValTrackerRadius2 = 8F * density
6064
alphaTrackerWidth = 4F * density
6165
hueTrackerHeight = 4F * density
6266

6367
/* Tracker Styles */
6468
trackerCornerRadius = 2F * density
6569
trackerStrokeWidth = 1F * density
66-
trackerStrokeColor = -0xe3e3e4
70+
trackerStrokeColor = Color.Black.hashCode()
6771

6872
/* Border Styles */
69-
borderCornerRadius = 2F * density
70-
borderStrokeWidth = 2F * density
71-
borderStrokeColor = -0x919192
73+
borderCornerRadius = 2F
74+
borderStrokeWidth = 2F
75+
borderStrokeColor = Color.DarkGray.hashCode()
7276

7377
/* Native Canvas */
7478
canvas = drawContext.canvas.nativeCanvas
7579
val bounds: Rect = canvas.clipBounds
76-
rect = RectF(
80+
outline = RectF(
7781
bounds.left.toFloat(),
7882
bounds.top.toFloat(),
7983
bounds.right.toFloat(),
8084
bounds.bottom.toFloat()
8185
)
86+
rect = RectF(
87+
bounds.left.toFloat() + borderStrokeWidth,
88+
bounds.top.toFloat() + borderStrokeWidth,
89+
bounds.right.toFloat() - borderStrokeWidth,
90+
bounds.bottom.toFloat() - borderStrokeWidth
91+
)
8292
}
8393

8494
/**

library/src/main/java/io/syslogic/colorpicker/compose/ColorPainter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class ColorPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
1818
private var value: Color = Color.Transparent
1919

2020
/**
21-
* Implementation of drawing logic for instances of [Painter]. This is invoked
22-
* internally within [draw] after the positioning and configuring the [Painter]
21+
* Implementation of drawing logic for instances of [Painter].
22+
* This is invoked internally within [draw] after the positioning and configuring the [Painter].
2323
*/
2424
override fun DrawScope.onDraw() {
2525
setCanvas(drawContext, density)
@@ -32,7 +32,7 @@ class ColorPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
3232
drawRect(
3333
size = size,
3434
color = Color(borderStrokeColor),
35-
topLeft = Offset(rect.left, rect.top),
35+
topLeft = Offset(outline.left, outline.top),
3636
style = Stroke(width = borderStrokeWidth,
3737
pathEffect = PathEffect.cornerPathEffect(borderCornerRadius)
3838
)

library/src/main/java/io/syslogic/colorpicker/compose/HuePainter.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class HuePainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
2121
private var value: Float = 360f
2222

2323
/**
24-
* Implementation of drawing logic for instances of [Painter]. This is invoked
25-
* internally within [draw] after the positioning and configuring the [Painter]
24+
* Implementation of drawing logic for instances of [Painter].
25+
* This is invoked internally within [draw] after the positioning and configuring the [Painter].
2626
*/
2727
override fun DrawScope.onDraw() {
2828
setCanvas(drawContext, density)
@@ -37,7 +37,7 @@ class HuePainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
3737
drawRect(
3838
size = size,
3939
color = Color(borderStrokeColor),
40-
topLeft = Offset(rect.left, rect.top),
40+
topLeft = Offset(outline.left, outline.top),
4141
style = Stroke(width = borderStrokeWidth,
4242
pathEffect = PathEffect.cornerPathEffect(borderCornerRadius)
4343
)
@@ -62,7 +62,7 @@ class HuePainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
6262
val list: MutableList<Color> = MutableList(360) { Color.Black }
6363
while (i < list.size) {
6464
val value = (list.size - i).toFloat()
65-
list[i] = Color(android.graphics.Color.HSVToColor(255, floatArrayOf(value, 1f, 1f)))
65+
list[i] = Color(android.graphics.Color.HSVToColor(255, floatArrayOf(value, 1F, 1F)))
6666
i++
6767
}
6868
return list

library/src/main/java/io/syslogic/colorpicker/compose/SatValPainter.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
3030

3131
/* Saturation Shader with Alpha */
3232
val alpha: Int = getAlpha().times(255).toInt()
33-
val color: Int = HSVToColor(alpha, floatArrayOf(getHue(), 1.0F, 1.0F))
33+
val color: Int = HSVToColor(alpha, floatArrayOf(getHue(), 1F, 1F))
3434
val mSaturationShader = LinearGradientShader (
3535
from = Offset(rect.right, rect.top),
3636
to = Offset(rect.left, rect.top),
@@ -47,27 +47,31 @@ class SatValPainter(intrinsicSize: Size) : BasePainter(intrinsicSize) {
4747
)
4848

4949
/* Compose Shader */
50-
val compose = Paint()
51-
compose.shader = ComposeShader(mContrastShader, mSaturationShader, PorterDuff.Mode.MULTIPLY)
52-
canvas.drawRect(rect, compose)
50+
val composition = Paint()
51+
composition.shader = ComposeShader(mContrastShader, mSaturationShader, PorterDuff.Mode.MULTIPLY)
52+
canvas.drawRect(rect, composition)
5353

5454
/* Borderline */
5555
val border = Paint()
5656
border.style = Paint.Style.STROKE
5757
border.strokeWidth = borderStrokeWidth
5858
border.color = borderStrokeColor
59-
canvas.drawRect(rect, border)
59+
canvas.drawRect(outline, border)
6060

61-
/* Tracker Paint */
61+
/* Tracker */
62+
val p: Point = satValToPoint(getSat(), getValue())
6263
val tracker = Paint()
6364
tracker.style = Paint.Style.STROKE
6465
tracker.strokeWidth = trackerStrokeWidth
65-
tracker.color = trackerStrokeColor
6666
tracker.isAntiAlias = true
6767

68-
/* Circular Tracker */
69-
val p: Point = satValToPoint(getSat(), getValue())
70-
canvas.drawCircle(p.x.toFloat(), p.y.toFloat(), satValTrackerRadius, tracker)
68+
/* Outer circle */
69+
tracker.color = trackerStrokeColor
70+
canvas.drawCircle(p.x.toFloat(), p.y.toFloat(), satValTrackerRadius1, tracker)
71+
72+
/* Inner circle */
73+
tracker.color = Color.White.hashCode()
74+
canvas.drawCircle(p.x.toFloat(), p.y.toFloat(), satValTrackerRadius2, tracker)
7175
}
7276

7377
private fun getAlpha() : Float {

0 commit comments

Comments
 (0)