annotate Android/java/org/madbutterfly/redraw_man.java @ 528:d687d3395264 Android_Skia

Clear variables and draw root coord. Although root coord is never in zeroing list, now, it still need to be redrawed after redrawing other zeroed coords.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 23 Dec 2009 10:33:51 +0800
parents 2d7df44e6299
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.graphics.Canvas;
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 java.util.ArrayList;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6
499
2d7df44e6299 Make classes public
Thinker K.F. Li <thinker@branda.to>
parents: 493
diff changeset
7 public class redraw_man {
493
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 Canvas _cr, _backend;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 int _rdman_addr; // address of redraw_man_t
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 coord root;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 ArrayList paints;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 MBView _view;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 public redraw_man(Canvas cr, Canvas backend, MBView view) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 int addr;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 _view = view;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 _cr = cr;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 _backend = backend;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 _rdman_addr = _jni.redraw_man_new(cr, backend);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 addr = _jni.rdman_get_root(_rdman_addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 root = new coord(this, addr);
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 paints = new ArrayList();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 static void _invalid_subtree(coord subtree) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 int i, sz;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 coord child;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 shape member;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 subtree.invalid();
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 sz = subtree.members.size();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 for(i = 0; i < sz; i ++) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 member = (shape)subtree.members.get(i);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 member.invalid();
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
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 sz = subtree.children.size();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 for(i = 0; i < sz; i++) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 child = (coord)subtree.children.get(i);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 _invalid_subtree(child);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 }
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 protected void finalize() {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
49 int i, sz;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 paint pnt;
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 _invalid_subtree(root);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
54 /* invalid paints */
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
55 sz = paints.size();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 for(i = 0; i < sz; i++) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 pnt = (paint)paints.get(i);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 pnt.invalid();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
61 _jni.redraw_man_free(_rdman_addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
62 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 public coord get_root() {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65 return root;
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 coord coord_new(coord parent) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 int addr;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 coord child;
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 addr = _jni.rdman_coord_new(_rdman_addr, parent.addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 child = new coord(this, addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 parent.children.add(child);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 return child;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 public void coord_free(coord obj) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 obj.finalize();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
81 obj.invalid();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
84 public shape shape_path_new(String pathdata) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
85 int addr;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86 shape new_shape;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
88 addr = _jni.rdman_shape_path_new(_rdman_addr, pathdata);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 new_shape = new shape(this, addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 return new_shape;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 public paint paint_color_new(float r, float g, float b, float a) {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 int addr;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
96 paint pnt;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
97
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 addr = _jni.rdman_paint_color_new(_rdman_addr, r, g, b, a);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 pnt = new paint(this, addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 return pnt;
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
102 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
103
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
104 public void redraw() {
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
105 _jni.rdman_redraw_all(_rdman_addr);
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 _view.redraw();
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107 }
1b6228092a57 Java code for MadButterfly JNI.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
108 }