@@ -5,6 +5,7 @@ import android.content.Context
55import android.graphics.Bitmap
66import android.graphics.Canvas
77import android.graphics.Color
8+ import android.graphics.Matrix
89import android.graphics.Paint
910import android.graphics.Point
1011import android.graphics.PointF
@@ -394,23 +395,35 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
394395 }
395396
396397 private fun bucketFill () {
397- val touchedX = mCurX.toInt()
398- val touchedY = mCurY.toInt()
399- if (contains(touchedX, touchedY)) {
400- val bitmap = getBitmap()
401- val color = mPaintOptions.color
402-
403- ensureBackgroundThread {
404- val path = bitmap.vectorFloodFill(
405- color = color,
406- x = touchedX,
407- y = touchedY,
408- tolerance = FLOOD_FILL_TOLERANCE
409- )
410- val paintOpts = PaintOptions (color = color, strokeWidth = 5f )
411- addOperation(path, paintOpts)
412- post { invalidate() }
413- }
398+ if (mCenter == null ) {
399+ mCenter = PointF (width / 2f , height / 2f )
400+ }
401+
402+ val touchedX = mLastTouchX.toInt()
403+ val touchedY = mLastTouchY.toInt()
404+ if (! contains(touchedX, touchedY)) return
405+
406+ val toScreen = Matrix ().apply {
407+ preTranslate(mPosX, mPosY)
408+ preScale(mScaleFactor, mScaleFactor, mCenter!! .x, mCenter!! .y)
409+ }
410+
411+ val fromScreen = Matrix ().apply { toScreen.invert(this ) }
412+
413+ val bitmap = getBitmap()
414+ val color = mPaintOptions.color
415+ ensureBackgroundThread {
416+ val path = bitmap.vectorFloodFill(
417+ color = color,
418+ x = touchedX,
419+ y = touchedY,
420+ tolerance = FLOOD_FILL_TOLERANCE
421+ )
422+
423+ path.transform(fromScreen)
424+ val paintOpts = PaintOptions (color = color, strokeWidth = 5f )
425+ addOperation(path, paintOpts)
426+ post { invalidate() }
414427 }
415428 }
416429
0 commit comments