diff --git a/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt b/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt index e35a907..2f0c87e 100644 --- a/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt +++ b/neumorphism/src/main/java/soup/neumorphism/NeumorphShapeDrawable.kt @@ -180,7 +180,7 @@ class NeumorphShapeDrawable : Drawable { } private fun updateShadowShape() { - val internalBounds = getBoundsInternal() + val internalBounds = this.getBoundsInternal() if (internalBounds.width() <= 0 || internalBounds.height() <= 0) { shadow = null return @@ -305,7 +305,8 @@ class NeumorphShapeDrawable : Drawable { drawBackgroundBitmap(canvas) } - shadow?.draw(canvas, outlinePath) + val shadowBounds = this.getBoundsInternal() + shadow?.draw(canvas, outlinePath, shadowBounds) if (hasStroke()) { drawStrokeShape(canvas) diff --git a/neumorphism/src/main/java/soup/neumorphism/internal/shape/BasinShape.kt b/neumorphism/src/main/java/soup/neumorphism/internal/shape/BasinShape.kt index 10ca3b0..889a261 100644 --- a/neumorphism/src/main/java/soup/neumorphism/internal/shape/BasinShape.kt +++ b/neumorphism/src/main/java/soup/neumorphism/internal/shape/BasinShape.kt @@ -16,8 +16,8 @@ internal class BasinShape(drawableState: NeumorphShapeDrawableState) : Shape { shadows.forEach { it.setDrawableState(newDrawableState) } } - override fun draw(canvas: Canvas, outlinePath: Path) { - shadows.forEach { it.draw(canvas, outlinePath) } + override fun draw(canvas: Canvas, outlinePath: Path, bounds: Rect) { + shadows.forEach { it.draw(canvas, outlinePath, bounds) } } override fun updateShadowBitmap(bounds: Rect) { diff --git a/neumorphism/src/main/java/soup/neumorphism/internal/shape/FlatShape.kt b/neumorphism/src/main/java/soup/neumorphism/internal/shape/FlatShape.kt index 0287ed3..499385e 100644 --- a/neumorphism/src/main/java/soup/neumorphism/internal/shape/FlatShape.kt +++ b/neumorphism/src/main/java/soup/neumorphism/internal/shape/FlatShape.kt @@ -27,7 +27,7 @@ internal class FlatShape( this.drawableState = newDrawableState } - override fun draw(canvas: Canvas, outlinePath: Path) { + override fun draw(canvas: Canvas, outlinePath: Path, bounds: Rect) { canvas.withClipOut(outlinePath) { val elevation = drawableState.shadowElevation val z = drawableState.shadowElevation + drawableState.translationZ @@ -36,13 +36,15 @@ internal class FlatShape( val inset = drawableState.inset left = inset.left.toFloat() top = inset.top.toFloat() - lightShadowBitmap?.let { + lightShadowBitmap?.let { originalShadow -> val offset = -elevation - z - drawBitmap(it, offset + left, offset + top, null) + val scaledShadow = Bitmap.createScaledBitmap(originalShadow, bounds.width() + (offset + left).toInt(), bounds.height() + (offset + top).toInt(), false) + drawBitmap(scaledShadow, offset + left, offset + top, null) } - darkShadowBitmap?.let { + darkShadowBitmap?.let { originalShadow -> val offset = -elevation + z - drawBitmap(it, offset + left, offset + top, null) + val scaledShadow = Bitmap.createScaledBitmap(originalShadow, bounds.width() + (offset + left).toInt(), bounds.height() + (offset + top).toInt(), false) + drawBitmap(scaledShadow, offset + left, offset + top, null) } } } diff --git a/neumorphism/src/main/java/soup/neumorphism/internal/shape/PressedShape.kt b/neumorphism/src/main/java/soup/neumorphism/internal/shape/PressedShape.kt index c279331..522802d 100644 --- a/neumorphism/src/main/java/soup/neumorphism/internal/shape/PressedShape.kt +++ b/neumorphism/src/main/java/soup/neumorphism/internal/shape/PressedShape.kt @@ -24,7 +24,7 @@ internal class PressedShape( this.drawableState = newDrawableState } - override fun draw(canvas: Canvas, outlinePath: Path) { + override fun draw(canvas: Canvas, outlinePath: Path, bounds: Rect) { canvas.withClip(outlinePath) { shadowBitmap?.let { val left: Float diff --git a/neumorphism/src/main/java/soup/neumorphism/internal/shape/Shape.kt b/neumorphism/src/main/java/soup/neumorphism/internal/shape/Shape.kt index 36ce12d..7fe94ed 100644 --- a/neumorphism/src/main/java/soup/neumorphism/internal/shape/Shape.kt +++ b/neumorphism/src/main/java/soup/neumorphism/internal/shape/Shape.kt @@ -3,10 +3,11 @@ package soup.neumorphism.internal.shape import android.graphics.Canvas import android.graphics.Path import android.graphics.Rect +import android.graphics.RectF import soup.neumorphism.NeumorphShapeDrawable.NeumorphShapeDrawableState internal interface Shape { fun setDrawableState(newDrawableState: NeumorphShapeDrawableState) - fun draw(canvas: Canvas, outlinePath: Path) + fun draw(canvas: Canvas, outlinePath: Path, bounds: Rect) fun updateShadowBitmap(bounds: Rect) }