From 3974e42d5ec950023f79c3bdd55a33a49b551365 Mon Sep 17 00:00:00 2001 From: Dion Segijn Date: Sun, 10 Dec 2023 21:09:08 +0100 Subject: [PATCH] Remove emoji shapes Unfortunately the implementation wasn't as far as I hoped. I'll have to revisit the implementation and find a good way to support emoji's and its different shapes and sizes in combination with rendering Text in a proper way. Right now I ran into some limitations properly rendering Text as a particle and rotate it for example. --- .idea/gradle.xml | 3 +-- .../main/java/nl/dionsegijn/konfetti/compose/DrawShapes.kt | 5 ----- .../src/main/java/nl/dionsegijn/konfetti/core/Particle.kt | 2 -- .../main/java/nl/dionsegijn/konfetti/core/PartySystem.kt | 1 - .../java/nl/dionsegijn/konfetti/core/emitter/Confetti.kt | 7 ------- .../main/java/nl/dionsegijn/konfetti/core/models/Shape.kt | 5 ----- .../src/main/java/nl/dionsegijn/konfetti/xml/DrawShapes.kt | 5 +---- .../main/java/nl/dionsegijn/konfetti/xml/KonfettiView.kt | 2 +- 8 files changed, 3 insertions(+), 27 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index c8b375b2..5b95889f 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,8 +5,6 @@ diff --git a/konfetti/compose/src/main/java/nl/dionsegijn/konfetti/compose/DrawShapes.kt b/konfetti/compose/src/main/java/nl/dionsegijn/konfetti/compose/DrawShapes.kt index d2b14379..88500130 100644 --- a/konfetti/compose/src/main/java/nl/dionsegijn/konfetti/compose/DrawShapes.kt +++ b/konfetti/compose/src/main/java/nl/dionsegijn/konfetti/compose/DrawShapes.kt @@ -71,10 +71,5 @@ fun Shape.draw(drawScope: DrawScope, particle: Particle, imageResource: ImageBit drawable.draw(it.nativeCanvas) } } - is Shape.Text -> { - drawScope.drawIntoCanvas { - it.nativeCanvas.drawText(text, particle.x, particle.y, particle.paint) - } - } } } diff --git a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/Particle.kt b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/Particle.kt index a507156d..8532919b 100644 --- a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/Particle.kt +++ b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/Particle.kt @@ -1,6 +1,5 @@ package nl.dionsegijn.konfetti.core -import android.graphics.Paint import nl.dionsegijn.konfetti.core.models.Shape /** @@ -25,5 +24,4 @@ data class Particle( val scaleX: Float, val shape: Shape, val alpha: Int, - val paint: Paint ) diff --git a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/PartySystem.kt b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/PartySystem.kt index 214808b9..e09a08fc 100644 --- a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/PartySystem.kt +++ b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/PartySystem.kt @@ -65,6 +65,5 @@ fun Confetti.toParticle(): Particle { scaleX, shape, alpha, - paint ) } diff --git a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/emitter/Confetti.kt b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/emitter/Confetti.kt index 56b970de..f7066371 100644 --- a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/emitter/Confetti.kt +++ b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/emitter/Confetti.kt @@ -25,13 +25,6 @@ class Confetti( val rotationSpeed2D: Float = 1f, val pixelDensity: Float ) { - val paint: Paint = Paint() - - init { - if (shape is Shape.Text) { - paint.textSize = shape.textSizeInPixels - } - } var rotation = 0f private var rotationWidth = width diff --git a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/models/Shape.kt b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/models/Shape.kt index e1a3ff7a..b235928d 100644 --- a/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/models/Shape.kt +++ b/konfetti/core/src/main/java/nl/dionsegijn/konfetti/core/models/Shape.kt @@ -39,9 +39,4 @@ sealed interface Shape { drawable.intrinsicHeight.toFloat() / drawable.intrinsicWidth } } - - data class Text( - val text: String, - val textSizeInPixels: Float - ) : Shape } diff --git a/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/DrawShapes.kt b/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/DrawShapes.kt index 09c12d1f..e2387fc8 100644 --- a/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/DrawShapes.kt +++ b/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/DrawShapes.kt @@ -20,7 +20,7 @@ import nl.dionsegijn.konfetti.core.models.Shape.Text * `size` and must vertically/horizontally center their asset if it does not have an equal width * and height. */ -fun Shape.draw(particle: Particle, canvas: Canvas, paint: Paint, size: Float) { +fun Shape.draw(canvas: Canvas, paint: Paint, size: Float) { when (this) { Square -> canvas.drawRect(0f, 0f, size, size, paint) @@ -50,8 +50,5 @@ fun Shape.draw(particle: Particle, canvas: Canvas, paint: Paint, size: Float) { drawable.setBounds(0, top, size.toInt(), top + height) drawable.draw(canvas) } - is Text -> { - canvas.drawText(text, particle.x, particle.y, particle.paint) - } } } diff --git a/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/KonfettiView.kt b/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/KonfettiView.kt index 8edbafcb..9e711ff3 100644 --- a/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/KonfettiView.kt +++ b/konfetti/xml/src/main/java/nl/dionsegijn/konfetti/xml/KonfettiView.kt @@ -89,7 +89,7 @@ open class KonfettiView : View { canvas.rotate(rotation, centerX, width / 2) canvas.scale(scaleX, 1f) - shape.draw(this, canvas, paint, width) + shape.draw(canvas, paint, width) canvas.restoreToCount(saveCount) }