@@ -5,6 +5,7 @@ import android.content.Context
5
5
import android.graphics.Bitmap
6
6
import android.graphics.Canvas
7
7
import android.graphics.Color
8
+ import android.graphics.Matrix
8
9
import android.graphics.Paint
9
10
import android.graphics.Point
10
11
import android.graphics.PointF
@@ -394,23 +395,35 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
394
395
}
395
396
396
397
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() }
414
427
}
415
428
}
416
429
0 commit comments