チェンジセット 1489

差分発生行の前後
無視リスト:
コミット日時:
2008/10/02 21:00:22 (4 年前)
コミッタ:
gyuque
ログメッセージ:

supported complex shapes, linear gradient fill, mix implicit/explicit this reference

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • ruby/jsplash/trunk/client2/demo_20081001/asblock.js

    r1479 r1489  
    1212      onEnterFrame = function () { 
    1313        if (!this.a_set) { 
    14           _x = Math.random() * 700 - 30; 
    15           _y = -70 - Math.random() * 460; 
     14          this._x = Math.random() * 700 - 30; 
     15          this._y = -70 - Math.random() * 460; 
    1616          this.ay = Math.random() * 4 + 5; 
    1717          this.ax = Math.random() * 7 - 3; 
  • ruby/jsplash/trunk/client2/index.xml

    r1478 r1489  
    5353                <div id="progbar"><div>  </div></div> 
    5454                <p id="statusout"> </p> 
    55                 <p id="sout">starting <em>JSplash Player 0.2.2</em>...<br />-------------------------------------<br /></p> 
     55                <p id="sout">starting <em>JSplash Player 0.2.4</em>...<br />-------------------------------------<br /></p> 
    5656                <svg id="svgrt" xmlns="http://www.w3.org/2000/svg" style="width: 100px; height: 100px;"> 
    5757                </svg> 
  • ruby/jsplash/trunk/client2/jsplash/objects.js

    r1478 r1489  
    66JSplash.injectScriptVariables = function(func, vlist) { 
    77        var decls = ["\n"]; 
    8         var saves = ["\n"]; 
     8        var saves = ["}\n"]; 
    99        var len = vlist.length; 
    1010         
     
    1313                saves.push("this.__locals__['"+vlist[i]+"'] = "+vlist[i]+";\n"); 
    1414        } 
     15         
     16        decls.push("with(this){\n"); 
     17         
    1518         
    1619        var func2; 
     
    233236                this.updateProxy(); 
    234237 
    235                 var vlist = P.thisMembersList(); 
     238                var vlist = []; // P.thisMembersList(); 
    236239                var len, i; 
    237240                 
     
    240243                        vlist.push(objname); 
    241244                        this.getProxy().__locals__[objname] = this.nameMap[objname].getProxy(); 
    242                         this.getProxy().setChidrenRefs(); 
     245                        this.getProxy().__setChidrenRefs__(); 
    243246                } 
    244247 
     
    266269                } 
    267270 
    268                 P.setThisObjects(); 
    269                 P.saveBindedLocal(); 
     271                //P.setThisObjects(); 
     272                //P.saveBindedLocal(); 
     273                P.__prepareImplicitThis__(); 
    270274                try { 
    271275                        act.tweaked_action(); 
     
    274278                        console.log("[AS] " + e); 
    275279                } 
    276                 P.pickBindedLocal(); 
     280                //P.pickBindedLocal(); 
    277281                this.applyProxyChanges(); 
    278282 
     
    465469                this.__locals__ = {}; 
    466470                this.__old_locals__ = {}; 
    467                 this.setThisObjects(); 
    468         }, 
    469          
    470         setChidrenRefs: function() { 
     471                //this.setThisObjects(); 
     472        }, 
     473         
     474        __setChidrenRefs__: function() { 
    471475                var m = this.owner.nameMap; 
    472476                for (var name in m) { 
     
    474478                        { 
    475479                                this[name] = m[name].getProxy(); 
    476                                 this[name].setChidrenRefs(); 
     480                                this[name].__setChidrenRefs__(); 
    477481                                m[name].updateProxy(); 
    478482                        } 
     
    480484        }, 
    481485         
     486        __prepareImplicitThis__: function() { 
     487                if (!this.onEnterFrame) 
     488                        this.onEnterFrame = null; 
     489        }, 
     490         
     491        /* 
    482492        setThisObjects: function() { 
    483493                var thislist = this.thisMembersList(); 
     
    505515        }, 
    506516         
     517         
     518        thisMembersList: function() { 
     519                return ['play', 'stop', '_parent', 'gotoAndPlay', 'gotoAndStop', 'onEnterFrame', '_x', '_y', '_rotation', '_xscale', '_yscale']; 
     520        }, 
     521         
     522        */ 
     523         
    507524        type_of: function() { 
    508525                return this.owner.klass.swf_object_type; 
    509         }, 
    510          
    511         thisMembersList: function() { 
    512                 return ['play', 'stop', '_parent', 'gotoAndPlay', 'gotoAndStop', 'onEnterFrame', '_x', '_y', '_rotation', '_xscale', '_yscale']; 
    513526        }, 
    514527         
  • ruby/jsplash/trunk/client2/jsplash/player.js

    r1464 r1489  
    1616                this.executor.frameRate = swf.frameRate; 
    1717                this.svg = svg; 
     18                JSplash.createFillDef(svg); 
    1819         
    1920                svg.style.width  = swf.pxWidth  + "px"; 
  • ruby/jsplash/trunk/client2/jsplash/shaperenderer.js

    r1478 r1489  
    22JSplash.ShapeRenderer.prototype = { 
    33        initialize: function(source) { 
     4                this.shape_id = source.id; 
    45                this.edgeStyles = source.line_styles.slice(); 
    56                this.fillStyles = source.fill_styles; 
     
    89                this.rightFillEdges = {}; 
    910                this.edgeList = []; 
     11                this.displayList = null; 
    1012                 
    1113                this.fillLoops = null; 
    1214                this.te_id = 0; 
     15                this.fillDefMap = {}; 
     16        }, 
     17         
     18        lookupFillId: function(fi) { 
     19                if (!JSplash.defsElement) 
     20                        return null; 
     21         
     22                if (this.fillDefMap[fi]) { 
     23                        return this.fillDefMap[fi]; 
     24                } 
     25                 
     26                var fid = "gf"+this.shape_id+"_"+fi; 
     27                var filldata = this.fillStyles[fi-1]; 
     28                if (!filldata.grad) 
     29                        return null; 
     30                         
     31                var attrs = {id: fid, gradientUnits: 'userSpaceOnUse', x1: -819, x2: 819}; 
     32                if (filldata.mov || filldata.scl || filldata.skw) { 
     33                        var M =[1, 0, 0, 1, 0, 0]; 
     34                        if (filldata.mov) { 
     35                                M[4] = JSplash.$twips(filldata.mov[0]); 
     36                                M[5] = JSplash.$twips(filldata.mov[1]); 
     37                        } 
     38 
     39                        if (filldata.scl) { 
     40                                M[0] = filldata.scl[0]; 
     41                                M[3] = filldata.scl[1]; 
     42                        } 
     43 
     44                        if (filldata.skw) { 
     45                                M[1] = filldata.skw[0]; 
     46                                M[2] = filldata.skw[1]; 
     47                        } 
     48 
     49                        attrs.gradientTransform = "matrix("+M.join(' ')+")"; 
     50                } 
     51                 
     52                var gdef = JSplash.$svg("linearGradient", attrs); 
     53                JSplash.defsElement.appendChild(gdef); 
     54                 
     55                 
     56                var len = filldata.s.length; 
     57                for (var i = 0;i < len;i++) { 
     58                        var stp = JSplash.$svg("stop", {'stop-color': ('#'+filldata.c[i]), offset: (filldata.s[i] / 255)}); 
     59                        gdef.appendChild(stp); 
     60                } 
     61                 
     62                this.fillDefMap[fi] = fid; 
     63                return fid; 
    1364        }, 
    1465 
     
    2576                var _ty = 0; 
    2677                var _first_seg = true; 
     78                 
     79                var order_index = 0; 
    2780 
    2881                var x1, y1; 
     
    64117 
    65118                                if (rcd.f0 != undefined) { 
    66                                         cur_leftFill  = rcd.f0 + fs_ofs
     119                                        cur_leftFill  = rcd.f0 ? (rcd.f0 + fs_ofs) : 0
    67120                                } 
    68121 
    69122                                if (rcd.f1 != undefined) { 
    70                                         cur_rightFill = rcd.f1 + fs_ofs
     123                                        cur_rightFill = rcd.f1 ? (rcd.f1 + fs_ofs) : 0
    71124                                } 
    72125 
    73126                                if (rcd.ls != undefined) { 
    74                                         cur_lineStyle = rcd.ls + es_ofs
     127                                        cur_lineStyle = rcd.ls ? (rcd.ls + es_ofs) : 0
    75128                                } 
    76129                        } 
     
    87140                                        _ty = y2 + rcd.p[3]; 
    88141                                 
    89                                         this.addCurve(_first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,   x1, y1, x2, y2, _tx, _ty); 
     142                                        this.addCurve(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,   x1, y1, x2, y2, _tx, _ty); 
    90143                                } 
    91144                                else 
     
    97150                                        _ty += rcd.p[1]; 
    98151                                 
    99                                         this.addLine(_first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,   x1, y1, _tx, _ty); 
     152                                        this.addLine(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,   x1, y1, _tx, _ty); 
    100153                                } 
    101154                                 
     
    107160        }, 
    108161         
    109         addLine: function(fst, ls, fL, fR, x1, y1, x2, y2) { 
     162        addLine: function(oi, fst, ls, fL, fR, x1, y1, x2, y2) { 
    110163                var E = new JSplash.EdgePart(false, ls, fst); 
     164                E.oi = oi; 
    111165                E.tx1 = x1; 
    112166                E.ty1 = y1; 
     
    117171        }, 
    118172         
    119         addCurve: function(fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { 
     173        addCurve: function(oi, fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { 
    120174                var E = new JSplash.EdgePart(true, ls, fst); 
     175                E.oi = oi; 
    121176                E.tx1 = x1; 
    122177                E.ty1 = y1; 
     
    149204        }, 
    150205         
     206        buildDrawOrder: function() { 
     207                if (this.displayList) 
     208                        return; 
     209 
     210                var loopss = this.fillLoops; 
     211                if (!loopss) return; 
     212                         
     213                this.displayList = []; 
     214                var len, i, llen, k, E, lps, fi; 
     215                 
     216                var elist = this.edgeList; 
     217                 
     218                // gather head edges of polylines 
     219                len = elist.length; 
     220                for (i = 0;i < len;i++) { 
     221                        E = elist[i]; 
     222                        if (!E.isFirst) continue; 
     223                         
     224                        this.displayList.push(new JSplash.DisplayListEntry(0, i, E.oi+1)); 
     225                } 
     226 
     227                var ent; 
     228                // gather fill loops 
     229                len = loopss.length; 
     230                for (i = 0;i < len;i++) { 
     231                        lps  = loopss[i].loops; 
     232                        llen = lps.length; 
     233                        fi = loopss[i].fill_index; 
     234                         
     235                        ent = new JSplash.DisplayListEntry(1, lps, lps[0][0].original.oi); 
     236                        ent.fill_index = fi; 
     237                        this.displayList.push(ent); 
     238                         
     239                        /* 
     240                        for (k = 0;k < llen;k++) { 
     241                                ent = new JSplash.DisplayListEntry(1, lps[k], lps[k][0].original.oi); 
     242                                ent.fill_index = fi; 
     243                                console.log(fi); 
     244                                this.displayList.push(ent); 
     245                        }*/ 
     246                } 
     247                 
     248                this.displayList.sort(this.osorter); 
     249        }, 
     250         
     251        renderDisplayList: function(g) { 
     252                if (!this.displayList) 
     253                        return; 
     254         
     255                var list = this.displayList; 
     256                var len  = list.length; 
     257                var di; 
     258                 
     259                for (var i = 0;i < len;i++) { 
     260                        di = list[i]; 
     261                        if (di.type == 0) 
     262                                this.buildEdges(g, di.obj, -1); 
     263                        else { 
     264                                this.buildAFill(di.obj, di.fill_index, g); 
     265                        } 
     266                } 
     267        }, 
     268         
     269        osorter: function (a,b) { 
     270                return a.index - b.index; 
     271        }, 
     272         
    151273        buildFills: function(g) { 
    152274                var loopss = this.fillLoops; 
     
    158280                        this.buildAFill(loopss[i].loops, this.fillStyles[loopss[i].fill_index-1], g); 
    159281                } 
    160         }, 
    161  
    162         buildAFill: function(list, style, g) { 
     282                /* 
     283                 
     284                var elist   = this.edgeList; 
     285                var next_fi = null; 
     286                var edge_start = 0; 
     287                var edge_end   = elist.length; 
     288                 
     289                if (this.layerStartIndices.length) 
     290                { 
     291                        next_fi = this.layerStartIndices[0].fi; 
     292                        edge_end   = this.layerStartIndices[0].ei; 
     293                        this.layerStartIndices.shift(); 
     294                } 
     295                 
     296         
     297                for (var i = 0;i < len;i++) { 
     298                        if (next_fi && loopss[i].fill_index >= next_fi) { 
     299                                this.buildEdges(g, edge_start, edge_end); 
     300                         
     301                                edge_start = edge_end; 
     302                                if (this.layerStartIndices.length) { 
     303                                        next_fi    = this.layerStartIndices[0].fi; 
     304                                        edge_end   = this.layerStartIndices[0].ei; 
     305                                        this.layerStartIndices.shift(); 
     306                                } 
     307                                else { 
     308                                        next_fi  = null; 
     309                                        edge_end = elist.length; 
     310                                } 
     311 
     312                        } 
     313                 
     314                        this.buildAFill(loopss[i].loops, this.fillStyles[loopss[i].fill_index-1], g); 
     315                } 
     316                 
     317                this.buildEdges(g, edge_start, edge_end);*/ 
     318        }, 
     319 
     320        buildAFill: function(list, fi, g) { 
     321                var style = this.fillStyles[fi-1]; 
    163322                if (!style) return; 
    164323                 
     
    166325                if (style.rgb) 
    167326                        style_str = '#'+style.rgb; 
     327                else if (style.grad) 
     328                        style_str = 'url(#' + this.lookupFillId(fi)+')'; 
    168329                         
    169330                if (!style_str) return; 
     
    199360                g.appendChild( JSplash.$svg('path', {d: commands.join(' '), fill: style_str}) ); 
    200361        }, 
    201          
    202         buildSVG: function(g) { 
    203                 this.buildFills(g); 
    204          
     362 
     363        buildALoop: function(lp, style, g) { 
     364                if (!style) return; 
     365                 
     366                var style_str = null; 
     367                if (style.rgb) 
     368                        style_str = '#'+style.rgb; 
     369                         
     370                if (!style_str) return; 
     371                var E; 
     372                var commands = [], k; 
     373                var llen = lp.length; 
     374                for (k = 0;k < llen;k++) { 
     375                        E = lp[k]; 
     376                        E.calcPx(); 
     377                        if (k==0) 
     378                                commands.push('M '+E.px1+','+E.py1); 
     379                                 
     380                        if (E.original.curved) { 
     381                                commands.push('Q ' + E.pxC +','+ E.pyC); 
     382                                commands.push(E.px2 +','+ E.py2); 
     383                        } 
     384                        else 
     385                                commands.push('L ' + E.px2 +','+ E.py2); 
     386                }                
     387                 
     388                commands.push('Z'); 
     389                g.appendChild( JSplash.$svg('path', {d: commands.join(' '), fill: style_str}) ); 
     390        }, 
     391         
     392        buildEdges: function(g, edge_start, edge_end) { 
    205393                var E; 
    206394                var edges = this.edgeList; 
     
    212400                var curStyle = null; 
    213401                 
    214                 for (var i = 0;i < len;i++) { 
     402                var oneshot = 0; 
     403                if (edge_end < 0) { 
     404                        edge_end = edges.length; 
     405                        oneshot = 1; 
     406                } 
     407                 
     408                for (var i = edge_start;i < edge_end;i++) { 
    215409                        E = edges[i]; 
    216410                        E.calcPx(); 
     
    223417                                                paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: curStyle, 'stroke-width': curWidth})); 
    224418                                } 
     419 
     420                                if (oneshot == 2) 
     421                                        break; 
    225422                                 
    226423                                if (E.lineStyle) { 
     
    229426                                        curStyle = '#' + this.edgeStyles[ E.lineStyle-1 ].rgb; 
    230427                                } 
     428                                 
     429                                if (oneshot == 1) 
     430                                        oneshot = 2; 
    231431                        } 
    232432                         
     
    248448                for (;paths.length;) 
    249449                        g.appendChild(paths.shift()); 
    250                  
     450        }, 
     451         
     452        buildSVG: function(g) { 
     453                this.buildDrawOrder(); 
     454                this.renderDisplayList(g); 
    251455                return g; 
    252456        }, 
     
    395599} 
    396600 
     601JSplash.DisplayListEntry = function(t, obj, i) { 
     602        this.index = i; 
     603        this.type  = t; /* 0: edge  1: fill loop */ 
     604        this.obj   = obj; 
     605        this.fill_index = 0; 
     606} 
     607 
    397608JSplash.EdgePart = function(cv, ls, first) { 
    398609        this.isFirst = first; 
     
    400611        this.lineStyle = ls; 
    401612        this.px1 = null; 
     613        this.oi = 0; 
    402614        /* tx1, ty1, tx2, ty2, txC, tyC */ 
    403615} 
     
    449661} 
    450662 
    451  
     663JSplash.createFillDef = function(svg) { 
     664        if (!JSplash.defsElement) { 
     665                var defs = JSplash.$svg('defs'); 
     666                svg.appendChild(defs); 
     667                JSplash.defsElement = defs; 
     668        } 
     669
    452670 
    453671JSplash.EdgePart.prototype.calcPx = function() {