Code example for Path

Methods: closecomputeBoundslineTomoveToquadToreset

0
        this.mY1 = y1;
        this.mCtrlx = ctrlx;
        this.mCtrly = ctrly;
        this.mX2 = x2;
        this.mY2 = y2;
        this.mPath = new Path();
         
        update(); 
    } 
     
    /** 
     * Creates a quadratic curve shape, copying the contents from the src QuadCurveShape. 
     * @param curve The quadratic curve shape to copy from when initializing the new quadratic curve shape 
     */ 
    public QuadCurveShape(QuadCurveShape curve) {
        this.mX1 = curve.mX1;
        this.mY1 = curve.mY1;
        this.mCtrlx = curve.mCtrlx;
        this.mCtrly = curve.mCtrly;
        this.mX2 = curve.mX2;
        this.mY2 = curve.mY2;
        this.mPath = curve.mPath;
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public void clip(Canvas canvas) {
        // can not clip 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method has no effect because the curve shape is not closed shape.  
     */ 
    public boolean contains(float x, float y) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method has no effect 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 has no effect because the curve shape is not closed shape.  
     */ 
    public boolean contains(PointF point) {
        return false; 
    } 
 
    /** 
     * {@inheritDoc}  
     * @note This method has no effect because the curve shape is not closed shape.  
     */ 
    public boolean contains(RectShape rect) {
        return false; 
    } 
 
    /** 
     * {@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}  
     */ 
    @Deprecated 
    public RectShape getBounds() {
        return new RectShape(this.rectBuffer);
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    public void getBounds(RectShape rect) {
        rect.setRectF(this.rectBuffer);
    } 
     
    /** 
     * {@inheritDoc}  
     */ 
    public Path getPath() {
        return mPath;
    } 
 
    /** 
     * {@inheritDoc}  
     */ 
    //TODO change more appropriate method 
    public boolean intersects(float x, float y, float width, float height) {
        float tmpx, tmpy, tmpw, tmph;
        Region region = new Region(mRegion);
        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); 
        } 
        region.getBounds();
        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.mCtrlx += x;
        this.mCtrly += 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 ctrlx The x-coordinate of the control point on a quadratic curve 
     * @param ctrlyThe y-coordinate of the control point on a quadratic 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 ctrlx, float ctrly, float x2, float y2) {
        this.mX1 = x1;
        this.mY1 = y1;
        this.mCtrlx = ctrlx;
        this.mCtrly = ctrly;
        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 ctrlx The x-coordinate of the control point on a quadratic curve 
     * @param ctrlyThe y-coordinate of the control point on a quadratic 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 ctrlx, double ctrly, double x2, double y2) {
        this.mX1 = (float)x1;
        this.mY1 = (float)y1;
        this.mCtrlx = (float)ctrlx;
        this.mCtrly = (float)ctrly;
        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.quadTo(mCtrlx, mCtrly, mX2, mY2);
         
        mPath.computeBounds(rectBuffer, false);
        mRegion = new Region((int)rectBuffer.left, (int)rectBuffer.top, (int)rectBuffer.right, (int)rectBuffer.bottom);
         
        mPath.lineTo(mX2 + 1, mY2);
        mPath.quadTo(mCtrlx + 1, mCtrly, mX1 + 1, mY1);
        mPath.close();
         
        mRegion.setPath(mPath, mRegion);
    } 
     
    /**