-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbb4b54
commit 379b869
Showing
15 changed files
with
238 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
coil-test/src/androidMain/kotlin/coil3/test/ColorImage.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package coil3.test | ||
|
||
import android.graphics.Paint | ||
import coil3.Canvas | ||
import coil3.Image | ||
import coil3.annotation.Poko | ||
|
||
@Poko | ||
actual class ColorImage actual constructor( | ||
actual val color: Int, | ||
actual override val width: Int, | ||
actual override val height: Int, | ||
actual override val size: Long, | ||
actual override val shareable: Boolean, | ||
) : Image { | ||
private var lazyPaint: Paint? = null | ||
|
||
actual override fun draw(canvas: Canvas) { | ||
val paint = lazyPaint ?: run { | ||
Paint() | ||
.apply { color = this@ColorImage.color } | ||
.also { lazyPaint = it } | ||
} | ||
if (width >= 0 && height >= 0) { | ||
canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), paint) | ||
} else { | ||
canvas.drawPaint(paint) | ||
} | ||
} | ||
|
||
actual companion object { | ||
actual const val Black = 0xFF000000.toInt() | ||
actual const val White = 0xFFFFFFFF.toInt() | ||
actual const val Transparent = 0x00000000.toInt() | ||
actual const val Red = 0xFFFF0000.toInt() | ||
actual const val Green = 0xFF00FF00.toInt() | ||
actual const val Blue = 0xFF0000FF.toInt() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package coil3.test | ||
|
||
import coil3.Canvas | ||
import coil3.Image | ||
|
||
/** | ||
* An image that draws a [color]. | ||
* | ||
* By default the image has no intrinsic size and will fill its canvas. Set [width] and [height] | ||
* to a positive value to draw a square with those dimensions. | ||
*/ | ||
expect class ColorImage( | ||
color: Int = Black, | ||
width: Int = -1, | ||
height: Int = -1, | ||
size: Long = 0, | ||
shareable: Boolean = true, | ||
) : Image { | ||
val color: Int | ||
override val size: Long | ||
override val width: Int | ||
override val height: Int | ||
override val shareable: Boolean | ||
override fun draw(canvas: Canvas) | ||
|
||
companion object { | ||
val Black: Int | ||
val White: Int | ||
val Transparent: Int | ||
val Red: Int | ||
val Green: Int | ||
val Blue: Int | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
coil-test/src/nonAndroidMain/kotlin/coil3/test/ColorImage.nonAndroid.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package coil3.test | ||
|
||
import coil3.Canvas | ||
import coil3.Image | ||
import coil3.annotation.Poko | ||
import org.jetbrains.skia.Paint | ||
import org.jetbrains.skia.Rect | ||
|
||
@Poko | ||
actual class ColorImage actual constructor( | ||
actual val color: Int, | ||
actual override val width: Int, | ||
actual override val height: Int, | ||
actual override val size: Long, | ||
actual override val shareable: Boolean, | ||
) : Image { | ||
private var lazyPaint: Paint? = null | ||
private var lazyRect: Rect? = null | ||
|
||
actual override fun draw(canvas: Canvas) { | ||
val paint = lazyPaint ?: run { | ||
Paint() | ||
.apply { color = this@ColorImage.color } | ||
.also { lazyPaint = it } | ||
} | ||
if (width >= 0 && height >= 0) { | ||
val rect = lazyRect ?: run { | ||
Rect.makeWH(width.toFloat(), height.toFloat()) | ||
.also { lazyRect = it } | ||
} | ||
canvas.drawRect(rect, paint) | ||
} else { | ||
canvas.drawPaint(paint) | ||
} | ||
} | ||
|
||
actual companion object { | ||
actual const val Black = 0xFF000000.toInt() | ||
actual const val White = 0xFFFFFFFF.toInt() | ||
actual const val Transparent = 0x00000000.toInt() | ||
actual const val Red = 0xFFFF0000.toInt() | ||
actual const val Green = 0xFF00FF00.toInt() | ||
actual const val Blue = 0xFF0000FF.toInt() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.