Index: /ruby/jsplash/trunk/client2/demo_20081001/asblock.js =================================================================== --- /ruby/jsplash/trunk/client2/demo_20081001/asblock.js (リビジョン 1479) +++ /ruby/jsplash/trunk/client2/demo_20081001/asblock.js (リビジョン 1489) @@ -12,6 +12,6 @@ onEnterFrame = function () { if (!this.a_set) { - _x = Math.random() * 700 - 30; - _y = -70 - Math.random() * 460; + this._x = Math.random() * 700 - 30; + this._y = -70 - Math.random() * 460; this.ay = Math.random() * 4 + 5; this.ax = Math.random() * 7 - 3; Index: /ruby/jsplash/trunk/client2/jsplash/shaperenderer.js =================================================================== --- /ruby/jsplash/trunk/client2/jsplash/shaperenderer.js (リビジョン 1478) +++ /ruby/jsplash/trunk/client2/jsplash/shaperenderer.js (リビジョン 1489) @@ -2,4 +2,5 @@ JSplash.ShapeRenderer.prototype = { initialize: function(source) { + this.shape_id = source.id; this.edgeStyles = source.line_styles.slice(); this.fillStyles = source.fill_styles; @@ -8,7 +9,57 @@ this.rightFillEdges = {}; this.edgeList = []; + this.displayList = null; this.fillLoops = null; this.te_id = 0; + this.fillDefMap = {}; + }, + + lookupFillId: function(fi) { + if (!JSplash.defsElement) + return null; + + if (this.fillDefMap[fi]) { + return this.fillDefMap[fi]; + } + + var fid = "gf"+this.shape_id+"_"+fi; + var filldata = this.fillStyles[fi-1]; + if (!filldata.grad) + return null; + + var attrs = {id: fid, gradientUnits: 'userSpaceOnUse', x1: -819, x2: 819}; + if (filldata.mov || filldata.scl || filldata.skw) { + var M =[1, 0, 0, 1, 0, 0]; + if (filldata.mov) { + M[4] = JSplash.$twips(filldata.mov[0]); + M[5] = JSplash.$twips(filldata.mov[1]); + } + + if (filldata.scl) { + M[0] = filldata.scl[0]; + M[3] = filldata.scl[1]; + } + + if (filldata.skw) { + M[1] = filldata.skw[0]; + M[2] = filldata.skw[1]; + } + + attrs.gradientTransform = "matrix("+M.join(' ')+")"; + } + + var gdef = JSplash.$svg("linearGradient", attrs); + JSplash.defsElement.appendChild(gdef); + + + var len = filldata.s.length; + for (var i = 0;i < len;i++) { + var stp = JSplash.$svg("stop", {'stop-color': ('#'+filldata.c[i]), offset: (filldata.s[i] / 255)}); + gdef.appendChild(stp); + } + + this.fillDefMap[fi] = fid; + return fid; }, @@ -25,4 +76,6 @@ var _ty = 0; var _first_seg = true; + + var order_index = 0; var x1, y1; @@ -64,13 +117,13 @@ if (rcd.f0 != undefined) { - cur_leftFill = rcd.f0 + fs_ofs; + cur_leftFill = rcd.f0 ? (rcd.f0 + fs_ofs) : 0; } if (rcd.f1 != undefined) { - cur_rightFill = rcd.f1 + fs_ofs; + cur_rightFill = rcd.f1 ? (rcd.f1 + fs_ofs) : 0; } if (rcd.ls != undefined) { - cur_lineStyle = rcd.ls + es_ofs; + cur_lineStyle = rcd.ls ? (rcd.ls + es_ofs) : 0; } } @@ -87,5 +140,5 @@ _ty = y2 + rcd.p[3]; - this.addCurve(_first_seg, cur_lineStyle, cur_leftFill, cur_rightFill, x1, y1, x2, y2, _tx, _ty); + this.addCurve(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill, x1, y1, x2, y2, _tx, _ty); } else @@ -97,5 +150,5 @@ _ty += rcd.p[1]; - this.addLine(_first_seg, cur_lineStyle, cur_leftFill, cur_rightFill, x1, y1, _tx, _ty); + this.addLine(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill, x1, y1, _tx, _ty); } @@ -107,6 +160,7 @@ }, - addLine: function(fst, ls, fL, fR, x1, y1, x2, y2) { + addLine: function(oi, fst, ls, fL, fR, x1, y1, x2, y2) { var E = new JSplash.EdgePart(false, ls, fst); + E.oi = oi; E.tx1 = x1; E.ty1 = y1; @@ -117,6 +171,7 @@ }, - addCurve: function(fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { + addCurve: function(oi, fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { var E = new JSplash.EdgePart(true, ls, fst); + E.oi = oi; E.tx1 = x1; E.ty1 = y1; @@ -149,4 +204,71 @@ }, + buildDrawOrder: function() { + if (this.displayList) + return; + + var loopss = this.fillLoops; + if (!loopss) return; + + this.displayList = []; + var len, i, llen, k, E, lps, fi; + + var elist = this.edgeList; + + // gather head edges of polylines + len = elist.length; + for (i = 0;i < len;i++) { + E = elist[i]; + if (!E.isFirst) continue; + + this.displayList.push(new JSplash.DisplayListEntry(0, i, E.oi+1)); + } + + var ent; + // gather fill loops + len = loopss.length; + for (i = 0;i < len;i++) { + lps = loopss[i].loops; + llen = lps.length; + fi = loopss[i].fill_index; + + ent = new JSplash.DisplayListEntry(1, lps, lps[0][0].original.oi); + ent.fill_index = fi; + this.displayList.push(ent); + + /* + for (k = 0;k < llen;k++) { + ent = new JSplash.DisplayListEntry(1, lps[k], lps[k][0].original.oi); + ent.fill_index = fi; + console.log(fi); + this.displayList.push(ent); + }*/ + } + + this.displayList.sort(this.osorter); + }, + + renderDisplayList: function(g) { + if (!this.displayList) + return; + + var list = this.displayList; + var len = list.length; + var di; + + for (var i = 0;i < len;i++) { + di = list[i]; + if (di.type == 0) + this.buildEdges(g, di.obj, -1); + else { + this.buildAFill(di.obj, di.fill_index, g); + } + } + }, + + osorter: function (a,b) { + return a.index - b.index; + }, + buildFills: function(g) { var loopss = this.fillLoops; @@ -158,7 +280,44 @@ this.buildAFill(loopss[i].loops, this.fillStyles[loopss[i].fill_index-1], g); } - }, - - buildAFill: function(list, style, g) { + /* + + var elist = this.edgeList; + var next_fi = null; + var edge_start = 0; + var edge_end = elist.length; + + if (this.layerStartIndices.length) + { + next_fi = this.layerStartIndices[0].fi; + edge_end = this.layerStartIndices[0].ei; + this.layerStartIndices.shift(); + } + + + for (var i = 0;i < len;i++) { + if (next_fi && loopss[i].fill_index >= next_fi) { + this.buildEdges(g, edge_start, edge_end); + + edge_start = edge_end; + if (this.layerStartIndices.length) { + next_fi = this.layerStartIndices[0].fi; + edge_end = this.layerStartIndices[0].ei; + this.layerStartIndices.shift(); + } + else { + next_fi = null; + edge_end = elist.length; + } + + } + + this.buildAFill(loopss[i].loops, this.fillStyles[loopss[i].fill_index-1], g); + } + + this.buildEdges(g, edge_start, edge_end);*/ + }, + + buildAFill: function(list, fi, g) { + var style = this.fillStyles[fi-1]; if (!style) return; @@ -166,4 +325,6 @@ if (style.rgb) style_str = '#'+style.rgb; + else if (style.grad) + style_str = 'url(#' + this.lookupFillId(fi)+')'; if (!style_str) return; @@ -199,8 +360,35 @@ g.appendChild( JSplash.$svg('path', {d: commands.join(' '), fill: style_str}) ); }, - - buildSVG: function(g) { - this.buildFills(g); - + + buildALoop: function(lp, style, g) { + if (!style) return; + + var style_str = null; + if (style.rgb) + style_str = '#'+style.rgb; + + if (!style_str) return; + var E; + var commands = [], k; + var llen = lp.length; + for (k = 0;k < llen;k++) { + E = lp[k]; + E.calcPx(); + if (k==0) + commands.push('M '+E.px1+','+E.py1); + + if (E.original.curved) { + commands.push('Q ' + E.pxC +','+ E.pyC); + commands.push(E.px2 +','+ E.py2); + } + else + commands.push('L ' + E.px2 +','+ E.py2); + } + + commands.push('Z'); + g.appendChild( JSplash.$svg('path', {d: commands.join(' '), fill: style_str}) ); + }, + + buildEdges: function(g, edge_start, edge_end) { var E; var edges = this.edgeList; @@ -212,5 +400,11 @@ var curStyle = null; - for (var i = 0;i < len;i++) { + var oneshot = 0; + if (edge_end < 0) { + edge_end = edges.length; + oneshot = 1; + } + + for (var i = edge_start;i < edge_end;i++) { E = edges[i]; E.calcPx(); @@ -223,4 +417,7 @@ paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: curStyle, 'stroke-width': curWidth})); } + + if (oneshot == 2) + break; if (E.lineStyle) { @@ -229,4 +426,7 @@ curStyle = '#' + this.edgeStyles[ E.lineStyle-1 ].rgb; } + + if (oneshot == 1) + oneshot = 2; } @@ -248,5 +448,9 @@ for (;paths.length;) g.appendChild(paths.shift()); - + }, + + buildSVG: function(g) { + this.buildDrawOrder(); + this.renderDisplayList(g); return g; }, @@ -395,4 +599,11 @@ } +JSplash.DisplayListEntry = function(t, obj, i) { + this.index = i; + this.type = t; /* 0: edge 1: fill loop */ + this.obj = obj; + this.fill_index = 0; +} + JSplash.EdgePart = function(cv, ls, first) { this.isFirst = first; @@ -400,4 +611,5 @@ this.lineStyle = ls; this.px1 = null; + this.oi = 0; /* tx1, ty1, tx2, ty2, txC, tyC */ } @@ -449,5 +661,11 @@ } - +JSplash.createFillDef = function(svg) { + if (!JSplash.defsElement) { + var defs = JSplash.$svg('defs'); + svg.appendChild(defs); + JSplash.defsElement = defs; + } +} JSplash.EdgePart.prototype.calcPx = function() { Index: /ruby/jsplash/trunk/client2/jsplash/objects.js =================================================================== --- /ruby/jsplash/trunk/client2/jsplash/objects.js (リビジョン 1478) +++ /ruby/jsplash/trunk/client2/jsplash/objects.js (リビジョン 1489) @@ -6,5 +6,5 @@ JSplash.injectScriptVariables = function(func, vlist) { var decls = ["\n"]; - var saves = ["\n"]; + var saves = ["}\n"]; var len = vlist.length; @@ -13,4 +13,7 @@ saves.push("this.__locals__['"+vlist[i]+"'] = "+vlist[i]+";\n"); } + + decls.push("with(this){\n"); + var func2; @@ -233,5 +236,5 @@ this.updateProxy(); - var vlist = P.thisMembersList(); + var vlist = []; // P.thisMembersList(); var len, i; @@ -240,5 +243,5 @@ vlist.push(objname); this.getProxy().__locals__[objname] = this.nameMap[objname].getProxy(); - this.getProxy().setChidrenRefs(); + this.getProxy().__setChidrenRefs__(); } @@ -266,6 +269,7 @@ } - P.setThisObjects(); - P.saveBindedLocal(); + //P.setThisObjects(); + //P.saveBindedLocal(); + P.__prepareImplicitThis__(); try { act.tweaked_action(); @@ -274,5 +278,5 @@ console.log("[AS] " + e); } - P.pickBindedLocal(); + //P.pickBindedLocal(); this.applyProxyChanges(); @@ -465,8 +469,8 @@ this.__locals__ = {}; this.__old_locals__ = {}; - this.setThisObjects(); - }, - - setChidrenRefs: function() { + //this.setThisObjects(); + }, + + __setChidrenRefs__: function() { var m = this.owner.nameMap; for (var name in m) { @@ -474,5 +478,5 @@ { this[name] = m[name].getProxy(); - this[name].setChidrenRefs(); + this[name].__setChidrenRefs__(); m[name].updateProxy(); } @@ -480,4 +484,10 @@ }, + __prepareImplicitThis__: function() { + if (!this.onEnterFrame) + this.onEnterFrame = null; + }, + + /* setThisObjects: function() { var thislist = this.thisMembersList(); @@ -505,10 +515,13 @@ }, + + thisMembersList: function() { + return ['play', 'stop', '_parent', 'gotoAndPlay', 'gotoAndStop', 'onEnterFrame', '_x', '_y', '_rotation', '_xscale', '_yscale']; + }, + + */ + type_of: function() { return this.owner.klass.swf_object_type; - }, - - thisMembersList: function() { - return ['play', 'stop', '_parent', 'gotoAndPlay', 'gotoAndStop', 'onEnterFrame', '_x', '_y', '_rotation', '_xscale', '_yscale']; }, Index: /ruby/jsplash/trunk/client2/jsplash/player.js =================================================================== --- /ruby/jsplash/trunk/client2/jsplash/player.js (リビジョン 1464) +++ /ruby/jsplash/trunk/client2/jsplash/player.js (リビジョン 1489) @@ -16,4 +16,5 @@ this.executor.frameRate = swf.frameRate; this.svg = svg; + JSplash.createFillDef(svg); svg.style.width = swf.pxWidth + "px"; Index: /ruby/jsplash/trunk/client2/index.xml =================================================================== --- /ruby/jsplash/trunk/client2/index.xml (リビジョン 1478) +++ /ruby/jsplash/trunk/client2/index.xml (リビジョン 1489) @@ -53,5 +53,5 @@
-
starting JSplash Player 0.2.2...
-------------------------------------
starting JSplash Player 0.2.4...
-------------------------------------