annotate nodejs/paints.cc @ 750:199bac90b90a

Add linearGradient support.
author wycc
date Thu, 26 Aug 2010 00:16:12 +0800
parents d0ee92a96c47
children a49358b040b5
rev   line source
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <v8.h>
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 extern "C" {
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "mb.h"
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 }
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include "mbfly_njs.h"
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 using namespace v8;
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
568
d796e6b8b97e Real initialize a paint_color_t object for paint_color JS obj
Thinker K.F. Li <thinker@branda.to>
parents: 567
diff changeset
11 #ifndef ASSERT
d796e6b8b97e Real initialize a paint_color_t object for paint_color JS obj
Thinker K.F. Li <thinker@branda.to>
parents: 567
diff changeset
12 #define ASSERT(x)
d796e6b8b97e Real initialize a paint_color_t object for paint_color JS obj
Thinker K.F. Li <thinker@branda.to>
parents: 567
diff changeset
13 #endif
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
15 /*! \defgroup xnjsmb_paints JS binding for paints
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
16 * \ingroup xnjsmb
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
17 *
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
18 * @{
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
19 */
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
21 static void
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
22 xnjsmb_paint_fill(paint_t *paint, Handle<Object> self, shape_t *sh) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
23 Handle<Value> rt_v;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
24 Handle<Object> rt_o;
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
25 redraw_man_t *rdman;
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
26
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
27 rt_v = GET(self, "mbrt");
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
28 rt_o = rt_v->ToObject();
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
29 rdman = xnjsmb_rt_rdman(rt_o);
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
30
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
31 rdman_paint_fill(rdman, paint, sh);
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
32
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
33 if(sh_get_coord(sh))
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
34 rdman_shape_changed(rdman, sh);
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
35 }
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
36
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
37 static void
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
38 xnjsmb_paint_stroke(paint_t *paint, Handle<Object> self, shape_t *sh) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
39 Handle<Value> rt_v;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
40 Handle<Object> rt_o;
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
41 redraw_man_t *rdman;
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
42
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
43 rt_v = GET(self, "mbrt");
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
44 rt_o = rt_v->ToObject();
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
45 rdman = xnjsmb_rt_rdman(rt_o);
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
46
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
47 rdman_paint_stroke(rdman, paint, sh);
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
48
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
49 if(sh_get_coord(sh))
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
50 rdman_shape_changed(rdman, sh);
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
51 }
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
52
699
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
53 static void
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
54 xnjsmb_paint_color_set_color(paint_t *paint, Handle<Object> self,
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
55 float r, float g, float b, float a) {
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
56 Handle<Value> rt_v;
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
57 Handle<Object> rt_o;
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
58 redraw_man_t *rdman;
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
59
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
60 rt_v = GET(self, "mbrt");
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
61 rt_o = rt_v->ToObject();
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
62 rdman = xnjsmb_rt_rdman(rt_o);
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
63
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
64 paint_color_set(paint, r, g, b, a);
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
65
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
66 rdman_paint_changed(rdman, paint);
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
67 }
0b98bdc53215 Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
68
733
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
69 /*! \brief Set stops for linear paint for Javascript code.
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
70 */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
71 static void
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
72 xnjsmb_paint_linear_set_stops(paint_t *paint, Handle<Value> stops) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
73 Array *stops_o;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
74 Array *stop_o;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
75 int nstops;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
76 grad_stop_t *grad_stops, *old_grad_stops;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
77 int i;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
78
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
79 stops_o = Array::Cast(*stops);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
80 nstops = stops_o->Length();
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
81 grad_stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * nstops);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
82 ASSERT(grad_stops != NULL);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
83
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
84 for(i = 0; i < nstops; i++) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
85 stop_o = Array::Cast(*stops_o->Get(i));
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
86 ASSERT(stop_o->Length() == 5);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
87 grad_stop_init(grad_stops + i,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
88 stop_o->Get(0)->ToNumber()->Value(), /* off */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
89 stop_o->Get(1)->ToNumber()->Value(), /* r */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
90 stop_o->Get(2)->ToNumber()->Value(), /* g */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
91 stop_o->Get(3)->ToNumber()->Value(), /* b */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
92 stop_o->Get(4)->ToNumber()->Value()); /* a */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
93 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
94
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
95 old_grad_stops = paint_linear_stops(paint, nstops, grad_stops);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
96 if(old_grad_stops)
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
97 free(old_grad_stops); /* The stops, here, were allocated for
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
98 * previous calling of this
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
99 * function. */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
100 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
101
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
102 /*! \brief Set stops for radial paint for Javascript code.
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
103 */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
104 static void
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
105 xnjsmb_paint_radial_set_stops(paint_t *paint, Handle<Value> stops) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
106 Array *stops_o;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
107 Array *stop_o;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
108 int nstops;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
109 grad_stop_t *grad_stops, *old_grad_stops;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
110 int i;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
111
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
112 stops_o = Array::Cast(*stops);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
113 nstops = stops_o->Length();
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
114 grad_stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * nstops);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
115 ASSERT(grad_stops != NULL);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
116
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
117 for(i = 0; i < nstops; i++) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
118 stop_o = Array::Cast(*stops_o->Get(i));
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
119 ASSERT(stop_o->Length() == 5);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
120 grad_stop_init(grad_stops + i,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
121 stop_o->Get(0)->ToNumber()->Value(), /* off */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
122 stop_o->Get(1)->ToNumber()->Value(), /* r */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
123 stop_o->Get(2)->ToNumber()->Value(), /* g */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
124 stop_o->Get(3)->ToNumber()->Value(), /* b */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
125 stop_o->Get(4)->ToNumber()->Value()); /* a */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
126 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
127
735
d0ee92a96c47 Fix typo and add initialize code for linear and radial
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
128 old_grad_stops = paint_radial_stops(paint, nstops, grad_stops);
733
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
129 if(old_grad_stops)
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
130 free(old_grad_stops); /* The stops, here, were allocated for
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
131 * previous calling of this
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
132 * function. */
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
133 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
134
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
135 #include "paints-inc.h"
568
d796e6b8b97e Real initialize a paint_color_t object for paint_color JS obj
Thinker K.F. Li <thinker@branda.to>
parents: 567
diff changeset
136
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
137 /*! \defgroup xnjsmb_paints_cons Constructor of paints
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
138 *
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
139 * @{
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 */
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
141 paint_t *
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
142 xnjsmb_paint_color_new(njs_runtime_t *rt,
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
143 float r, float g, float b, float a,
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
144 const char **err) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
145 paint_t *paint;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
146 redraw_man_t *rdman;
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
148 rdman = X_njs_MB_rdman(rt);
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
149 paint = rdman_paint_color_new(rdman, r, g, b, a);
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
150 if(paint == NULL) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
151 *err = "can not allocate a paint_color_t";
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
152 return NULL;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
153 }
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
155 return paint;
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
156 }
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
158 paint_t *
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
159 xnjsmb_paint_image_new(njs_runtime_t *rt, mb_img_data_t *img,
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
160 const char **err) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
161 paint_t *paint;
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
162 redraw_man_t *rdman;
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
163
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
164 rdman = X_njs_MB_rdman(rt);
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
165 paint = rdman_paint_image_new(rdman, img);
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
166 if(paint == NULL) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
167 *err = "can not allocate a paint_image_t";
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
168 return NULL;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
169 }
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
170
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
171 return paint;
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
172 }
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
173
733
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
174 paint_t *
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
175 xnjsmb_paint_linear_new(njs_runtime_t *rt,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
176 float x1, float y1, float x2, float y2,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
177 const char **err) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
178 paint_t *paint;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
179 redraw_man_t *rdman;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
180
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
181 rdman = X_njs_MB_rdman(rt);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
182 paint = rdman_paint_linear_new(rdman, x1, y1, x2, y2);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
183 if(paint == NULL) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
184 *err = "can not allocate a paint_linear_t";
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
185 return NULL;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
186 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
187
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
188 return paint;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
189 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
190
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
191 paint_t *
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
192 xnjsmb_paint_radial_new(njs_runtime_t *rt,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
193 float cx, float cy, float r,
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
194 const char **err) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
195 paint_t *paint;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
196 redraw_man_t *rdman;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
197
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
198 rdman = X_njs_MB_rdman(rt);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
199 paint = rdman_paint_radial_new(rdman, cx, cy, r);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
200 if(paint == NULL) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
201 *err = "can not allocate a paint_radial_t";
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
202 return NULL;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
203 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
204
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
205 return paint;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
206 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
207
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
208 /* @} */
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
209
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
210 /*! \defgroup xnjsmb_paints_export Exported wrapper maker for paints
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
211 *
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
212 * These functions are used by MB runtime to wrap C paints to JS
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
213 * objects.
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
214 *
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
215 * @{
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
216 */
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
217 Handle<Value>
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
218 export_xnjsmb_auto_paint_color_new(paint_t *paint) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
219 Handle<Value> ret;
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
220
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
221 ret = xnjsmb_auto_paint_color_new(paint);
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
222
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
223 return ret;
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
224 }
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
225
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
226 Handle<Value>
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
227 export_xnjsmb_auto_paint_image_new(paint_t *paint) {
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
228 Handle<Value> ret;
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
229
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
230 ret = xnjsmb_auto_paint_image_new(paint);
636
cc39cf3f623c paint_image_t for nodejs.
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
231
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
232 return ret;
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
233 }
733
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
234
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
235 Handle<Value>
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
236 export_xnjsmb_auto_paint_linear_new(paint_t *paint) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
237 Handle<Value> ret;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
238
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
239 ret = xnjsmb_auto_paint_linear_new(paint);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
240
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
241 return ret;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
242 }
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
243
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
244 Handle<Value>
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
245 export_xnjsmb_auto_paint_radial_new(paint_t *paint) {
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
246 Handle<Value> ret;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
247
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
248 ret = xnjsmb_auto_paint_radial_new(paint);
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
249
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
250 return ret;
163f0d9e6382 Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
251 }
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
252 /* @} */
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
253
637
714cd6470bd9 Doc on xnjsmb_paints_init_mb_rt_temp()
Thinker K.F. Li <thinker@branda.to>
parents: 636
diff changeset
254 /*! \brief Initialize paints for mbfly.
714cd6470bd9 Doc on xnjsmb_paints_init_mb_rt_temp()
Thinker K.F. Li <thinker@branda.to>
parents: 636
diff changeset
255 *
714cd6470bd9 Doc on xnjsmb_paints_init_mb_rt_temp()
Thinker K.F. Li <thinker@branda.to>
parents: 636
diff changeset
256 * This function is called by init() in mbfly_njs.cc when the module
714cd6470bd9 Doc on xnjsmb_paints_init_mb_rt_temp()
Thinker K.F. Li <thinker@branda.to>
parents: 636
diff changeset
257 * being loaded.
714cd6470bd9 Doc on xnjsmb_paints_init_mb_rt_temp()
Thinker K.F. Li <thinker@branda.to>
parents: 636
diff changeset
258 */
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
259 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
260 static int init_flag = 0;
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
261 Handle<ObjectTemplate> rt_proto_temp;
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
262
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
263 if(!init_flag) {
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
264 xnjsmb_auto_paint_init();
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
265 xnjsmb_auto_paint_color_init();
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
266 xnjsmb_auto_paint_image_init();
735
d0ee92a96c47 Fix typo and add initialize code for linear and radial
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
267 xnjsmb_auto_paint_linear_init();
d0ee92a96c47 Fix typo and add initialize code for linear and radial
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
268 xnjsmb_auto_paint_radial_init();
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
269
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
270 init_flag = 1;
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
271 }
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
272 }
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
273
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 637
diff changeset
274 /* @} */