チェンジセット 1535

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

0.4.7: improved shape renderer and executor

ファイル:

凡例:

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

    r1526 r1535  
    111111                        this.g.style.display = "none"; 
    112112                        this.sleeping = true; 
     113                         
     114                        for (d in this.depthMap) 
     115                                this.depthMap[d].sleep(); 
    113116                } 
    114117                this.destroyProxy(); 
  • ruby/jsplash/trunk/client2/jsplash/player.js

    r1526 r1535  
    5959 
    6060        onTopMouseMove: function(svg, e) { 
     61                 
    6162                var x, y; 
    62                 if (e.offsetX) { 
     63                if (window.opera) 
     64                { 
     65                 
     66                        var elem = Event.element(e); 
     67                        var ro = Position.realOffset(this.svg); 
     68                        var co = Position.cumulativeOffset(this.svg); 
     69                        x = e.clientX - co.left + ro.left; 
     70                        y = e.clientY - co.top  + ro.top; 
     71                } 
     72                else if (e.offsetX) { 
    6373                        x = e.offsetX; 
    6474                        y = e.offsetY; 
     
    7080 
    7181                this.stage.setMousePos(x, y); 
     82                 
    7283        }, 
    7384         
  • ruby/jsplash/trunk/client2/jsplash/shaperenderer.js

    r1526 r1535  
    1010                this.edgeList = []; 
    1111                this.displayList = null; 
     12 
     13                this.pendingEdges = null; 
    1214                 
    1315                this.fillLoops = null; 
     
    1719                this.pathCache = null; 
    1820                this.do_cache = false; 
     21                 
     22                // At first, we have to check if this shape is in 'single-side mode' 
     23                // In single-side mode, we can render this shape in manner of 
     24                // standard vector renderer - e.g. cairo, flash.graphics.* APIs 
     25                 
     26                // The other mode is 'two-side mode'. This is more complex so we have to 
     27                // analyze and rebuild shape data before rendering. 
     28         
     29                this.single_side = this.checkSingleSideMode(); 
     30                if (this.single_side) 
     31                { 
     32                        this.defineShape.shape[this.defineShape.shape.length-1].term = true; 
     33                        //console.warn(this.shape_id); 
     34                } 
     35        }, 
     36         
     37        checkSingleSideMode: function() { 
     38                // is single-side mode? 
     39         
     40                // more than 1 style -> NO 
     41                if (this.fillStyles.length > 1) 
     42                        return false; 
     43                         
     44                var r; 
     45                var fill_flag = 0; 
     46                var records = this.defineShape.shape; 
     47                var len = records.length; 
     48                for (var i = 0;i < len;i++) { 
     49                        r = records[i]; 
     50                        if (r.schange) return false; // has new styles -> NO 
     51                        if (r.f0 != undefined || r.f1 != undefined) { 
     52                                if (fill_flag != 0) // more than 1 style change -> NO 
     53                                        return false; 
     54                                         
     55                                if (r.f0 != undefined) 
     56                                        fill_flag |= 0x1; 
     57                                         
     58                                if (r.f1 != undefined) 
     59                                        fill_flag |= 0x2; 
     60                                         
     61                                if (fill_flag == 0x3) // both side fill -> NO 
     62                                        return false; 
     63                        } 
     64                } 
     65 
     66                // Yes, this is. 
     67                return true; 
    1968        }, 
    2069         
     
    77126                return fid; 
    78127        }, 
     128         
     129        buildEdgeIndex_S: function() { 
     130                this.displayList = []; 
     131 
     132                var cur_rightFill = 0; 
     133                var cur_leftFill  = 0; 
     134                var cur_lineStyle = 0; 
     135 
     136                var records = this.defineShape.shape; 
     137                var len = records.length, llen; 
     138                var rcd; 
     139 
     140                var _tx = 0; 
     141                var _ty = 0; 
     142                var _first_seg = true; 
     143                var order_index = 0; 
     144                var i, k; 
     145                var loops = []; 
     146                this.pendingEdges = null; 
     147                var edge_starts = []; 
     148                 
     149                for (i = 0;i < len;i++) { 
     150                        rcd = records[i]; 
     151                         
     152                        if (rcd.t == 0) { 
     153                                if (rcd.f0 != undefined || rcd.f1 != undefined || rcd.term) { 
     154                                        if (this.pendingEdges) 
     155                                        { 
     156                                                llen = this.pendingEdges.length; 
     157                                                for (k = 0;k < llen;k++) 
     158                                                        this.pendingEdges[k].self_tearOff(); 
     159                                                 
     160                                                loops.push(this.pendingEdges); 
     161                                        } 
     162                                         
     163                                        this.pendingEdges = []; 
     164                                } 
     165 
     166                                if (!rcd.term) 
     167                                { 
     168                                        edge_starts.push(this.edgeList.length); 
     169                                        _first_seg = true; 
     170                                } 
     171                                 
     172                                /* ShapeSetup */ 
     173                                if (rcd.p) { 
     174                                        _tx = rcd.p[0]; 
     175                                        _ty = rcd.p[1]; 
     176                                } 
     177                                 
     178                                if (rcd.f0 != undefined) cur_leftFill  = rcd.f0; 
     179                                if (rcd.f1 != undefined) cur_rightFill = rcd.f1; 
     180                                if (rcd.ls != undefined) cur_lineStyle = rcd.ls; 
     181                        } 
     182                        else { 
     183                                var E; 
     184                                if (rcd.t == 2) 
     185                                { 
     186                                        x1 = _tx; 
     187                                        y1 = _ty; 
     188                                         
     189                                        x2 = _tx + rcd.p[0]; 
     190                                        y2 = _ty + rcd.p[1]; 
     191                                         
     192                                        _tx = x2 + rcd.p[2]; 
     193                                        _ty = y2 + rcd.p[3]; 
     194                                 
     195                                        E = this.addCurve(order_index++, _first_seg, cur_lineStyle, x1, y1, x2, y2, _tx, _ty); 
     196                                } 
     197                                else 
     198                                { 
     199                                        x1 = _tx; 
     200                                        y1 = _ty; 
     201                                         
     202                                        _tx += rcd.p[0]; 
     203                                        _ty += rcd.p[1]; 
     204                                 
     205                                        E = this.addLine(order_index++, _first_seg, cur_lineStyle, x1, y1, _tx, _ty); 
     206                                } 
     207                                 
     208                                _first_seg = false; 
     209                        }                        
     210                } 
     211                 
     212                 
     213                var di; 
     214                di = new JSplash.DisplayListEntry(1, loops, 0); 
     215                di.fill_index = cur_rightFill || cur_leftFill; 
     216                this.displayList.push( di ); 
     217                 
     218                len = edge_starts.length; 
     219                for (i = 0;i < len;i++) { 
     220                        var si = edge_starts[i]; 
     221                        if (this.edgeList[si].lineStyle) { 
     222                                this.displayList.push( new JSplash.DisplayListEntry(0, si, 1) ); 
     223                        } 
     224                } 
     225        }, 
    79226 
    80227        buildEdgeIndex: function() { 
     228                if (this.single_side) 
     229                        return this.buildEdgeIndex_S(); 
    81230                var records = this.defineShape.shape; 
    82231                var len = records.length, slen, k, ls; 
     
    101250                var fs_count = this.fillStyles.length; 
    102251                 
     252                var prev_start_edge = null; 
     253                 
    103254                if (JSplash.WireFrameMode) 
    104255                        this.edgeStyles = [{w:20, rgb:'000'}]; 
     256                         
     257                this.pendingEdges = null; 
    105258 
    106259                for (var i = 0;i < len;i++) { 
     
    109262                        if (rcd.t == 0) { 
    110263                                _first_seg = true; 
     264                                 
     265                                this.registerPendingEdges(cur_leftFill, cur_rightFill); 
     266                                this.pendingEdges = []; 
    111267                         
    112268                                /* ShapeSetup */ 
     
    149305                        } 
    150306                        else { 
     307                                var E; 
    151308                                if (rcd.t == 2) 
    152309                                { 
     
    160317                                        _ty = y2 + rcd.p[3]; 
    161318                                 
    162                                         this.addCurve(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,  x1, y1, x2, y2, _tx, _ty); 
     319                                        E = this.addCurve(order_index++, _first_seg, cur_lineStyle, x1, y1, x2, y2, _tx, _ty); 
    163320                                } 
    164321                                else 
     
    170327                                        _ty += rcd.p[1]; 
    171328                                 
    172                                         this.addLine(order_index++, _first_seg, cur_lineStyle, cur_leftFill, cur_rightFill,   x1, y1, _tx, _ty); 
    173                                 } 
     329                                        E = this.addLine(order_index++, _first_seg, cur_lineStyle, x1, y1, _tx, _ty); 
     330                                } 
     331                                 
     332                                if (_first_seg) 
     333                                        prev_start_edge = E; 
    174334                                 
    175335                                _first_seg = false; 
     
    180340        }, 
    181341         
    182         addLine: function(oi, fst, ls, fL, fR, x1, y1, x2, y2) { 
     342        addLine: function(oi, fst, ls, x1, y1, x2, y2) { 
    183343                var E = new JSplash.EdgePart(false, ls, fst); 
    184344                E.oi = oi; 
     
    188348                E.ty2 = y2; 
    189349                 
    190                 this.addEdge(fL, fR, E); 
    191         }, 
    192          
    193         addCurve: function(oi, fst, ls, fL, fR, x1, y1, cx, cy, x2, y2) { 
     350                this.addEdge(E); 
     351                return E; 
     352        }, 
     353         
     354        addCurve: function(oi, fst, ls, x1, y1, cx, cy, x2, y2) { 
    194355                var E = new JSplash.EdgePart(true, ls, fst); 
    195356                E.oi = oi; 
     
    201362                E.tyC = cy; 
    202363 
    203                 this.addEdge(fL, fR, E); 
    204         }, 
    205          
    206         addEdge: function(fL, fR, E) { 
     364                this.addEdge(E); 
     365                return E; 
     366        }, 
     367         
     368        addEdge: function(E) { 
    207369                var list; 
    208370                 
    209371                this.edgeList.push(E); 
    210                  
    211                 if (fL != 0) { 
    212                         if (!this.leftFillEdges[fL]) 
    213                                 this.leftFillEdges[fL] = []; 
    214                         list = this.leftFillEdges[fL]; 
    215                         list.push(E); 
    216                 } 
    217  
    218                 if (fR != 0) { 
    219                         if (!this.rightFillEdges[fR]) 
    220                                 this.rightFillEdges[fR] = []; 
    221                         list = this.rightFillEdges[fR]; 
    222                         list.push(E); 
     372                if (this.pendingEdges) 
     373                        this.pendingEdges.push(E); 
     374        }, 
     375         
     376        registerPendingEdges: function(fL, fR) { 
     377                var edges = this.pendingEdges; 
     378                if (!edges) return false; 
     379                 
     380                var len = edges.length; 
     381                var E; 
     382         
     383                for (i = 0;i < len;i++) { 
     384                        E = edges[i]; 
     385                 
     386                        if (fL != 0) { 
     387                                if (!this.leftFillEdges[fL]) 
     388                                        this.leftFillEdges[fL] = []; 
     389                                list = this.leftFillEdges[fL]; 
     390                                list.push(E); 
     391                        } 
     392 
     393                        if (fR != 0) { 
     394                                if (!this.rightFillEdges[fR]) 
     395                                        this.rightFillEdges[fR] = []; 
     396                                list = this.rightFillEdges[fR]; 
     397                                list.push(E); 
     398                        } 
    223399                } 
    224400        }, 
     
    282458                for (var i = 0;i < len;i++) { 
    283459                        di = list[i]; 
     460                        di_nxt = list[i+1]; 
    284461                        if (di.type == 0) 
    285462                                this.buildEdges(g, di.obj, -1); 
     
    320497                var len = list.length; 
    321498                var commands = [], lp, k, llen, E; 
     499                 
     500                var last_x = null; 
     501                var last_y = null; 
     502                 
    322503                for (var i = 0;i < len;i++) { 
    323504                        lp = list[i]; 
    324505                        llen = lp.length; 
    325506                         
    326                         if (i) { 
     507                        if (i && !this.single_side) { 
    327508                                commands.push('Z'); 
    328509                        } 
     
    333514                                if (k==0) 
    334515                                        commands.push('M '+E.px1+','+E.py1); 
     516                                else if (this.single_side && E.isFirst && (E.original.tx1 != last_x || E.original.ty1 != last_y)) 
     517                                        commands.push('M '+E.px1+','+E.py1); 
    335518                                         
    336519                                if (E.original.curved) { 
     
    340523                                else 
    341524                                        commands.push('L ' + E.px2 +','+ E.py2); 
    342                         } 
    343                 } 
    344                  
     525                                 
     526                                last_x = E.original.tx2; 
     527                                last_y = E.original.ty2; 
     528                        } 
     529                } 
     530 
    345531                commands.push('Z'); 
    346532 
    347533                attrs = {d: commands.join(' '), fill: style_str}; 
     534                 
     535                if (this.single_side) 
     536                        attrs["fill-rule"] = "evenodd"; 
     537                 
    348538                if (style.a) { 
    349539                        attrs["fill-opacity"] = style.a; 
     
    401591                        oneshot = 1; 
    402592                } 
    403                  
     593 
    404594                for (var i = edge_start;i < edge_end;i++) { 
    405595                        E = edges[i]; 
    406596                        E.calcPx(); 
    407                          
    408597                        if (E.isFirst) { 
    409598                                if (i) 
     
    432621                                        curAlpha =       this.edgeStyles[ E.lineStyle-1 ].a; 
    433622                                } 
    434                                 
     623         
    435624                                if (oneshot == 1) 
    436625                                        oneshot = 2; 
     
    448637                                } 
    449638                        } 
    450                 } 
     639 
     640                } 
     641 
    451642 
    452643                if (commands.length > 1) 
     
    626817} 
    627818 
     819JSplash.MorphShapeRenderer = Class.create(); 
     820JSplash.MorphShapeRenderer.prototype = { 
     821        initialize: function(source) { 
     822                this.derived_shape = {}; 
     823 
     824                this.calcShape(source.shape1, source.shape2); 
     825 
     826                this.derived_shape.id    = source.id; 
     827                this.derived_shape.shape = source.shape2; 
     828                this.derived_shape.fill_styles = this.calcFillStyles(source.fill_styles); 
     829                this.derived_shape.line_styles = this.calcLineStyles(source.line_styles); 
     830 
     831                this.inner_renderer = new JSplash.ShapeRenderer(this.derived_shape); 
     832        }, 
     833 
     834        calcShape: function(s1, s2) { 
     835                var i, len = s1.length; 
     836                var r1, r2; 
     837                for (i = 0;i < len;i++) { 
     838                        r1 = s1[i]; 
     839                        r2 = s2[i]; 
     840 
     841                        if (r1.ls != undefined) r2.ls = r1.ls; 
     842                        if (r1.f0 != undefined) r2.f0 = r1.f0; 
     843                        if (r1.f1 != undefined) r2.f1 = r1.f1; 
     844                } 
     845        }, 
     846 
     847        calcFillStyles: function(src) { 
     848                var ret = []; 
     849                var len, i; 
     850 
     851                len = src.length; 
     852                for (i = 0;i < len;i++) { 
     853                        var s1 = src[i][0]; 
     854                        var s2 = src[i][1]; 
     855                        ret.push(s2); 
     856                } 
     857 
     858                return ret; 
     859        }, 
     860 
     861        calcLineStyles: function(src) { 
     862                var ret = []; 
     863                var len, i; 
     864 
     865                len = src.length; 
     866                for (i = 0;i < len;i++) { 
     867                        var s1 = src[i][0]; 
     868                        var s2 = src[i][1]; 
     869                        ret.push(s2); 
     870                } 
     871 
     872                return ret; 
     873        }, 
     874 
     875        buildEdgeIndex: function() { 
     876                return this.inner_renderer.buildEdgeIndex(); 
     877        }, 
     878 
     879        buildSVG: function(g) { 
     880                return this.inner_renderer.buildSVG(g); 
     881        } 
     882} 
     883 
    628884JSplash.DisplayListEntry = function(t, obj, i) { 
    629885        this.index = i; 
     
    646902                return new JSplash.TearedEdge(this, rev, eid); 
    647903        }, 
     904         
     905        self_tearOff: function() { 
     906                this.original = this; 
     907        } 
    648908} 
    649909