My main goal is to subtract Path from a predefined area (also created using Path) in Android 1.6.
In any case, so that Region.setPath handles the traversed path in the same way that the canvas refers to the stroked path (is that what my users see)?
I understand that style is used to draw on canvas, but I need behavior to reflect what is drawn on the canvas, and the path drawn is Stroked.
The behavior works when adding shapes to a path (path.addRect, path.addCircle), but not when using lineTo, quadTo, cubeTo. My only other option is to make a path consisting of nothing but rectangles or circles.
public class ComplexRegions extends Activity { static Display display; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); display = getWindowManager().getDefaultDisplay(); setContentView(new SampleView(this)); } private static class SampleView extends View { Path orig_path, finger_path; Paint dirty_paint, fingerpaint, temp_paint; Region orig_region, clip, fingerregion, tempregion; Canvas c; int h, w; public float mX, mY, dx, dy; boolean b; public SampleView(Context context) { super(context); fingerregion = new Region(); tempregion = new Region(); orig_region = new Region(); clip = new Region(); orig_path = new Path(); finger_path = new Path(); dirty_paint = new Paint(); dirty_paint.setStyle(Paint.Style.STROKE); dirty_paint.setColor(Color.BLUE); dirty_paint.setStrokeWidth(5); dirty_paint.setStrokeCap(Paint.Cap.ROUND); dirty_paint.setStrokeJoin(Paint.Join.ROUND); dirty_paint.setAntiAlias(false); fingerpaint = new Paint(); fingerpaint.setColor(Color.GREEN); fingerpaint.setStrokeWidth(10); fingerpaint.setStyle(Paint.Style.STROKE); fingerpaint.setStrokeCap(Paint.Cap.ROUND); fingerpaint.setStrokeJoin(Paint.Join.ROUND); fingerpaint.setAntiAlias(false); temp_paint = new Paint(); temp_paint.setColor(Color.RED); temp_paint.setStrokeWidth(1); temp_paint.setStyle(Paint.Style.STROKE); temp_paint.setStrokeCap(Paint.Cap.ROUND); temp_paint.setStrokeJoin(Paint.Join.ROUND); temp_paint.setAntiAlias(false); w = display.getWidth(); h = display.getHeight(); clip.set(0, 0, w, h); orig_path.addRect(w*0.25f, h*0.55f, w*0.65f, h*0.65f, Path.Direction.CW); orig_region.setPath(orig_path, clip); } @Override protected void onDraw(Canvas c) { c.drawPath(orig_path, dirty_paint); c.drawPath(finger_path, fingerpaint);
}
source share