チェンジセット 1464

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

supported solid fill

ファイル:

凡例:

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

    r1457 r1464  
    122122                 
    123123                t = Math.floor(1000 / this.frameRate); 
    124 if(this.frameCount++ < 155) 
     124                 
     125if(this.frameCount++ < 355) 
    125126                window.setTimeout(this.tick.bind(this), t); 
    126127        }, 
  • ruby/jsplash/trunk/client2/jsplash/objects.js

    r1462 r1464  
    177177         
    178178        doReservedAction: function() { 
    179 //              console.log("+++++ DoAction +++++ "+this+"  "+(this.context.frameC)); 
    180179                if (!this.klass) 
    181180                        return; 
     
    231230                } 
    232231                 
    233                 if (!act.tweaked_action || !JSplash.$arreq(vlist, act.vlist)) 
     232                var changed_proxy = false; 
     233                if (act.tweaked_action && act.tweaked_action._binded_this_ != this.getProxy()) 
     234                        changed_proxy = true; 
     235                 
     236                if (!act.tweaked_action || !JSplash.$arreq(vlist, act.vlist) || changed_proxy) 
    234237                { 
    235238                        act.vlist = vlist; 
    236239                        act.tweaked_action = ( JSplash.injectScriptVariables(act.action, vlist) ).bind( this.getProxy() ); 
     240                        act.tweaked_action._binded_this_ = this.getProxy(); 
    237241                } 
    238242                         
  • ruby/jsplash/trunk/client2/jsplash/player.js

    r1462 r1464  
    126126 
    127127JSplash.$putstat = function(s) { 
    128         $('statusout').innerHTML = s; 
     128        var o = $('statusout'); 
     129        if (o) 
     130                o.innerHTML = s; 
    129131} 
    130132 
  • ruby/jsplash/trunk/client2/jsplash/shaperenderer.js

    r1457 r1464  
    33        initialize: function(source) { 
    44                this.edgeStyles = source.line_styles.slice(); 
     5                this.fillStyles = source.fill_styles; 
    56                this.defineShape = source; 
    67                this.leftFillEdges  = {}; 
    78                this.rightFillEdges = {}; 
    89                this.edgeList = []; 
     10                 
     11                this.fillLoops = null; 
     12                this.te_id = 0; 
    913        }, 
    1014 
     
    2630                var x2, y2; 
    2731                 
    28 //////////////////////// 
    29 if (this.edgeStyles.length < 1) { 
    30 this.edgeStyles.push({w:30}); 
    31 cur_lineStyle=1; 
    32 } 
    33  
    3432                for (var i = 0;i < len;i++) { 
    3533                        rcd = records[i]; 
     
    8987                } 
    9088                 
    91                 this._dump(); 
     89                this.commitFill(); 
    9290        }, 
    9391         
     
    134132        }, 
    135133         
     134        buildFills: function(g) { 
     135                var loopss = this.fillLoops; 
     136                if (!loopss) return; 
     137                 
     138                var len = loopss.length; 
     139                 
     140                for (var i = 0;i < len;i++) { 
     141                        this.buildAFill(loopss[i].loops, this.fillStyles[loopss[i].fill_index-1], g); 
     142                } 
     143        }, 
     144 
     145        buildAFill: function(list, style, g) { 
     146                if (!style) return; 
     147                 
     148                var style_str = null; 
     149                if (style.rgb) 
     150                        style_str = '#'+style.rgb; 
     151                         
     152                if (!style_str) return; 
     153 
     154                 
     155                var len = list.length; 
     156                var commands = [], lp, k, llen, E; 
     157                for (var i = 0;i < len;i++) { 
     158                        lp = list[i]; 
     159                        llen = lp.length; 
     160                         
     161                        if (i) { 
     162                                commands.push('Z'); 
     163                        } 
     164                         
     165                        for (k = 0;k < llen;k++) { 
     166                                E = lp[k]; 
     167                                E.calcPx(); 
     168                                if (k==0) 
     169                                        commands.push('M '+E.px1+','+E.py1); 
     170                                         
     171                                if (E.original.curved) { 
     172                                        commands.push('Q ' + E.pxC +','+ E.pyC); 
     173                                        commands.push(E.px2 +','+ E.py2); 
     174                                } 
     175                                else 
     176                                        commands.push('L ' + E.px2 +','+ E.py2); 
     177                        } 
     178                } 
     179                 
     180                commands.push('Z'); 
     181                 
     182                g.appendChild( JSplash.$svg('path', {d: commands.join(' '), fill: style_str}) ); 
     183        }, 
     184         
    136185        buildSVG: function(g) { 
     186                this.buildFills(g); 
     187         
    137188                var E; 
    138189                var edges = this.edgeList; 
     
    142193                var paths = []; 
    143194                var curWidth = 0; 
     195                var curStyle = null; 
    144196                 
    145197                for (var i = 0;i < len;i++) { 
     
    152204                                        //commands.push('Z'); 
    153205                                        if (commands.length > 1) 
    154                                                 paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: 'black', 'stroke-width': curWidth})); 
     206                                                paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: curStyle, 'stroke-width': curWidth})); 
    155207                                } 
    156208                                 
     
    158210                                        commands = [( 'M ' + E.px1 +','+ E.py1 )]; 
    159211                                        curWidth = JSplash.$twips( this.edgeStyles[ E.lineStyle-1 ].w ); 
     212                                        curStyle = '#' + this.edgeStyles[ E.lineStyle-1 ].rgb; 
    160213                                } 
    161214                        } 
     
    175228 
    176229                if (commands.length > 1) 
    177                         paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: 'black', 'stroke-width': curWidth})); 
     230                        paths.push(JSplash.$svg('path', {d: commands.join(' '), fill: 'none', stroke: curStyle, 'stroke-width': curWidth})); 
    178231                for (;paths.length;) 
    179232                        g.appendChild(paths.shift()); 
     
    182235        }, 
    183236         
     237        commitFill: function() { 
     238                var len, i; 
     239 
     240                var fi; 
     241                var elist; 
     242                var nFills = this.fillStyles.length; 
     243 
     244                this.fillLoops = []; 
     245                for (fi = 1;fi <= nFills;fi++) 
     246                { 
     247                        var collected_edges = []; 
     248                        elist = this.rightFillEdges[fi]; 
     249                        if (elist) { 
     250                                len = elist.length; 
     251                                for (i = 0;i < len;i++) 
     252                                        collected_edges.push(elist[i].tearOff(false, this.te_id++)); 
     253                        } 
     254 
     255                        elist = this.leftFillEdges[fi]; 
     256                        if (elist) { 
     257                                len = elist.length; 
     258                                for (i = 0;i < len;i++) 
     259                                        collected_edges.push(elist[i].tearOff(true, this.te_id++)); 
     260 
     261                        } 
     262                         
     263                        var lps = this.makeLoop(collected_edges, fi); 
     264                        if (lps.length > 0) { 
     265                                this.fillLoops.push({fill_index: fi, loops: lps}); 
     266                        } 
     267                } 
     268                 
     269                /* clear */ 
     270                this.leftFillEdges  = {}; 
     271                this.rightFillEdges = {}; 
     272        }, 
     273         
     274        makeLoop: function(elist, fi) { 
     275                var pmap = {}, loops = []; 
     276                var i, len, te, k; 
     277 
     278                len = elist.length; 
     279                for (i = 0;i < len;i++) 
     280                { 
     281                        te = elist[i]; 
     282                        k = this.make_key(te.getTx1(), te.getTy1()); 
     283                        if (!pmap[k]) pmap[k] = []; 
     284                        pmap[k].push(te); 
     285                } 
     286                 
     287                var parts, start_k, fst, nxt; 
     288                len = elist.length; 
     289                for (i = 0;i < len;i++) 
     290                { 
     291                        te = elist[i]; 
     292                        if (te.has_loop) 
     293                                continue; 
     294                 
     295                        // assume that this is the first part 
     296                        te.has_loop = true; 
     297                        parts = [te]; 
     298                        fst = te; 
     299                        var usedmap = {}; 
     300                        for (start_k = this.make_key( te.getTx1(), te.getTy1() );;) 
     301                        { 
     302                                k = this.make_key( te.getTx2(), te.getTy2() ); 
     303                                if (k == start_k) // looped! 
     304                                { 
     305                                        this.use_all(parts); 
     306                                        loops.push(parts); 
     307                                        break; 
     308                                } 
     309                                 
     310                                if (!pmap[k] || pmap[k].length == 0) break; // no next edge 
     311                                 
     312                                nxt = this.seq_next(pmap[k], elist[i+1], usedmap); 
     313                                if (!nxt) break; 
     314                                 
     315                                te = nxt; 
     316                                usedmap[te.eid] = true; 
     317                                parts.push(te); 
     318                        } 
     319                } 
     320 
     321                return loops; 
     322        }, 
     323         
     324 
     325        seq_next: function(list, t, usedmap) { 
     326                if (!t) return null; 
     327 
     328                var i, len = list.length; 
     329                for (i = 0;i < len;i++) 
     330                { 
     331                        if (list[i] == t && !list[i].has_loop) 
     332                        { 
     333                                var ret = list[i]; 
     334                                list.splice(i, 1); 
     335 
     336                                return ret; 
     337                        } 
     338                } 
     339 
     340                for (i = 0;i < len;i++) 
     341                { 
     342                        if (!list[i].has_loop && !usedmap[list[i].eid]) 
     343                                return list[i]; 
     344                } 
     345 
     346                return null; 
     347        }, 
     348         
     349        use_all: function(a) { 
     350                var i, len = a.length; 
     351                for (i = 0;i < len;i++) 
     352                        a[i].has_loop = true; 
     353        }, 
     354         
     355        make_key: function(x, y) { 
     356                return (x+50000)*100000+y; 
     357        }, 
     358         
    184359        _dump: function() { 
    185                  
     360                var lines = [], fi; 
     361                var parts = []; 
     362                 
     363                lines.push("===== LEFT ====="); 
     364                for (fi in this.leftFillEdges) 
     365                        parts.push(fi+"("+(this.leftFillEdges[fi].length)+")"); 
     366                         
     367                lines.push( parts.join(' ') ); 
     368 
     369                parts = []; 
     370                lines.push("===== RIGHT ====="); 
     371                for (fi in this.rightFillEdges) 
     372                        parts.push(fi+"("+(this.rightFillEdges[fi].length)+")"); 
     373                         
     374                lines.push( parts.join(' ') ); 
     375                 
     376                console.log(lines.join("\n")); 
    186377        } 
    187378} 
     
    194385        /* tx1, ty1, tx2, ty2, txC, tyC */ 
    195386} 
     387 
     388JSplash.EdgePart.prototype = { 
     389        tearOff: function(rev, eid) { 
     390                return new JSplash.TearedEdge(this, rev, eid); 
     391        }, 
     392} 
     393 
     394 
     395JSplash.TearedEdge = function(org, rev, eid) 
     396{ 
     397        this.rev = rev; 
     398        this.original = org; 
     399        this.has_loop = false; 
     400        this.px1 = null; 
     401        this.eid = eid; 
     402} 
     403 
     404JSplash.TearedEdge.prototype = { 
     405        getTx1: function() { 
     406                return this.rev ? this.original.tx2 : this.original.tx1; 
     407        }, 
     408 
     409        getTy1: function() { 
     410                return this.rev ? this.original.ty2 : this.original.ty1; 
     411        }, 
     412 
     413 
     414        getTx2: function() { 
     415                return this.rev ? this.original.tx1 : this.original.tx2; 
     416        }, 
     417 
     418        getTy2: function() { 
     419                return this.rev ? this.original.ty1 : this.original.ty2; 
     420        }, 
     421         
     422        calcPx: function() { 
     423                if (this.px1 == null) { 
     424                        this.px1 = JSplash.$twips(this.getTx1()); 
     425                        this.py1 = JSplash.$twips(this.getTy1()); 
     426                        this.px2 = JSplash.$twips(this.getTx2()); 
     427                        this.py2 = JSplash.$twips(this.getTy2()); 
     428                        this.pxC = JSplash.$twips(this.original.txC); 
     429                        this.pyC = JSplash.$twips(this.original.tyC); 
     430                } 
     431        } 
     432} 
     433 
     434 
    196435 
    197436JSplash.EdgePart.prototype.calcPx = function() {