Mercurial > MadButterfly
comparison nodejs/mbapp.js @ 854:eff2f580b536 abs_n_rel_center
Use accessor to return bbox values
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 20 Sep 2010 22:43:43 +0800 |
parents | 13e0953c3fb3 |
children | 881efcd8a18f |
comparison
equal
deleted
inserted
replaced
853:13e0953c3fb3 | 854:eff2f580b536 |
---|---|
3 var mbfly = require("mbfly"); | 3 var mbfly = require("mbfly"); |
4 var svg = require("./svg"); | 4 var svg = require("./svg"); |
5 var sys = require("sys"); | 5 var sys = require("sys"); |
6 var ldr = mbfly.img_ldr_new("."); | 6 var ldr = mbfly.img_ldr_new("."); |
7 | 7 |
8 function _reverse(m1) { | |
9 var rev = new Array(1, 0, 0, 0, 1, 0); | |
10 var m = new Array(m1[0], m1[1], m1[2], m1[3], m1[4], m1[5]); | |
11 | |
12 rev[3] = -m[3] / m[0]; | |
13 m[3] = 0; | |
14 m[4] += rev[3] * m[1]; | |
15 m[5] += rev[3] * m[2]; | |
16 | |
17 rev[1] = -m[1] / m[4]; | |
18 rev[0] += rev[1] * rev[3]; | |
19 m[1] = 0; | |
20 m[2] += rev[1] * m[5]; | |
21 | |
22 rev[2] = -m[2]; | |
23 rev[5] = -m[5]; | |
24 | |
25 rev[0] = rev[0] / m[0]; | |
26 rev[1] = rev[1] / m[0]; | |
27 rev[2] = rev[2] / m[0]; | |
28 | |
29 rev[3] = rev[3] / m[4]; | |
30 rev[4] = rev[4] / m[4]; | |
31 rev[5] = rev[5] / m[4]; | |
32 | |
33 return rev; | |
34 } | |
35 | |
8 function _decorate_mb_rt(mb_rt) { | 36 function _decorate_mb_rt(mb_rt) { |
37 var coord; | |
38 | |
9 mb_rt._mbapp_saved_coord_new = mb_rt.coord_new; | 39 mb_rt._mbapp_saved_coord_new = mb_rt.coord_new; |
10 mb_rt.coord_new = function(parent) { | 40 mb_rt.coord_new = function(parent) { |
11 var coord; | 41 var coord; |
12 | 42 |
13 coord = this._mbapp_saved_coord_new(parent); | 43 coord = this._mbapp_saved_coord_new(parent); |
44 coord.type = "coord"; | |
14 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], | 45 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], |
15 coord[3], coord[4], coord[5]]; | 46 coord[3], coord[4], coord[5]]; |
47 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); | |
48 coord.parent = parent; | |
49 coord._mbapp_saved_add_shape = coord.add_shape; | |
50 coord.add_shape = function(shape) { | |
51 var coord; | |
52 | |
53 this._mbapp_saved_add_shape(shape); | |
54 shape.parent = this; | |
55 } | |
56 | |
16 return coord; | 57 return coord; |
17 }; | 58 }; |
59 | |
60 /* | |
61 * Decorate root coord | |
62 */ | |
63 coord = mb_rt.root; | |
64 coord.type = "coord"; | |
65 coord._mbapp_saved_mtx = [coord[0], coord[1], coord[2], | |
66 coord[3], coord[4], coord[5]]; | |
67 coord._mbapp_saved_rev_mtx = _reverse(coord._mbapp_saved_mtx); | |
68 coord._mbapp_saved_add_shape = coord.add_shape; | |
69 coord.add_shape = function(shape) { | |
70 var coord; | |
71 | |
72 this._mbapp_saved_add_shape(shape); | |
73 shape.parent = this; | |
74 } | |
18 } | 75 } |
19 | 76 |
20 app=function(display, w, h) { | 77 app=function(display, w, h) { |
21 var self = this; | 78 var self = this; |
22 var mb_rt; | 79 var mb_rt; |