/*
 * Copyright (C) 2013 Chen Hui <calmer91@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package master.flame.danmaku.controller;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;

public class DrawHelper {

    public static Paint paint;
    static {
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(50);
        //paint.setAntiAlias(true);
    }

    public static void drawText(Canvas canvas, String text) {

        canvas.drawText(text, 10, canvas.getHeight() - 50, paint);

    }

    public static void drawDuration(Canvas canvas, String text) {
        canvas.drawText(text, 100, 100, paint);
    }

    public static void drawCircle(float cx, float cy, Canvas canvas) {
        canvas.drawCircle(cx, cy, 50, paint);
    }

    public static void clearCanvas(Canvas canvas) {
        canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    }
}

@@ -805,16 +805,118 @@
 erDuff;%0D
+%0Aimport android.graphics.PorterDuffXfermode;%0D%0Aimport android.graphics.Rect;%0D%0Aimport android.util.Log;%0D
 %0A%0D%0Apubli
@@ -963,21 +963,53 @@
 c Paint 
-paint
+PAINT;%0D%0A%0D%0A    public static Rect RECT
 ;%0D%0A    s
@@ -1025,21 +1025,21 @@
         
-paint
+PAINT
  = new P
@@ -1059,101 +1059,99 @@
     
-paint.setColor(Color.RED);%0D%0A        paint.setTextSize(50);%0D%0A        //paint.setAntiAlias(true
+PAINT.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));%0D%0A        RECT = new Rect(
 );%0D%0A
@@ -1279,29 +1279,29 @@
 ght() - 50, 
-paint
+PAINT
 );%0D%0A%0D%0A    %7D%0D
@@ -1330,20 +1330,19 @@
 oid 
-drawDuration
+clearCanvas
 (Can
@@ -1347,37 +1347,24 @@
 anvas canvas
-, String text
 ) %7B%0D%0A       
@@ -1379,162 +1379,322 @@
 draw
-Text(text, 100, 100, paint);%0D%0A    %7D%0D%0A%0D%0A    public static void drawCircle(float cx, float cy, Canvas canvas) %7B%0D%0A        canvas.drawCircle(cx, cy, 50, paint
+Color(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);%0D%0A    %7D%0D%0A%0D%0A    public static void clearCanvas(Canvas canvas, int left, int top, int right, int bottom) %7B%0D%0A        RECT.set(Math.max(0, left), Math.max(0, top), Math.min(canvas.getWidth(),right), Math.min(canvas.getHeight(),bottom));%0D%0A        clearCanvas(canvas, RECT
 );%0D%0A
@@ -1699,37 +1699,38 @@
 %0D%0A    %7D%0D%0A%0D%0A    p
-ublic
+rivate
  static void cle
@@ -1743,32 +1743,43 @@
 as(Canvas canvas
+, Rect rect
 ) %7B%0D%0A        can
@@ -1779,65 +1779,300 @@
     
-canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR
+Log.e(%22DrawHelper rect%22, rect.toString());%0D%0A        if (rect.width() %3C= 0 %7C%7C rect.height() %3C= 0) %7B%0D%0A            return;%0D%0A        %7D%0D%0A        if (rect.contains(0, 0, canvas.getWidth(), canvas.getHeight()))%0D%0A            clearCanvas(canvas);%0D%0A        else%0D%0A            canvas.drawRect(rect, PAINT
 );%0D%0A

Add new method for DrawHelper