annotate Android/java/org/madbutterfly/MBView.java @ 1392:cd5fb45bc247

Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
author wycc
date Sun, 27 Mar 2011 08:27:03 +0800
parents c468e397614d
children
rev   line source
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 package org.madbutterfly;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 import android.view.SurfaceView;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 import android.view.SurfaceHolder;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 import android.content.Context;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 import android.graphics.Canvas;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 import android.graphics.Bitmap;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 import android.graphics.Paint;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 import android.graphics.Xfermode;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 import android.graphics.PorterDuff;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 import android.graphics.PorterDuffXfermode;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12
499
2d7df44e6299 Make classes public
Thinker K.F. Li <thinker@branda.to>
parents: 493
diff changeset
13 public class MBView extends SurfaceView {
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 redraw_man rdman;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 Canvas cr, backend;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 Bitmap cr_bmap, backend_bmap;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 Paint copy_pnt;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 int w, h;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 public MBView(Context context) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 super(context);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 Paint paint;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 Xfermode mode;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 rdman = null;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 cr = null;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 backend = null;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 mode = new PorterDuffXfermode(PorterDuff.Mode.SRC);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 copy_pnt = new Paint();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 copy_pnt.setXfermode(mode);
505
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
32 w = 100;
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
33 h = 100;
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 public redraw_man get_rdman() {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 if(rdman != null)
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 return rdman;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 w = getWidth();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 h = getHeight();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 cr = new Canvas(cr_bmap);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 backend = new Canvas(backend_bmap);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 rdman = new redraw_man(cr, backend, this);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 return rdman;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 this.w = w;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 this.h = h;
505
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
56
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
57 if(rdman == null) {
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
58 get_rdman();
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
59 return;
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
60 }
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
61
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 cr_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 cr.setBitmap(cr_bmap);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 backend_bmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 backend.setBitmap(backend_bmap);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 public void redraw() {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 SurfaceHolder holder;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 Canvas canvas;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 holder = getHolder();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 canvas = holder.lockCanvas();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 canvas.drawBitmap(backend_bmap, 0, 0, copy_pnt);
505
c468e397614d Fix issue of initialize rdman and add shape::stroke_width().
Thinker K.F. Li <thinker@branda.to>
parents: 499
diff changeset
75 holder.unlockCanvasAndPost(canvas);
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 }