aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
diff options
context:
space:
mode:
authorhwc4872012-03-02 09:36:31 -0800
committerhwc4872012-03-02 09:36:31 -0800
commitd044b6d9755d8ca686501fc3dd5644180e2ffbf0 (patch)
tree0ff6ca04987639417c0188ca8af2580b62d65f9f /js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
parentcf32843b1d64c631e6e7c808cc4f13ac316e1baf (diff)
downloadninja-d044b6d9755d8ca686501fc3dd5644180e2ffbf0.tar.gz
WebGL File IO
Diffstat (limited to 'js/helper-classes/RDGE/runtime/RuntimeGeomObj.js')
-rw-r--r--js/helper-classes/RDGE/runtime/RuntimeGeomObj.js274
1 files changed, 274 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
new file mode 100644
index 00000000..da941b56
--- /dev/null
+++ b/js/helper-classes/RDGE/runtime/RuntimeGeomObj.js
@@ -0,0 +1,274 @@
1
2/* <copyright>
3This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
4No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
5(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
6</copyright> */
7
8///////////////////////////////////////////////////////////////////////
9// Class RuntimeGeomObj
10// Super class for all geometry classes
11///////////////////////////////////////////////////////////////////////
12function RuntimeGeomObj()
13{
14 ///////////////////////////////////////////////////////////////////////
15 // Constants
16 ///////////////////////////////////////////////////////////////////////
17 this.GEOM_TYPE_RECTANGLE = 1;
18 this.GEOM_TYPE_CIRCLE = 2;
19 this.GEOM_TYPE_LINE = 3;
20 this.GEOM_TYPE_PATH = 4;
21 this.GEOM_TYPE_CUBIC_BEZIER = 5;
22 this.GEOM_TYPE_UNDEFINED = -1;
23
24 ///////////////////////////////////////////////////////////////////////
25 // Instance variables
26 ///////////////////////////////////////////////////////////////////////
27 this._children;
28
29 // stroke and fill colors
30 this._strokeColor = [0,0,0,0];
31 this._fillColor = [0,0,0,0];
32
33 // array of materials
34 this._materials = [];
35
36 ///////////////////////////////////////////////////////////////////////
37 // Property accessors
38 ///////////////////////////////////////////////////////////////////////
39
40 this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; }
41
42 ///////////////////////////////////////////////////////////////////////
43 // Methods
44 ///////////////////////////////////////////////////////////////////////
45 this.makeStrokeMaterial = function()
46 {
47 }
48
49 this.makeFillMaterial = function()
50 {
51 }
52
53
54 this.render = function()
55 {
56 }
57
58 this.addChild = function( child )
59 {
60 if (!this._children) this._children = [];
61 this._children.push( child );
62 }
63
64 this.import = function()
65 {
66 }
67
68 this.importMaterials = function(importStr)
69 {
70 var nMaterials = Number( getPropertyFromString( "nMaterials: ", importStr ) );
71 for (var i=0; i<nMaterials; i++)
72 {
73 var matNodeName = getPropertyFromString( "materialNodeName: ", importStr );
74
75 var mat;
76 var materialType = getPropertyFromString( "material: ", importStr );
77 switch (materialType)
78 {
79 case "flat": mat = new RuntimeFlatMaterial(); break;
80 case "pulse": mat = new RuntimePulseMaterial(); break;
81
82 default:
83 console.log( "material type: " + materialType + " is not supported" );
84 break;
85 }
86
87 if (mat)
88 {
89 mat.import( importStr );
90 mat._materialNodeName = matNodeName;
91 this._materials.push( mat );
92 }
93
94 var endIndex = importStr.indexOf( "endMaterial\n" );
95 if (endIndex < 0) break;
96 importStr = importStr.substr( endIndex );
97 }
98 }
99}
100
101function getPropertyFromString( prop, str )
102{
103 var index = str.indexOf( prop );
104 if (index < 0) throw new Error( "property " + prop + " not found in string: " + str);
105
106 var rtnStr = str.substr( index+prop.length );
107 index = rtnStr.indexOf( "\n" );
108 if (index >= 0)
109 rtnStr = rtnStr.substr(0, index);
110
111 return rtnStr;
112}
113
114///////////////////////////////////////////////////////////////////////
115// Class RuntimeRectangle
116///////////////////////////////////////////////////////////////////////
117function RuntimeRectangle()
118{
119 // inherit the members of RuntimeGeomObj
120 this.inheritedFrom = RuntimeGeomObj;
121 this.inheritedFrom();
122
123 this.import = function( importStr )
124 {
125 this._xOffset = Number( getPropertyFromString( "xoff: ", importStr ) );
126 this._yOffset = Number( getPropertyFromString( "yoff: ", importStr ) );
127 this._width = Number( getPropertyFromString( "width: ", importStr ) );
128 this._height = Number( getPropertyFromString( "height: ", importStr ) );
129 this._strokeWidth = Number( getPropertyFromString( "strokeWidth: ", importStr ) );
130 this._innerRadius = Number( getPropertyFromString( "innerRadius: ", importStr ) );
131 this._strokeStyle = Number( getPropertyFromString( "strokeStyle: ", importStr ) );
132 var strokeMaterialName = getPropertyFromString( "strokeMat: ", importStr );
133 var fillMaterialName = getPropertyFromString( "fillMat: ", importStr );
134 this._strokeStyle = getPropertyFromString( "strokeStyle: ", importStr );
135 this._fillColor = eval( "[" + getPropertyFromString( "fillColor: ", importStr ) + "]" );
136 this._strokeColor = eval( "[" + getPropertyFromString( "strokeColor: ", importStr ) + "]" );
137 this._tlRadius = Number( getPropertyFromString( "tlRadius: ", importStr ) );
138 this._trRadius = Number( getPropertyFromString( "trRadius: ", importStr ) );
139 this._blRadius = Number( getPropertyFromString( "blRadius: ", importStr ) );
140 this._brRadius = Number( getPropertyFromString( "brRadius: ", importStr ) );
141
142 this.importMaterials( importStr );
143 }
144
145 this.renderPath = function( inset, ctx )
146 {
147 // various declarations
148 var pt, rad, ctr, startPt, bPts;
149 var width = Math.round(this.getWidth()),
150 height = Math.round(this.getHeight());
151
152 pt = [inset, inset]; // top left corner
153
154 var tlRad = this._tlRadius; //top-left radius
155 var trRad = this._trRadius;
156 var blRad = this._blRadius;
157 var brRad = this._brRadius;
158
159 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0))
160 {
161 ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset);
162 }
163 else
164 {
165 // get the top left point
166 rad = tlRad - inset;
167 if (rad < 0) rad = 0;
168 pt[1] += rad;
169 if (MathUtils.fpSign(rad) == 0) pt[1] = inset;
170 ctx.moveTo( pt[0], pt[1] );
171
172 // get the bottom left point
173 pt = [inset, height - inset];
174 rad = blRad - inset;
175 if (rad < 0) rad = 0;
176 pt[1] -= rad;
177 ctx.lineTo( pt[0], pt[1] );
178
179 // get the bottom left curve
180 if (MathUtils.fpSign(rad) > 0)
181 ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset );
182
183 // do the bottom of the rectangle
184 pt = [width - inset, height - inset];
185 rad = brRad - inset;
186 if (rad < 0) rad = 0;
187 pt[0] -= rad;
188 ctx.lineTo( pt[0], pt[1] );
189
190 // get the bottom right arc
191 if (MathUtils.fpSign(rad) > 0)
192 ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad );
193
194 // get the right of the rectangle
195 pt = [width - inset, inset];
196 rad = trRad - inset;
197 if (rad < 0) rad = 0;
198 pt[1] += rad;
199 ctx.lineTo( pt[0], pt[1] );
200
201 // do the top right corner
202 if (MathUtils.fpSign(rad) > 0)
203 ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset );
204
205 // do the top of the rectangle
206 pt = [inset, inset]
207 rad = tlRad - inset;
208 if (rad < 0) rad = 0;
209 pt[0] += rad;