So I'm currently building kids coloring book app. I want to restrict the draw area so it will only can draw path in the selected area. For example, if I touch the horn, then the draw area is only the space inside the border of the horn. For now, I only able to draw the path in the bitmap (the draw area is not restricted).
First picture: Touched area.
Second picture: User can only draw path inside the blue space.
For now, this is my onDraw code:
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(mBitmapCanvas, 0f, 0f, paintCanvas);
canvas.drawPath(mPaths, drawPaint);
}
onTouch:
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
if (isEditable){
switch (motionEvent.getAction()) {
case 0:
if (paths.isEmpty()) {
mBitmap = Bitmap.createBitmap(mBitmapCanvas);
paths.add(mBitmap);
}
mPaths.reset();
setColor(ShaderInt);
mPaths.moveTo(x, y);
mX = x;
mY = y;
invalidate();
break;
case 1:
mPaths.lineTo(mX, mY);
mCanvas.drawPath(mPaths, drawPaint);
mCanvas.drawPath(mPaths, drawPaint);
mBitmap = Bitmap.createBitmap(mBitmapCanvas);
paths.add(mBitmap);
mPaths.reset();
invalidate();
break;
case 2:
float abs = Math.abs(x - this.mX);
float abs2 = Math.abs(y - this.mY);
if (abs >= TOUCH_TOLERANCE || abs2 >= TOUCH_TOLERANCE) {
this.mPaths.quadTo(this.mX, this.mY, (this.mX + x) / 2.0f, (this.mY + y) / 2.0f);
this.mX = x;
this.mY = y;
}
invalidate();
break;
default:
return false;
}
} else {
return false;
}
invalidate();
return true;
}
Is there any way so I can make the draw area restricted to the touched/selected area? Any help will be so appreciated, thank you!