SF.net SVN: openanimator:[84] 0.6

2 views
Skip to first unread message

mor...@users.sourceforge.net

unread,
Jan 2, 2011, 2:28:38 PM1/2/11
to openan...@googlegroups.com
Revision: 84
http://openanimator.svn.sourceforge.net/openanimator/?rev=84&view=rev
Author: mordox
Date: 2011-01-02 19:28:38 +0000 (Sun, 02 Jan 2011)

Log Message:
-----------
clock sample which is working in ff3 not in others :(

Modified Paths:
--------------
0.6/core-framework/compile.bat
0.6/core-framework/compile.sh
0.6/core-framework/oa-drawing.js
0.6/core-framework/oa-parser.js
0.6/core-framework/oa-pkg.js
0.6/core-framework/oa-render.js
0.6/core-framework/oa.js
0.6/core-framework/pkg-config.js

Added Paths:
-----------
0.6/core-framework/pkg-clock.js
0.6/sample/clock/
0.6/sample/clock/anim.json
0.6/sample/clock/index.html

Modified: 0.6/core-framework/compile.bat
===================================================================
--- 0.6/core-framework/compile.bat 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/compile.bat 2011-01-02 19:28:38 UTC (rev 84)
@@ -2,6 +2,6 @@
mkdir build
: Merge Order is important
:Static Load
-type jquery.js oa.js ext-jx.js oa-drawing.js oa-parser.js oa-render.js pkg-config.js oa-pkg.js > build/oa-merge.js
+type jquery.js oa.js ext-jx.js oa-drawing.js oa-parser.js oa-render.js pkg-config.js pkg-clock.js oa-pkg.js > build/oa-merge.js
:Dynamic Load
:type jquery.js oa.js oa-drawing.js oa-parser.js oa-render.js oa-pkg.js > build/oa-merge.js

Modified: 0.6/core-framework/compile.sh
===================================================================
--- 0.6/core-framework/compile.sh 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/compile.sh 2011-01-02 19:28:38 UTC (rev 84)
@@ -3,6 +3,6 @@
rm -rf build && mkdir build
# Merge Order is important
#Static Load
-cat jquery.js oa.js oa-drawing.js oa-parser.js oa-render.js pkg-config.js oa-pkg.js > build/oa-merge.js
+cat jquery.js oa.js oa-drawing.js oa-parser.js oa-render.js pkg-config.js pkg-clock.js oa-pkg.js > build/oa-merge.js
#Dynamic Load
#cat jquery.js oa.js oa-drawing.js oa-parser.js oa-render.js oa-pkg.js > build/oa-merge.js

Modified: 0.6/core-framework/oa-drawing.js
===================================================================
--- 0.6/core-framework/oa-drawing.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/oa-drawing.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -26,9 +26,10 @@
// Data objects
oa.drawing = function (refDoc) {

+ this.uuid = oa.randomid();
this._mydoc = refDoc;

- this._mystore = {};
+ this._store = {};

/* Store API */
this.lib_getstore = function() {
@@ -48,7 +49,7 @@
return false;
}
}
- this._store[id] = {_id:id, _name:id, _type:type , _isvisible : 1, _w:0, _h:0 , _r:255 , _g:255, _b:255,_a:255,_radd:0, _gadd:0, _badd:0, _aadd:0,_rmul:1, _gmul:1, _bmul:1, _amul:1 };
+ this._store[id] = {_id:id, _name:id, _type:type , _isvisible : 1, _w:0, _h:0 /*, _r:255 , _g:255, _b:255,_a:255,_radd:0, _gadd:0, _badd:0, _aadd:0,_rmul:1, _gmul:1, _bmul:1, _amul:1 */};
return true;
}catch(e) {oa.error(e); }
return false;
@@ -122,12 +123,12 @@
}catch(ex) { oa.error('oa:lib_del> Item not found!'); }
};

- this._mystore_config = {};
+ this._store_config = {frame_start:0,frame_end:0,frame_gap:100,frame_current:0,loop:0,play_state:"play"};
/* Config Getter/Setter */
this.config_get = function(key) {
oa.log('oa:config_get> ' + key);
try {
- return this._mystore_config[key];
+ return this._store_config[key];
}catch(ex) {
oa.error('Config Item not found!');
return undefined;
@@ -139,7 +140,7 @@
try {
if(val == undefined) { oa.error('invalid value'); return false; }

- this._mystore_config[key] = val;
+ this._store_config[key] = val;
return true;

}catch(e) {

Modified: 0.6/core-framework/oa-parser.js
===================================================================
--- 0.6/core-framework/oa-parser.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/oa-parser.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -37,18 +37,20 @@
try {
var jsonData = args['jsonData'];
//jsonData = eval("(" + jsonData + ")");
- jsonData = $.parseJSON(jsonData);
+ if(typeof jsonData == "string") jsonData = $.parseJSON(jsonData);
var siloAll = jsonData.openanimator.silo;
oa.log(siloAll);
oa.log("siloAll len",siloAll.length);
+ oa.log(this.MAPPING);
//process each silo
for(var i = 0; i< siloAll.length ; i++) {
oa.debug("parse " + i);
try {
+ oa.debug(siloAll[i].IDENTITY.TYPE);
if(typeof(this.MAPPING[siloAll[i].IDENTITY.TYPE]) != 'undefined') {
//eval(this.MAPPING[siloAll[i].IDENTITY.TYPE])(curDrawing,{'jsonData': siloAll[i]});
oa.pkg.run_parser(this.MAPPING[ siloAll[i].IDENTITY.TYPE ],curDrawing,{'jsonData':siloAll[i]});
- }
+ }else { oa.debug("no mapping found");}
}catch(e) { oa.error(e); }
}
}catch(e) { oa.error(e); }

Modified: 0.6/core-framework/oa-pkg.js
===================================================================
--- 0.6/core-framework/oa-pkg.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/oa-pkg.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -23,24 +23,34 @@
oa.namespace("oa.pkg");

oa.pkg = {
- queue : [ {script:"pkg-config.js",callingprefix:"oa.fn.anim_config",parserfn:"parser"} ],
+ queue : [ {script:"pkg-config.js",callingprefix:"oa.fn.anim_config",parserfn:"parser"} ,
+ {script:"pkg-clock.js",callingprefix:"oa.fn.clock",parserfn:"parser",renderfn:"render"} ],
init_self: function(oaUrlPath) {
try {
if(oaUrlPath == undefined) oaUrlPath = "../../core-framework/";
for(var i=0;i<this.queue.length;i++) {
- oa.debug("oa.pkg> " + i + " " + this.queue[i]);
- if(window[ this.queue[i].callingprefix ] == undefined) {
+ oa.debug("oa.pkg> " + i ); oa.debug(this.queue[i]);
+
+ var nm = oa.getnamespace(this.queue[i].callingprefix);
+
+ if(nm == undefined) {
try {
var element = window.document.createElement("script");
element.type = "text/javascript"; element.src=oaUrlPath + this.queue[i].script; element.id = oa.randomid();
window.document.getElementsByTagName("body")[0].appendChild(element);
}catch(e) {oa.error(e);}
}else {
- if(typeof this.queue[i].parserfn == "string") {
+ oa.debug("already loaded");
+ if(this.queue[i].parserfn && typeof this.queue[i].parserfn == "string") {
try {
- oa.parser.setMapping(window[ this.queue[i].callingprefix ].MY_TYPE , this.queue[i].callingprefix);
+ oa.parser.setMapping(nm.MY_TYPE , this.queue[i].callingprefix);
}catch(e){oa.error(e);}
}
+ if(this.queue[i].renderfn && typeof this.queue[i].renderfn == "string"){
+ try {
+ oa.render.setMapping(nm.MY_TYPE, this.queue[i].callingprefix)
+ }catch(e){oa.error(e);}
+ }
}
}
}catch(e){oa.error(e);}
@@ -48,11 +58,26 @@
run_parser: function(prefix,drawing,args) {
try {
for(var i=0;i<this.queue.length;i++) {
+ oa.debug("run_parser: "); oa.debug(this.queue[i]);
if(this.queue[i].callingprefix == prefix) {
- (window[ prefix ])[ this.queue[i].parserfn ](drawing,args); break;
+ var nm = oa.getnamespace(prefix);
+ (nm)[ this.queue[i].parserfn ](drawing,args); break;
}
}
}catch(e){oa.error(e);}
+ },
+ run_render : function(prefix,drawing,args){
+ try {
+ oa.debug("run_render: " + prefix)
+ for(var i=0;i<this.queue.length;i++) {
+ oa.debug("run_render: que "); oa.debug(this.queue[i]);
+ if(this.queue[i].callingprefix == prefix) {
+ var nm = oa.getnamespace(prefix);
+ (nm)[ this.queue[i].renderfn ](drawing,args); break;
+ }
+ }
+ }catch(e){oa.error(e);}
}
};

+oa.pkg.init_self();

Modified: 0.6/core-framework/oa-render.js
===================================================================
--- 0.6/core-framework/oa-render.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/oa-render.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -42,16 +42,79 @@

for(var k in cStore) {
try {
- if(cStore[k].isvisible == 0) continue;
+ if(parseInt(cStore[k]._isvisible) == 0) continue;

- var renderfn = this.MAPPING[ (cStore[k]._type) ];
+ //var renderfn = this.MAPPING[ (cStore[k]._type) ];
var args_c = { '_frame' : frame , '_id':cStore[k]._id };
- oa.log("renderfn",renderfn);
- //eval(renderfn)(curDrawing,args_c); TODO
+ //oa.log("renderfn",renderfn);
+ //eval(renderfn)(curDrawing,args_c);
+ oa.pkg.run_render(this.MAPPING[cStore[k]._type],curDrawing,args_c);
} catch(e) { oa.error(e); }
}
}catch(e) { oa.error(e); }

+ },
+ drawing_registry: [],/* to store all the items that oa.render.run has already scheduled in the background */
+ run: function(drawing) {
+ try {
+ var isalreadyadded = false;
+ for(var i=0;i<this.drawing_registry.length;i++){
+ if(this.drawing_registry[i].drawing.uuid == drawing.uuid) {
+ drawing.config_set('play_state','play'); isalreadyadded = true; break;
+ /* This drawing is already in the queue. Toggle the play state */
+ }
+ }
+ if(!isalreadyadded) { var id = oa.addbgtask(oa.render,"run_slave",drawing); this.drawing_registry.push({'drawing':drawing,'bgid':id}); }
+ }catch(e){oa.error(e);}
+ },
+ play : function(drawing) {
+ try {drawing.config_set('play_state','play');}catch(e){oa.error(e);}
+ },
+ stop : function(drawing) {
+ try {drawing.config_set('play_state','stop');}catch(e){oa.error(e);}
+ },
+ rewind: function(drawing) {
+ try{drawing.config_set('frame_current',0);}catch(e){oa.error(e);}
+ },
+ run_slave : function(curDrawing) {
+ try {
+
+
+ var play_state = curDrawing.config_get('play_state');
+
+ if(play_state == "stop") return; // nothing much to do
+
+ var frame_start = parseInt(curDrawing.config_get('frame_start'));
+ var frame_end = parseInt(curDrawing.config_get('frame_end'));
+ var frame_gap = parseInt(curDrawing.config_get('frame_gap'));
+ var frame_current = parseInt(curDrawing.config_get('frame_current'));
+
+ var play_loop = parseInt(curDrawing.config_get('loop'));
+
+ //exit at invalid range
+ if(!( (frame_start <= frame_current) && (frame_current <= frame_end) )) return;
+
+ //renderPhase
+ if(frame_start <= frame_current && frame_current <= frame_end) {
+ //check playstate
+ if(play_state == 'play') {
+ oa.render.render( curDrawing, { '_frame' : frame_current});
+ }
+ }
+ //updatePhase
+ if(play_state == 'play') {
+ ++frame_current;
+ if(frame_current > frame_end) {
+ if(play_loop == 1) { frame_current = frame_start; }
+ else { --frame_current; play_state = 'stop'; }
+ }
+
+ }
+ //commit changes in updatePhase
+ curDrawing.config_set('play_state', play_state);
+ curDrawing.config_set('frame_current',frame_current);
+
+ }catch(e) {oa.error(e);}
}
};

Modified: 0.6/core-framework/oa.js
===================================================================
--- 0.6/core-framework/oa.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/oa.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -24,36 +24,70 @@

oa = {
VERSION: "0.6",
- debug : function(msg) { try { console.log(msg); }catch(e){} },
+ debug : function(msg) { try { console.debug(msg); }catch(e){} },
log: function(msg){ try { console.log(msg); }catch(e){} },
error: function(msg) { try{ console.error(msg); }catch(e){}} ,
namespace: function(nm) {
+ /* Create a empty namespace if it does not exist */
try {
if(nm && typeof(nm) == "string") {
var hier = nm.split(".");
var parent = window;
- for(var i =0;i<hier.length;i++) {
+ for(var i =0,i_n=hier.length;i<i_n;i++) {
if(parent[hier[i]] == undefined) { parent[hier[i]] = {}; }
parent = parent[hier[i]];
}
}
}catch(e){ oa.error(e); }
},
+ checknamespace: function(nm) {
+ /* Check if a namespace exists*/
+ var result = false;
+ try {
+ if(nm && typeof(nm) == "string") {
+ var hier = nm.split(".");
+ var parent = window;
+ for(var i=0,i_n=hier.length;i<i_n;i++){
+ if(parent[hier[i]] == undefined) { break; }
+ parent = parent[hier[i]];
+ }
+ result = true;
+ }
+ }catch(e){oa.error(e); result = false;}
+ return result;
+ },
+ getnamespace : function(nm){
+ /* Get the namespace object */
+ var result = undefined;
+ try {
+ if(nm && typeof(nm) == "string"){
+ var hier = nm.split(".");
+ var parent = window;
+ for(var i=0,i_n=hier.length;i<i_n;i++){
+ if(parent[hier[i]] == undefined) { result = undefined;break; }
+ parent = parent[hier[i]];
+ }
+ result = parent;
+ }
+
+ }catch(e){oa.error(e);}
+ return result;
+ },
_rand : 0,
randomid: function() { return "oai_" + (++this._rand); },
/* Run background tasks */
_bg : [],
- addbgtask: function(parentObject,functionName) {
- try { this._bg.push({"scope":parentObject,"fn":functionName}); return this._bg.length; }catch(e) { oa.error(e); }
+ addbgtask: function(parentObject,functionName,arguments) {
+ try { this._bg.push({"scope":parentObject,"fn":functionName,"args":arguments}); return this._bg.length; }catch(e) { oa.error(e); }
},
removebgtask: function(id) {
- try { if(typeof id == "string") id = parseInt(id); this._bg[id] = {}; }catch(e) { oa.error(e); }
+ try { if(typeof id == "string" && id>0) id = parseInt(id); this._bg[id-1] = {}; }catch(e) { oa.error(e); }
},
_bg_runner : function() {
try {
for(var i=0;i<this._bg.length;i++) {
if(this._bg[i].scope)
- try { (this._bg[i].scope)[this._bg[i].fn](); }catch(e) { oa.error(e); }
+ try { (this._bg[i].scope)[this._bg[i].fn](this._bg[i].args); }catch(e) { oa.error(e); }
}
setTimeout("oa._bg_runner()",1000);
}catch(e) { oa.error(e); }

Added: 0.6/core-framework/pkg-clock.js
===================================================================
--- 0.6/core-framework/pkg-clock.js (rev 0)
+++ 0.6/core-framework/pkg-clock.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -0,0 +1,115 @@
+/*
+ * pkg-clock.js
+ * This file is part of OpenAnimator
+ *
+ * Copyright (C) 2010 - OpenAnimator Team
+ *
+ * OpenAnimator is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenAnimator is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with OpenAnimator; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+oa.namespace('oa.fn.clock');
+
+oa.fn.clock = {
+ MY_TYPE: 'anim/clock/1.0',
+ parser: function(curDrawing,args) {
+ try {
+ var jsonData = args['jsonData'];
+ oa.log(jsonData);
+ var id = jsonData.IDENTITY['NAME'];
+ //check for existing item with same name
+ var iscreated = curDrawing.lib_new( id , this.MY_TYPE );
+ if( iscreated == false ) throw 'Unable to create Item ' + id ;
+ //ELSE create new item
+ if(!curDrawing.lib_set(id,'_x', jsonData.x)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'_y', jsonData.y)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'handsize', jsonData.handsize)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'color_second', jsonData.color_second)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'color_minute', jsonData.color_minute)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'color_hour', jsonData.color_hour)) throw 'Unable to set';
+ if(!curDrawing.lib_set(id,'_isvisible', jsonData.isvisible)) throw 'Unable to set';
+ }catch(e) { oa.error(e); }
+ },
+ _rand: 0,
+ CK_second : 0.8,
+ CK_min : 0.7,
+ CK_hour : 0.5,
+ DEG2RAD : (Math.PI / 180),
+ render: function(curDrawing, args) {
+ oa.debug('render clock');
+ var id = args['_id'];
+ var x = curDrawing.lib_get(id,'_x');
+ var y = curDrawing.lib_get(id,'_y');
+ var handsize = curDrawing.lib_get(id,'handsize');
+ var color_second = curDrawing.lib_get(id,'color_second');
+ var color_min = curDrawing.lib_get(id,'color_minute');
+ var color_hr = curDrawing.lib_get(id,'color_hour');
+ var init = curDrawing.lib_get(id,'init');
+ oa.debug(init);
+ if(init == undefined || init == 0){
+ var doc = curDrawing._mydoc;
+ curDrawing.lib_set(id,'dom_ckid_range',this._create_clock(doc,x,y,handsize));
+ curDrawing.lib_set(id,'dom_hndsec_range',this._create_hand(doc,this.CK_second * handsize,color_second));
+ curDrawing.lib_set(id,'init',1);
+ }
+ var idr_hand_second = curDrawing.lib_get(id,'dom_hndsec_range');
+ var dt = new Date();
+ var rad_sec = 6 * dt.getSeconds() * this.DEG2RAD;
+ var rad_min = 6 * dt.getMinutes() * this.DEG2RAD;
+ var rad_hour = 30 * dt.getHours() * this.DEG2RAD;
+ this._set_hand_rot(doc,rad_sec,x,y,idr_hand_second);
+
+ },
+ HND_ID : 'id_oa_fn_clock_hand_',
+ HND_SPACING : 5,
+ _create_hand : function(doc,hlen,color) {
+ var id_start=this._rand+1,clen = 0,spacing = this.HND_SPACING;
+ for(;clen<hlen;clen+=spacing) {
+ var ndiv = doc.createElement("div");
+ ndiv.setAttribute('id',this.HND_ID + (++this._rand));
+ $(ndiv).css({'position':'absolute','width':'1px','height':'1px','background-color': 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')'});
+ doc.getElementsByTagName('body')[0].appendChild(ndiv);
+ }
+ var id_end = this._rand;
+ return [ id_start, id_end ];
+ },
+ _set_hand_rot : function(doc,rad, x,y, id_range) {
+ var h=0,spacing = this.HND_SPACING;
+ var m_cos = Math.cos(rad), m_sin = Math.sin(rad);
+ for(var i=id_range[0],i_n=id_range[1];i<i_n;i++,h+=spacing){
+ $('#' + this.HND_ID + i).css({'top': y- Math.round(h * m_cos),'left':x + Math.round(h * m_sin)});
+ }
+ },
+ CK_ID : 'id_oa_fn_clock_',
+ _create_clock : function(doc,x,y,h) {
+ var id_start = this._rand+1;
+ var deg = 0,rad;
+ for(var i=1;i<=12;i++){
+ deg+=30; rad = deg * this.DEG2RAD ;
+ var ndiv = doc.createElement('div');
+ ndiv.setAttribute('id', this.CK_ID + (++this._rand));
+ ndiv.innerHTML = i;
+
+ $(ndiv).css({'position':'absolute', 'top': y - Math.round(h * Math.cos(rad)) ,'left': x + Math.round(h * Math.sin(rad)) });
+ doc.getElementsByTagName('body')[0].appendChild(ndiv);
+
+ }
+ var id_end = this._rand;
+ return [ id_start, id_end ];
+ }
+
+
+
+};

Modified: 0.6/core-framework/pkg-config.js
===================================================================
--- 0.6/core-framework/pkg-config.js 2010-12-25 04:49:17 UTC (rev 83)
+++ 0.6/core-framework/pkg-config.js 2011-01-02 19:28:38 UTC (rev 84)
@@ -28,15 +28,10 @@
try {
var jsonData = args['jsonData'];
oa.log(jsonData);
- curDrawing.config_set('window_width',jsonData['window-width']);
- curDrawing.config_set('window_height',jsonData['window-height']);
curDrawing.config_set('frame_gap',jsonData['frame-gap']);
curDrawing.config_set('loop', jsonData['loop']);
curDrawing.config_set('frame_start', jsonData['frame-start']);
curDrawing.config_set('frame_end', jsonData['frame-end']);
- curDrawing.config_set('r',jsonData['bg_r']);
- curDrawing.config_set('g', jsonData['bg_g']);
- curDrawing.config_set('b',jsonData['bg_b']);

}catch(e) { oa.error(e); }
},

Added: 0.6/sample/clock/anim.json
===================================================================
--- 0.6/sample/clock/anim.json (rev 0)
+++ 0.6/sample/clock/anim.json 2011-01-02 19:28:38 UTC (rev 84)
@@ -0,0 +1,19 @@
+{
+ "openanimator" : {
+ "silo" : [
+ {
+ "IDENTITY": { "TYPE" : "anim/config/1.0" },
+ "frame-gap" : 100,
+ "loop": 1,
+ "frame-start": 0,
+ "frame-end": 10,
+
+ },
+ {
+ "IDENTITY" : { "TYPE" : "anim/clock/1.0" ,"NAME": "clock"},
+ "isvisible" : 1,
+ "x": 150, "y" : 150, "handsize": 80, "color_second" : [255,0,0], "color_minute":[0,255,0],"color_hour":[0,0,255]
+ }
+ ]
+ }
+}

Added: 0.6/sample/clock/index.html
===================================================================
--- 0.6/sample/clock/index.html (rev 0)
+++ 0.6/sample/clock/index.html 2011-01-02 19:28:38 UTC (rev 84)
@@ -0,0 +1,18 @@
+<html>
+
+<body>
+Empty animation
+
+<script type="text/javascript" src="../../core-framework/build/oa-merge.js"></script>
+<script type="text/javascript">
+try {
+//load animation
+$.get("anim.json", function(data) {
+ var drawing = new oa.drawing(window.document); window['drawing'] = drawing;
+ oa.parser.parse(drawing, {'jsonData':data});
+ oa.render.run(drawing);
+} );
+}catch(e){oa.error(e);}
+</script>
+</body>
+</html>


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

Reply all
Reply to author
Forward
0 new messages