comparison nodejs/component.js @ 1408:c918b79892ab

Add component class which is sued to access the objects in different frame for the same screen object. We will treat the object as the same if the duplicated-src are the same or it is the grpup defined by duplicated-src.
author wycc
date Wed, 06 Apr 2011 07:51:06 +0800
parents
children d19f47691d5e
comparison
equal deleted inserted replaced
1407:f19121bd6a6c 1408:c918b79892ab
1 var mbfly = require("mbfly");
2 var svg = require("./svg");
3 var sys=require("sys");
4 /*
5 The Component and ComponentManager is used to keep track of the symbol
6 table in different frame.
7
8
9 */
10 function mul(a,b)
11 {
12 var m = [a[0]*b[0]+a[1]*b[3], a[0]*b[1]+a[1]*b[4], a[0]*b[2]+a[1]*b[5]+a[2],
13 a[3]*b[0]+a[4]*b[3], a[3]*b[1]+a[4]*b[4], a[3]*b[2]+a[4]*b[5]+a[5]];
14 a[0] = m[0];
15 a[1] = m[1];
16 a[2] = m[2];
17 a[3] = m[3];
18 a[4] = m[4];
19 a[5] = m[5];
20 }
21
22 function Component(app, name) {
23 this.app = app;
24 this.name = name;
25 this.coord = null;
26 }
27
28 Component.prototype.translate=function(tx,ty) {
29 if (this.coord) {
30 mul(this.coord, [1,0,tx,0,1,ty]);
31 }
32 }
33
34 Component.prototype.resize=function(sx,sy) {
35
36 if (this.coord) {
37 mul(this.coord, [sx,0,0,0,sy,0]);
38 }
39 }
40
41 Component.prototype.set=function(m) {
42
43 if (this.coord) {
44 this.coord[0] = m[0];
45 this.coord[1] = m[1];
46 this.coord[2] = m[2];
47 this.coord[3] = m[3];
48 this.coord[4] = m[4];
49 this.coord[5] = m[5];
50 }
51 }
52 Component.prototype.hide=function(m) {
53 if (this.coord) {
54 this.coord.hide();
55 }
56 }
57
58 Component.prototype.show=function(m) {
59 if (this.coord) {
60 this.coord.show();
61 }
62 }
63
64 Component.prototype.search=function() {
65 this.coord = this.app._componentmanager.search(this.name);
66 }
67
68 Component.prototype.realize=function() {
69 if (this.coord == null) {
70 this.search();
71 }
72 return this.coord;
73 }
74
75 Component.prototype.toCoord=function() {
76 return this.coord;
77 }
78
79
80 function ComponentManager(app)
81 {
82 this.app = app;
83 this.object_table = {};
84 }
85
86 /* \brief add an object into the current current component table.
87 * This first argument is the source node of the screen object.
88 * The second argument is the coord object which is displayed at
89 * the screen now.
90 *
91 * We need to use the soucer node to get the name of the object.
92 */
93 ComponentManager.prototype.add=function(source,obj) {
94 if (source.refid==undefined) {
95 sys.puts("Internal Error: no refid is defined\n");
96 return;
97 }
98 this.object_table[source.refid] = obj;
99 }
100
101
102 ComponentManager.prototype.del=function(name) {
103 delete this.object_table[name];
104 }
105
106 ComponentManager.prototype.dump=function(name) {
107 for(i in this.object_table) {
108 sys.puts(i);
109 }
110 }
111
112 ComponentManager.prototype.search=function(name) {
113 return this.object_table[name];
114 }
115
116
117 exports.Component = Component;
118 exports.ComponentManager = ComponentManager;