Mercurial > MadButterfly
annotate Android/jni/mbfly.cpp @ 1222:03daff2d939c
Add a space after every comma in an argument list
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Thu, 06 Jan 2011 09:37:24 +0800 |
parents | 0d9f1f4d3154 |
children |
rev | line source |
---|---|
496 | 1 #include <SkCanvas.h> |
2 | |
3 #define DECL_C extern "C" { | |
4 #define END_C } | |
5 | |
6 DECL_C | |
7 | |
8 #include <stdio.h> | |
9 #include <mb.h> | |
10 #include <jni.h> | |
11 | |
516
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
12 #define ASSERT(x) |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
13 |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
14 |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
15 extern mbe_t *skia_mbe_create_by_canvas(SkCanvas *canvas); |
496 | 16 |
17 jint Java_org_madbutterfly__1jni_redraw_1man_1new(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
18 jobject cls, |
496 | 19 jobject cr, |
20 jobject backend) { | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
21 jclass canvas_cls; |
496 | 22 jfieldID fid; |
23 SkCanvas *_cr, *_backend; | |
24 redraw_man_t *rdman; | |
516
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
25 mbe_t *mbe1, *mbe2; |
496 | 26 |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
27 canvas_cls = env->GetObjectClass(cr); |
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
28 fid = env->GetFieldID(canvas_cls, "mNativeCanvas", "I"); |
496 | 29 _cr = (SkCanvas *)env->GetIntField(cr, fid); |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
30 canvas_cls = env->GetObjectClass(backend); |
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
31 fid = env->GetFieldID(canvas_cls, "mNativeCanvas", "I"); |
496 | 32 _backend = (SkCanvas *)env->GetIntField(backend, fid); |
516
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
33 |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
34 mbe1 = skia_mbe_create_by_canvas(_cr); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
35 mbe2 = skia_mbe_create_by_canvas(_backend); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
36 ASSERT(mbe1 != NULL && mbe2 != NULL); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
37 |
496 | 38 rdman = (redraw_man_t *)malloc(sizeof(redraw_man_t)); |
516
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
39 ASSERT(rdman != NULL); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
40 redraw_man_init(rdman, mbe1, mbe2); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
41 |
496 | 42 return (jint)rdman; |
43 } | |
44 | |
45 void Java_org_madbutterfly__1jni_redraw_1man_1free(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
46 jobject cls, |
496 | 47 jint rdman) { |
48 redraw_man_destroy((redraw_man_t *)rdman); | |
49 free((redraw_man_t *)rdman); | |
50 } | |
51 | |
52 jint Java_org_madbutterfly__1jni_rdman_1add_1shape(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
53 jobject cls, |
496 | 54 jint rdman, |
55 jint shape, | |
56 jint coord) { | |
57 jint r; | |
58 | |
59 r = rdman_add_shape((redraw_man_t *)rdman, | |
60 (shape_t *)shape, | |
61 (coord_t *)coord); | |
62 return r; | |
63 } | |
64 | |
65 jint Java_org_madbutterfly__1jni_rdman_1get_1root(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
66 jobject cls, |
496 | 67 jint rdman) { |
68 jint root; | |
69 | |
70 root = (jint)rdman_get_root((redraw_man_t *)rdman); | |
71 return root; | |
72 } | |
73 | |
74 jint Java_org_madbutterfly__1jni_rdman_1redraw_1all(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
75 jobject cls, |
496 | 76 jint rdman) { |
77 jint r; | |
78 | |
79 r = rdman_redraw_all((redraw_man_t *)rdman); | |
80 return r; | |
81 } | |
82 | |
83 void Java_org_madbutterfly__1jni_rdman_1paint_1fill(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
84 jobject cls, |
496 | 85 jint rdman, |
86 jint paint, | |
87 jint shape) { | |
88 rdman_paint_fill((redraw_man_t *)rdman, | |
89 (paint_t *)paint, | |
90 (shape_t *)shape); | |
91 } | |
92 | |
93 void Java_org_madbutterfly__1jni_rdman_1paint_1stroke(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
94 jobject cls, |
496 | 95 jint rdman, |
96 jint paint, | |
97 jint shape) { | |
98 rdman_paint_stroke((redraw_man_t *)rdman, | |
99 (paint_t *)paint, | |
100 (shape_t *)shape); | |
101 } | |
102 | |
103 jint Java_org_madbutterfly__1jni_rdman_1coord_1new(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
104 jobject cls, |
496 | 105 jint rdman, |
106 jint parent) { | |
107 jint coord; | |
108 | |
109 coord = (jint)rdman_coord_new((redraw_man_t *)rdman, | |
110 (coord_t *)parent); | |
111 return coord; | |
112 } | |
113 | |
114 void Java_org_madbutterfly__1jni_rdman_1coord_1free(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
115 jobject cls, |
496 | 116 jint rdman, |
117 jint coord) { | |
118 rdman_coord_free((redraw_man_t *)rdman, | |
119 (coord_t *)coord); | |
120 } | |
121 | |
122 void Java_org_madbutterfly__1jni_rdman_1coord_1subtree_1free(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
123 jobject cls, |
496 | 124 jint rdman, |
125 jint coord) { | |
126 rdman_coord_subtree_free((redraw_man_t *)rdman, | |
127 (coord_t *)coord); | |
128 } | |
129 | |
130 void Java_org_madbutterfly__1jni_rdman_1coord_1changed(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
131 jobject cls, |
496 | 132 jint rdman, |
133 jint coord) { | |
134 rdman_coord_changed((redraw_man_t *)rdman, | |
135 (coord_t *)coord); | |
136 } | |
137 | |
138 void Java_org_madbutterfly__1jni_rdman_1shape_1changed(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
139 jobject cls, |
496 | 140 jint rdman, |
141 jint shape) { | |
142 rdman_shape_changed((redraw_man_t *)rdman, | |
143 (shape_t *)shape); | |
144 } | |
145 | |
146 void Java_org_madbutterfly__1jni_rdman_1shape_1free(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
147 jobject cls, |
496 | 148 jint rdman, |
149 jint shape) { | |
150 rdman_shape_free((redraw_man_t *)rdman, | |
151 (shape_t *)shape); | |
152 } | |
153 | |
154 jint Java_org_madbutterfly__1jni_rdman_1shape_1path_1new(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
155 jobject cls, |
496 | 156 jint rdman, |
157 jstring data) { | |
158 const char *str; | |
159 jint shape; | |
160 | |
161 str = env->GetStringUTFChars(data, NULL); | |
162 shape = (jint)rdman_shape_path_new((redraw_man_t *)rdman, (char *)str); | |
163 env->ReleaseStringUTFChars(data, str); | |
164 | |
165 return shape; | |
166 } | |
167 | |
516
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
168 void Java_org_madbutterfly__1jni_sh_1set_1stroke_1width(JNIEnv *env, |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
169 jobject cls, |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
170 jint shape, |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
171 jfloat w) { |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
172 sh_set_stroke_width((shape_t *)shape, w); |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
173 } |
0d9f1f4d3154
set stroke width for a shape.
Thinker K.F. Li <thinker@branda.to>
parents:
502
diff
changeset
|
174 |
496 | 175 jint Java_org_madbutterfly__1jni_rdman_1paint_1color_1new(JNIEnv *env, |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
176 jobject cls, |
496 | 177 jint rdman, |
178 jfloat r, jfloat g, | |
179 jfloat b, jfloat a) { | |
180 jint paint; | |
181 | |
182 paint = (jint)rdman_paint_color_new((redraw_man_t *)rdman, | |
183 r, g, b, a); | |
184 return paint; | |
185 } | |
186 | |
187 jint Java_org_madbutterfly__1jni_rdman_1paint_1free(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
188 jobject cls, |
496 | 189 jint rdman, |
190 jint paint) { | |
191 jint r; | |
192 | |
193 r = rdman_paint_free((redraw_man_t *)rdman, | |
194 (paint_t *)paint); | |
195 return r; | |
196 } | |
197 | |
198 void Java_org_madbutterfly__1jni_paint_1color_1set(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
199 jobject cls, |
496 | 200 jint paint, |
201 jfloat r, jfloat g, | |
202 jfloat b, jfloat a) { | |
203 paint_color_set((paint_t *)paint, r, g, b, a); | |
204 } | |
205 | |
206 jfloatArray Java_org_madbutterfly__1jni_paint_1color_1get(JNIEnv *env, | |
502
a53fc3eff8f1
Every static native method has the 2rd argument as class object.
Thinker K.F. Li <thinker@branda.to>
parents:
496
diff
changeset
|
207 jobject cls, |
496 | 208 jint paint) { |
209 co_comp_t r, g, b, a; | |
210 jfloat color[4]; | |
211 jfloatArray result; | |
212 | |
213 paint_color_get((paint_t *)paint, &r, &g, &b, &a); | |
214 color[0] = r; | |
215 color[1] = g; | |
216 color[2] = b; | |
217 color[3] = a; | |
218 | |
219 result = env->NewFloatArray(4); | |
220 env->SetFloatArrayRegion(result, 0, 4, color); | |
221 | |
222 return result; | |
223 } | |
224 | |
225 END_C | |
226 |