Mercurial > MadButterfly
comparison Android/java/org/madbutterfly/MBView.java @ 572:dcd7adb2c0fc
Merge from Android_Skia
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 09 Jun 2010 17:30:09 +0800 |
parents | c468e397614d |
children |
comparison
equal
deleted
inserted
replaced
463:aa2b388fba4e | 572:dcd7adb2c0fc |
---|---|
1 package org.madbutterfly; | |
2 | |
3 import android.view.SurfaceView; | |
4 import android.view.SurfaceHolder; | |
5 import android.content.Context; | |
6 import android.graphics.Canvas; | |
7 import android.graphics.Bitmap; | |
8 import android.graphics.Paint; | |
9 import android.graphics.Xfermode; | |
10 import android.graphics.PorterDuff; | |
11 import android.graphics.PorterDuffXfermode; | |
12 | |
13 public class MBView extends SurfaceView { | |
14 redraw_man rdman; | |
15 Canvas cr, backend; | |
16 Bitmap cr_bmap, backend_bmap; | |
17 Paint copy_pnt; | |
18 int w, h; | |
19 | |
20 public MBView(Context context) { | |
21 super(context); | |
22 Paint paint; | |
23 Xfermode mode; | |
24 | |
25 rdman = null; | |
26 cr = null; | |
27 backend = null; | |
28 | |
29 mode = new PorterDuffXfermode(PorterDuff.Mode.SRC); | |
30 copy_pnt = new Paint(); | |
31 copy_pnt.setXfermode(mode); | |
32 w = 100; | |
33 h = 100; | |
34 } | |
35 | |
36 public redraw_man get_rdman() { | |
37 if(rdman != null) | |
38 return rdman; | |
39 | |
40 w = getWidth(); | |
41 h = getHeight(); | |
42 | |
43 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); | |
44 cr = new Canvas(cr_bmap); | |
45 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); | |
46 backend = new Canvas(backend_bmap); | |
47 | |
48 rdman = new redraw_man(cr, backend, this); | |
49 | |
50 return rdman; | |
51 } | |
52 | |
53 protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
54 this.w = w; | |
55 this.h = h; | |
56 | |
57 if(rdman == null) { | |
58 get_rdman(); | |
59 return; | |
60 } | |
61 | |
62 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); | |
63 cr.setBitmap(cr_bmap); | |
64 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); | |
65 backend.setBitmap(backend_bmap); | |
66 } | |
67 | |
68 public void redraw() { | |
69 SurfaceHolder holder; | |
70 Canvas canvas; | |
71 | |
72 holder = getHolder(); | |
73 canvas = holder.lockCanvas(); | |
74 canvas.drawBitmap(backend_bmap, 0, 0, copy_pnt); | |
75 holder.unlockCanvasAndPost(canvas); | |
76 } | |
77 } |