Code example for Path

Methods: closecomputeBoundscubicTolineTomoveToreset

0
        this.mCtrly1 = ctrly1;
        this.mCtrlx2 = ctrlx2;
        this.mCtrly2 = ctrly2;
        this.mX2 = x2;
        this.mY2 = y2;
        this.mPath = new Path();
        this.mRegion = new Region();
         
        update(); 
    } 
     
    /** 
     * Creates a cubic curve shape, copying the contents from the src CubicCurveShape. 
     * @param curve The cubic curve shape to copy from when initializing the new cubic curve shape 
     */ 
    public CubicCurveShape(CubicCurveShape curve) {
        this.mX1 = curve.mX1;
        this.mY1 = curve.mY1;
        this.mCtrlx1 = curve.mCtrlx1;
        this.mCtrly1 = curve.mCtrly1;
        this.mCtrlx2 = curve.mCtrlx2;
        this.mCtrly2 = curve.mCtrly2;
        this.mX2 = curve.mX2;
        this.mY2 = curve.mY2;
        this.mPath = curve.mPath;
        this.mRegion = curve.mRegion;
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public Path getPath() {
        return mPath;
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void draw(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void fill(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void fillAndStroke(Canvas canvas, Paint paint) {
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawPath(mPath, paint);
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method has no effect because the curve shape is not closed shape.  
     */ 
    public void clip(Canvas canvas) {
        // can not clip 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method always returns false because the curve shape is not closed shape.  
     */ 
    public boolean contains(float x, float y) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method always returns false because the curve shape is not closed shape.  
     */ 
    public boolean contains(float x, float y, float width, float height) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method always returns false because the curve shape is not closed shape.  
     */ 
    public boolean contains(PointF point) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method always returns false because the curve shape is not closed shape.  
     */ 
    public boolean contains(RectShape rect) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    @Deprecated 
    public RectShape getBounds() {
        return new RectShape(regionBuffer.getBounds());
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void getBounds(RectShape rect) {
        rect.setRect(regionBuffer.getBounds());
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    //TODO change more appropriate method 
    public boolean intersects(float x, float y, float width, float height) {
        Region region = new Region(mRegion);
        float tmpx, tmpy, tmpw, tmph;
 
        if (x < width + x) {
            tmpx = x;
            tmpw = width;
        } 
        else{ 
            tmpx = width + x;
            tmpw = Math.abs(width); 
        } 
        if (y < height + y) {
            tmpy = y;
            tmph = height;
        } 
        else{ 
            tmpy = height + y;
            tmph = Math.abs(height); 
        } 
        return region.op((int)tmpx, (int)tmpy, (int)(tmpx + tmpw), (int)(tmpy + tmph), Op.INTERSECT);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(Rect rect) {
        return intersects(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public boolean intersects(RectShape rect) {
        return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void translate(float x, float y) {
        this.mX1 += x;
        this.mY1 += y;
        this.mCtrlx1 += x;
        this.mCtrly1 += y;
        this.mCtrlx2 += x;
        this.mCtrly2 += y;
        this.mX2 += x;
        this.mY2 += y;
         
        update(); 
    } 
     
    /** 
     * Sets the curve parameters from starting point (x1,y1), approaching control points 
     * (ctrlx1, ctrly1) and (ctrlx2, ctrly2), and ending at (x2,y2). 
     * @param x1 The x-coordinate of starting point 
     * @param y1 The y-coordinate of starting point 
     * @param ctrlx1 The x-coordinate of the 1st control point on a cubic curve 
     * @param ctrly1 The y-coordinate of the 1st control point on a cubic curve 
     * @param ctrlx2 The x-coordinate of the 2nd control point on a cubic curve 
     * @param ctrly2 The y-coordinate of the 2nd control point on a cubic curve 
     * @param x2 The x-coordinate of ending point 
     * @param y2 The y-coordinate of ending point 
     */ 
    public void setCurve(float x1, float y1, float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x2, float y2) {
        this.mX1 = x1;
        this.mY1 = y1;
        this.mCtrlx1 = ctrlx1;
        this.mCtrly1 = ctrly1;
        this.mCtrlx2 = ctrlx2;
        this.mCtrly2 = ctrly2;
        this.mX2 = x2;
        this.mY2 = y2;
         
        update(); 
    } 
     
    /** 
     * Sets the curve parameters from starting point (x1,y1), approaching control points 
     * (ctrlx1, ctrly1) and (ctrlx2, ctrly2), and ending at (x2,y2). 
     * @param x1 The x-coordinate of starting point 
     * @param y1 The y-coordinate of starting point 
     * @param ctrlx1 The x-coordinate of the 1st control point on a cubic curve 
     * @param ctrly1 The y-coordinate of the 1st control point on a cubic curve 
     * @param ctrlx2 The x-coordinate of the 2nd control point on a cubic curve 
     * @param ctrly2 The y-coordinate of the 2nd control point on a cubic curve 
     * @param x2 The x-coordinate of ending point 
     * @param y2 The y-coordinate of ending point 
     */ 
    public void setCurve(double x1, double y1, double ctrlx1, double ctrly1, double ctrlx2, double ctrly2, double x2, double y2) {
        this.mX1 = (float)x1;
        this.mY1 = (float)y1;
        this.mCtrlx1 = (float)ctrlx1;
        this.mCtrly1 = (float)ctrly1;
        this.mCtrlx2 = (float)ctrlx2;
        this.mCtrly2 = (float)ctrly2;
        this.mX2 = (float)x2;
        this.mY2 = (float)y2;
         
        update(); 
    } 
 
    /** 
     * Updates the internal data required to draw. 
     */ 
    private void update() { 
        mPath.reset();
        mPath.moveTo(mX1, mY1);
        mPath.cubicTo(mCtrlx1, mCtrly1, mCtrlx2, mCtrly2, mX2, mY2);
         
        RectF rect = new RectF();
        mPath.computeBounds(rect, false);
        mRegion = new Region((int)rect.left, (int)rect.top, (int)rect.right, (int)rect.bottom);
        regionBuffer.set(mRegion);
         
        mPath.lineTo(mX2 + 1, mY2);
        mPath.cubicTo(mCtrlx2 + 1, mCtrly2, mCtrlx1 + 1, mCtrly1, mX1 + 1, mY1);
        mPath.close();
 
        mRegion.setPath(mPath, mRegion);
    } 
     
    /**