Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove one shape from another with android.graphics.Path

what I'm trying to paint is the following: Screenshot But with a plus instead of a minus sign in the center of the arrow.

I want to subtract the 'minus' from the white base shape. Strangely that works fine for the minus, but if I draw a plus sign instead it does not subtract it anymore but adds it to the underlying path.

My Code for subtracting the minus looks like this

Path base = new Path();
[... draw the arrow ]

Path subtract = new Path();
subtract.moveTo(-xBarWidth/2, -xBarHeight/2); // center the path
subtract.rLineTo(xBarWidth, 0);
subtract.rLineTo(0, xBarHeight);
subtract.rLineTo(-xBarWidth, 0);
subtract.rLineTo(0, -xBarHeight);

base.add(subtract);

[in paint() function: canvas.draw(base, paint)]

The code for the plus sign:

int halfBarWidth = xBarWidth/2;
subtract.moveTo(-halfBarWidth, -xBarHeight/2);
subtract.rLineTo(halfBarWidth, 0);
subtract.rLineTo(0, halfBarWidth);
subtract.rLineTo(xBarHeight, 0);
subtract.rLineTo(0, -halfBarWidth);
subtract.rLineTo(halfBarWidth, 0);
subtract.rLineTo(0, -xBarHeight);
subtract.rLineTo(-halfBarWidth, 0);
subtract.rLineTo(0, -halfBarWidth);
subtract.rLineTo(-xBarHeight, 0);
subtract.rLineTo(0, halfBarWidth);
subtract.rLineTo(-halfBarWidth, 0);
subtract.rLineTo(0, xBarHeight);

However, now it draws a white plus on top of the arrow. I tried subtract.setFillType(FillType.INVERSE_EVEN_ODD) but it didn't change anything.

Unfortunately I can't find any help in the api.

like image 900
user823255 Avatar asked Jan 01 '12 22:01

user823255


1 Answers

maybe this will help someone: I had to set the fillType of base to EVEN_ODD

base.setFillType(FillType.EVEN_ODD);
like image 136
user823255 Avatar answered Nov 15 '22 02:11

user823255