# HG changeset patch # User wycc # Date 1302096921 -28800 # Node ID 6fa411fd9549836f8bbf4196701b044eaa137811 # Parent 5dd46a4f6257d34dffb44b5ab00bccc0acfded8c# Parent ce981aa3fbf29ea4605aeabcdc00cc92d307df51 Commit merged result diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/component.js Wed Apr 06 21:35:21 2011 +0800 @@ -0,0 +1,118 @@ +var mbfly = require("mbfly"); +var svg = require("./svg"); +var sys=require("sys"); +/* +The Component and ComponentManager is used to keep track of the symbol +table in different frame. + + +*/ +function mul(a,b) +{ + 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], + 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]]; + a[0] = m[0]; + a[1] = m[1]; + a[2] = m[2]; + a[3] = m[3]; + a[4] = m[4]; + a[5] = m[5]; +} + +function Component(app, name) { + this.app = app; + this.name = name; + this.coord = null; +} + +Component.prototype.translate=function(tx,ty) { + if (this.coord) { + mul(this.coord, [1,0,tx,0,1,ty]); + } +} + +Component.prototype.resize=function(sx,sy) { + + if (this.coord) { + mul(this.coord, [sx,0,0,0,sy,0]); + } +} + +Component.prototype.set=function(m) { + + if (this.coord) { + this.coord[0] = m[0]; + this.coord[1] = m[1]; + this.coord[2] = m[2]; + this.coord[3] = m[3]; + this.coord[4] = m[4]; + this.coord[5] = m[5]; + } +} +Component.prototype.hide=function(m) { + if (this.coord) { + this.coord.hide(); + } +} + +Component.prototype.show=function(m) { + if (this.coord) { + this.coord.show(); + } +} + +Component.prototype.search=function() { + this.coord = this.app._componentmanager.search(this.name); +} + +Component.prototype.realize=function() { + if (this.coord == null) { + this.search(); + } + return this.coord; +} + +Component.prototype.toCoord=function() { + return this.coord; +} + + +function ComponentManager(app) +{ + this.app = app; + this.object_table = {}; +} + +/* \brief add an object into the current current component table. + * This first argument is the source node of the screen object. + * The second argument is the coord object which is displayed at + * the screen now. + * + * We need to use the soucer node to get the name of the object. + */ +ComponentManager.prototype.add=function(source,obj) { + if (source.refid==undefined) { + sys.puts("Internal Error: no refid is defined\n"); + return; + } + this.object_table[source.refid] = obj; +} + + +ComponentManager.prototype.del=function(name) { + delete this.object_table[name]; +} + +ComponentManager.prototype.dump=function(name) { + for(i in this.object_table) { + sys.puts(i); + } +} + +ComponentManager.prototype.search=function(name) { + return this.object_table[name]; +} + + +exports.Component = Component; +exports.ComponentManager = ComponentManager; diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/coord.cc --- a/nodejs/coord.cc Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/coord.cc Wed Apr 06 21:35:21 2011 +0800 @@ -81,6 +81,7 @@ FOR_COORDS_PREORDER(coord, child) { child_hdl = (Persistent *)mb_prop_get(&child->obj.props, PROP_JSOBJ); + if (child_hdl == NULL) continue; SET(*child_hdl, "valid", _false); WRAP(*child_hdl, NULL); child_hdl->Dispose(); @@ -90,6 +91,7 @@ FOR_COORD_SHAPES(child, mem) { mem_hdl = (Persistent *)mb_prop_get(&mem->obj.props, PROP_JSOBJ); + if (mem_hdl == NULL) continue; SET(*mem_hdl, "valid", _false); WRAP(*mem_hdl, NULL); mem_hdl->Dispose(); diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/examples/mce/epg.js --- a/nodejs/examples/mce/epg.js Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/examples/mce/epg.js Wed Apr 06 21:35:21 2011 +0800 @@ -101,7 +101,9 @@ sys.puts("fetch "+ file); var u = URL.parse(url); var cachepath = 'cache/'+u.pathname; - if (isCached(cachepath,file,obj)) return; + if (isCached(cachepath,file,obj)) { + return; + } CreateDirectory(cachepath); // Fetch file from the server and convert it tyo PNG if it is not PNG format. @@ -145,6 +147,7 @@ obj.pend = obj.pend - 1; if (obj.pend == 0) { obj.onInitDone(); + sys.puts("done"); } }); @@ -159,7 +162,10 @@ for (i in cats) { c = cats[i]; httpGetFile(c['ProgramPIC'],'cat'+i+'.jpg',this); + sys.puts("this.pend="+this.pend); } + if (this.pend == 0) + this.onInitDone(); } EPG.prototype.getList=function(item,func) { diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/examples/mce/main.svg --- a/nodejs/examples/mce/main.svg Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/examples/mce/main.svg Wed Apr 06 21:35:21 2011 +0800 @@ -1,995 +1,157 @@ - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/examples/mce/mainmenu.js --- a/nodejs/examples/mce/mainmenu.js Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/examples/mce/mainmenu.js Wed Apr 06 21:35:21 2011 +0800 @@ -21,8 +21,8 @@ } MainMenu.prototype.init=function() { - app.loadSVG("main.svg"); - app.changeScene(1); + app.loadSVG("main1.svg"); + app.changeScene(0); var i; var self = this; @@ -40,124 +40,63 @@ } this.line=0; this.item = 0; - - animate.run([new animate.scale(app,this.items[this.item], 1, 1.5)], 0, 0.1); - app.refresh(); - - app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); - app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); - app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); - app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); - app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); -} + this.itemToScene=[0,15,31,47,63,79,95]; -MainMenu.prototype.key_left=function () -{ - var old = this.items[this.item]; - this.item = this.item - 1; - if (this.item == -1) { - this.item = 0; - return; - } - - var target = this.items[this.item]; - - old.bbox.update(); - target.bbox.update(); - - var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); - animate.run([an], 0, 0.1); - an = new animate.scale(this.app, target, 1.1, 1.5); - animate.run([an], 0, 0.3); - var sx = target.center.x - this.lightbar.center.x; - var an = new animate.shift(this.app, this.lightbar, sx, 0); - animate.run([an], 0, 0.3); + app.addKeyListener(mbapp.KEY_LEFT, function() { + self.item = self.item - 1; + if (self.item == -1) { + self.item = 0; + return; + } + self.app.runToScene(self.itemToScene[self.item]); + }); + app.addKeyListener(mbapp.KEY_RIGHT, function() { + self.item = self.item + 1; + if (self.item == self.items.length) { + self.item = self.item - 1; + return; + } + self.app.runToScene(self.itemToScene[self.item]); + }); + app.addKeyListener(mbapp.KEY_ENTER, function() { + self.key_enter(); + }); } -MainMenu.prototype.key_right=function() -{ - var old = this.items[this.item]; - this.item = this.item + 1; - if (this.item == this.items.length) { - this.item = this.item - 1; - return; - } - - var target = this.items[this.item]; - - old.bbox.update(); - target.bbox.update(); - - var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); - animate.run([an], 0, 0.1); - an = new animate.scale(this.app, target, 1.1, 1.5); - animate.run([an], 0, 0.3); - var sx = target.center.x - this.lightbar.center.x; - var an = new animate.shift(this.app, this.lightbar, sx, 0); - animate.run([an], 0, 0.3); -} - -MainMenu.prototype.key_up=function() -{ - var old = this.lines[this.line]; - this.line = this.line - 1; - if (this.line == -1) { - this.line = 0; - return; - } - var target = this.lines[this.line]; - var sy = target.center.y - this.lightbar.center.y; - var an = new animate.shift(this.app, this.lightbar, 0, sy); - animate.run([an], 0, 0.3); -} - - -MainMenu.prototype.key_down=function () -{ - var old = this.lines[this.line]; - this.line = this.line + 1; - if (this.line == this.lines.length) { - this.line = this.line - 1; - return; - } - var target = this.lines[this.line]; - var sy = target.center.y - this.lightbar.center.y; - var an = new animate.shift(this.app, this.lightbar, 0, sy); - animate.run([an], 0, 0.3); -} MainMenu.prototype.key_enter=function() { var self = this; var target = this.items[this.item]; - var an = new animate.scale(this.app, target, 1/1.1, 1/1.5); + var an = new animate.scale(this.app, target, 1, 1/1.5); animate.run([an], 0, 0.3,function() { var sx = 259 - target.center.x; var sy = 355 - target.center.y; var an1 = new animate.shift(self.app,target,sx,sy); - animate.run([an1],0,1,function() {self.changePage(self.item);}); + animate.run([an1],0,1,function() { + self.changePage(self.item); + }); }); for(i=0;i this.item) { - sx = 1920*2 - this.items[i].center.x; + sx = 1920 - this.items[i].center.x; sy = 0; } else { sx = -this.items[i].center.x*2; sy = 0; } - an = new animate.shift(this.app,this.items[i], sx, sy); - animate.run([an], 0, 2); - alpha = new animate.alpha(this.app,this.items[i], 0); - animate.run([an], 0, 2); + //alpha = new animate.alpha(this.app,this.items[i], 0); + an = new animate.shift(this.app,this.items[i], sx,sy); + animate.run([an], 0, 1); } } MainMenu.prototype.onNextPage=function() { - this.app.changeScene(2); + this.app.changeScene(97); } MainMenu.prototype.changePage=function(item) { - this.epg.getList(item,self.onNextPage()); + this.app.epg.getList(item,this.onNextPage); } exports.MainMenu=MainMenu; diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/mbapp.js --- a/nodejs/mbapp.js Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/mbapp.js Wed Apr 06 21:35:21 2011 +0800 @@ -4,6 +4,7 @@ var svg = require("./svg"); var sys = require("sys"); var ldr = mbfly.img_ldr_new("."); +var component = require("./component"); function _reverse(m1) { var rev = new Array(1, 0, 0, 0, 1, 0); @@ -123,8 +124,16 @@ this.keymap={}; this.onKeyPress = null; this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); - this.frame_interval = 1000/24; // 12 frame per second + this.frame_interval = 1000/30; // 12 frame per second this.timer = null; + this._time = Date.now(); + this._componentmanager = new component.ComponentManager(this); +} + +app.prototype.ts=function(m) { + var now = Date.now(); + var t = now-this._time; + sys.puts("["+t+"] "+m); } app.prototype.loadSVG=function(fname) { this.svg.load(this.mb_rt,this.mb_rt.root,fname); @@ -147,14 +156,28 @@ this.mb_rt.redraw_all(); this.mb_rt.flush(); } + app.prototype.get=function(name) { return this.mb_rt.mbnames[name]; } + + +app.prototype.getComponent=function(name) { + var comp = new component.Component(this,name); + this._componentmanager.dump(); + comp.realize(); + sys.puts("Search for "+name); + var obj = comp.toCoord(); + sys.puts("obj="+obj+" id="+obj.id+" refid="+obj.refid); + return comp; +} + app.prototype.addKeyboardListener=function(type,f) { return this.mb_rt.kbevents.add_event_observer(type,f); } app.prototype.refresh=function() { this.mb_rt.redraw_changed(); + //this.mb_rt.redraw_all(); this.mb_rt.flush(); } app.prototype.dump=function() { @@ -176,6 +199,10 @@ src.hide(); // Duplicate the group var nodes = src.children; + //if (src.dup) { + // src.dup.remove(); + // src.dup = null; + //} if (src.dup == null) { var dup = this.mb_rt.coord_new(src.parent); for (i in nodes) { @@ -183,6 +210,8 @@ var ng = this.mb_rt.coord_new(dup); var k = dup.clone_from_subtree(c); c.dup = k; + c.dup.id = c.id; + c.dup.refid = c.refid; } src.dup = dup; } else { @@ -195,9 +224,10 @@ for(i in nodes) { coord= nodes[i]; - if (coord.target) + if (coord.target) { this.generateScaleTweenObject(coord.dup,coord,coord.target,p,''); - else { + this._componentmanager.add(coord,coord.dup); + } else { sys.puts(coord.id); sys.puts(coord[0]); sys.puts(coord[1]); @@ -222,8 +252,8 @@ app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { //sys.puts("xxxxxxx"); //sys.puts("dest="+dest); - // sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); - //sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); + sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); + sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); //sys.puts("src.center="+src.center); //sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); if (src == null) return; @@ -277,7 +307,7 @@ nth = this.svg.getFrameNumber(s); if (nth == -1) return; } - sys.puts("goto to scene "+nth); + this.ts("goto to scene "+nth); this.currentScene = nth; var scenes = this.svg.scenes; if (scenes == null) return; @@ -312,7 +342,9 @@ } } this.get(scenes[i].ref).hide(); + this.ts("refresh"); this.refresh(); + this.ts("refresh done"); } app.prototype.runToScene=function(s) { @@ -334,17 +366,19 @@ this.startScene = this.currentScene; this.starttime = Date.now(); if (this.timer == null) { - this.timer = setTimeout(function() { - self.skipFrame() - }, this.frame_interval); + this.skipFrame(); } } app.prototype.skipFrame=function() { var self = this; if (this.currentScene != this.targetScene) { - var step = Math.round((Date.now() - this.starttime)/this.frame_interval)*this.skipdir; + var now = Date.now(); + var step = Math.round((now - this.starttime)/this.frame_interval)*this.skipdir; nextframe = this.startScene + step + //nextframe = this.currentScene + this.skipdir; + this.ts("goto begin"); + if (this.skipdir>0) { if (nextframe > this.targetScene) nextframe = this.targetScene; @@ -352,14 +386,22 @@ if (nextframe < this.targetScene) nextframe = this.targetScene; } - this.changeScene(nextframe); if (nextframe != this.targetScene) { + var timegap = (nextframe-this.startScene)*this.skipdir*this.frame_interval+this.starttime - Date.now(); + sys.puts("goto "+timegap); + if (timegap <200) { + timegap = 0; + } else { + } this.timer = setTimeout(function() { self.skipFrame() - }, this.frame_interval); + }, timegap); } else { this.timer = null; } + this.changeScene(nextframe); + now = Date.now(); + this.ts("goto end"); } } diff -r ce981aa3fbf2 -r 6fa411fd9549 nodejs/svg.js --- a/nodejs/svg.js Mon Apr 04 12:43:29 2011 +0800 +++ b/nodejs/svg.js Wed Apr 06 21:35:21 2011 +0800 @@ -976,16 +976,14 @@ attr = n.attr('duplicate-src'); if (attr) { var id = attr.value(); - var orign = this.mb_rt.mbnames[id].node; - sys.puts("xxxxxxxxxxxxxx"); - var nw = getInteger(orign,'width'); - var nh = getInteger(orign,'height'); - sys.puts("nw="+nw); - sys.puts("nh="+nh); - sys.puts("w="+w); - sys.puts("h="+h); - tcoord.sx *= w/nw; - tcoord.sy *= h/nh; + var coord = this.mb_rt.mbnames[id]; + if (coord) { + var orign = this.mb_rt.mbnames[id].node; + var nw = getInteger(orign,'width'); + var nh = getInteger(orign,'height'); + tcoord.sx *= w/nw; + tcoord.sy *= h/nh; + } } @@ -1037,13 +1035,40 @@ this.parseGroup(m,root,id, n) } +function getName(n) +{ + var attr = n.attr('mbname'); + var name; + + if (attr) { + name = attr.value(); + if (name != '') return name; + } + attr = n.attr('label'); + + if (attr) { + name = attr.value(); + if (name != '') return name; + } + attr = n.attr('id'); + + if (attr) { + name = attr.value(); + if (name != '') return name; + } + + return ''; + +} + loadSVG.prototype._check_duplicate_src=function(n,coord) { - var id = n.attr('id'); - coord.id = id; + var id = getName(n); if (id) { - coord.id = id.value(); + coord.id = id; + coord.refid = id; } else { coord.id = "NA"; + coord.refid ="NA"; } if (n.name()=="use") { n.coord.isuse = true @@ -1061,6 +1086,7 @@ sys.puts("duplicated"); } this.mb_rt.mbnames[id].target = coord; + coord.refid = this.mb_rt.mbnames[id].id; } catch(e) { sys.puts("id "+id+" is not defined"); } diff -r ce981aa3fbf2 -r 6fa411fd9549 pyink/domview.py --- a/pyink/domview.py Mon Apr 04 12:43:29 2011 +0800 +++ b/pyink/domview.py Wed Apr 06 21:35:21 2011 +0800 @@ -35,7 +35,10 @@ pass def name(self): - name = self.scenes_node.getAttribute('name') + try: + name = self.scenes_node.getAttribute('name') + except: + name='default' return name def rename(self, new_name):