Permalink
Browse files

Renamed some public methods in order to chain more naturally

  • Loading branch information...
1 parent 5c2faa9 commit 56e0273d557169af9230cf03db7d64ef96697ffc Tobias Schneider committed Feb 20, 2010
Showing with 64 additions and 81 deletions.
  1. +33 −48 src/movie.js
  2. +23 −20 src/parser.js
  3. +1 −1 src/stream.js
  4. +7 −12 src/svg_renderer.js
View
@@ -35,8 +35,8 @@
var d = t._dictionary = {},
l = t._timeline = [];
t._framesLoaded = 0;
- t._isPlaying = false;
- t._currFrame = -1;
+ t.isPlaying = false;
+ t.currentFrame = -1;
new Gordon.Parser(xhr.responseText, function(obj){
switch(obj.type){
case "header":
@@ -50,6 +50,7 @@
}
var r = t.renderer = t.renderer || Gordon.SvgRenderer;
t._renderer = new r(t.width, t.height, frmWidth, frmHeight, t.quality, t.scale, t.bgcolor);
+ t.totalFrames = t._frameCount;
break;
case "frame":
var bgcolor = obj.bgcolor;
@@ -60,21 +61,21 @@
var action = obj.action;
if(action){ eval("obj.action = function(){ (" + action + "(t)); }"); }
l.push(obj);
- var f = ++t._framesLoaded;
- t.onprogress(t.percentLoaded());
- if(f == 1){
+ var n = ++t._framesLoaded;
+ t.onprogress(~~((n * 100) / t.totalFrames));
+ if(n == 1){
if(t.id){
var stage = doc.getElementById(t.id);
stage.innerHTML = '';
- stage.appendChild(t._renderer.getNode());
+ stage.appendChild(t._renderer.node);
t._changeReadyState(s.INTERACTIVE);
}
if(t.autoplay){ t.play(); }
- else{ t.gotoFrame(0); }
- }else if(f == t._frameCount){ t._changeReadyState(s.COMPLETE); }
+ else{ t.goto(0); }
+ }else if(n == t.totalFrames){ t._changeReadyState(s.COMPLETE); }
break;
default:
- t._renderer.defineObject(obj);
+ t._renderer.define(obj);
d[obj.id] = obj;
}
});
@@ -88,42 +89,42 @@
play: function(){
var t = this,
- c = t._currFrame,
- timeout = 1100 / t._frameRate;
- t._isPlaying = true;
- if(c < t._frameCount - 1){
- if(t._framesLoaded >= c){ t.gotoFrame(c + 1); }
+ c = t.currentFrame,
+ timeout = 1000 / t._frameRate;
+ t.isPlaying = true;
+ if(c < t.totalFrames - 1){
+ if(t._framesLoaded >= c){ t.goto(c + 1); }
else{ timeout = 0; }
}else{
if(!t.loop){ return t.stop(); }
- else{ t.gotoFrame(0); }
+ else{ t.goto(0); }
}
setTimeout(function(){
- if(t._isPlaying){ t.play() };
+ if(t.isPlaying){ t.play() };
}, timeout);
return t;
},
- nextFrame: function(){
+ next: function(){
var t = this,
- c = t._currFrame;
- t.gotoFrame(c < t._frameCount - 1 ? c + 1 : 0);
+ c = t.currentFrame;
+ t.goto(c < t.totalFrames - 1 ? c + 1 : 0);
return t;
},
- gotoFrame: function gf(frameNum){
+ goto: function gf(frameNum){
var t = this;
if(gf.caller !== t.play){ t.stop(); }
- if(t._currFrame != frameNum){
- if(frameNum < t._currFrame){ t._currFrame = -1; }
- while(t._currFrame != frameNum){
- var frame = t._timeline[++t._currFrame],
+ if(t.currentFrame != frameNum){
+ if(frameNum < t.currentFrame){ t.currentFrame = -1; }
+ while(t.currentFrame != frameNum){
+ var frame = t._timeline[++t.currentFrame],
d = frame.displayList,
r = t._renderer;
for(var depth in d){
var character = d[depth];
- if(character){ r.placeCharacter(character); }
- else{ r.removeCharacter(depth); }
+ if(character){ r.place(character); }
+ else{ r.remove(depth); }
}
t.onenterframe(frameNum);
var action = frame.action;
@@ -134,38 +135,22 @@
},
stop: function(){
- this._isPlaying = false;
+ this.isPlaying = false;
return this;
},
- prevFrame: function(){
+ prev: function(){
var t = this,
- c = t._currFrame;
- t.gotoFrame(c > 0 ? c - 1 : t._frameCount - 1);
+ c = t.currentFrame;
+ t.goto(c > 0 ? c - 1 : t.totalFrames - 1);
return t;
},
- isPlaying: function(){
- return this._isPlaying;
- },
-
rewind: function(){
- this.gotoFrame(0);
+ this.goto(0);
return this;
},
- totalFrames: function(){
- return this._frameCount;
- },
-
- percentLoaded: function(){
- return Math.round((this._framesLoaded * 100) / this._frameCount);
- },
-
- currentFrame: function(){
- return this._currFrame;
- },
-
getURL: function(url, target){
var u = Gordon.urlTargets;
switch(target){
@@ -184,7 +169,7 @@
return this;
},
- toggleHighQuality: function thq(){
+ toggleQuality: function thq(){
var o = thq._orig,
t = this,
q = t.quality;
View
@@ -80,8 +80,8 @@
var id = s.readUI16(),
bounds = s.readRect(),
t = this,
- fillStyles = t._readFillStyleArray(),
- lineStyles = t._readLineStyleArray(),
+ fillStyles = t._readFillStyles(),
+ lineStyles = t._readLineStyles(),
numFillBits = s.readUB(4),
numLineBits = s.readUB(4),
segment = [],
@@ -122,7 +122,13 @@
}
x2 = Math.round(x2 * 100) / 100;
y2 = Math.round(y2 * 100) / 100;
- segment.push({i: i++, f: isFirst, x1: x1, y1: y1, cx: cx, cy: cy, x2: x2, y2: y2});
+ segment.push({
+ i: i++,
+ f: isFirst,
+ x1: x1, y1: y1,
+ cx: cx, cy: cy,
+ x2: x2, y2: y2
+ });
isFirst = false;
}else{
if(segment.length){
@@ -181,8 +187,8 @@
useSinglePath = false;
}
if(flags & c.NEW_STYLES){
- push.apply(fillStyles, t._readFillStyleArray());
- push.apply(lineStyles, t._readLineStyleArray());
+ push.apply(fillStyles, t._readFillStyles());
+ push.apply(lineStyles, t._readLineStyles());
numFillBits = s.readUB(4);
numLineBits = s.readUB(4);
fsOffset = fillStyles.length;
@@ -214,7 +220,7 @@
if(list){ push.apply(fillEdges, list); }
var edgeMap = {};
fillEdges.forEach(function(edge){
- var key = calcPointKey(edge.x1, edge.y1),
+ var key = calcPtKey(edge.x1, edge.y1),
list = edgeMap[key];
if(!list){ list = edgeMap[key] = []; }
list.push(edge);
@@ -225,12 +231,12 @@
var edge = fillEdges[j];
if(!edge.c){
var segment = [],
- firstKey = calcPointKey(edge.x1, edge.y1),
+ firstKey = calcPtKey(edge.x1, edge.y1),
usedMap = {};
do{
segment.push(edge);
usedMap[edge.i] = true;
- var key = calcPointKey(edge.x2, edge.y2);
+ var key = calcPtKey(edge.x2, edge.y2);
if(key == firstKey){
var k = segment.length;
while(k--){ segment[k].c = true; }
@@ -297,7 +303,7 @@
return t;
},
- _readFillStyleArray: function(){
+ _readFillStyles: function(){
var numStyles = s.readUI8();
if(0xff == numStyles){ numStyles = s.readUI16(); }
var styles = [],
@@ -349,7 +355,7 @@
return styles;
},
- _readLineStyleArray: function(){
+ _readLineStyles: function(){
var numStyles = s.readUI8();
if(0xff == numStyles){ numStyles = s.readUI16(); }
var styles = [],
@@ -479,10 +485,10 @@
stack.push("t.stop()");
break;
case a.NEXT_FRAME:
- stack.push("t.nextFrame()");
+ stack.push("t.next()");
break;
case a.PREVIOUS_FRAME:
- stack.push("t.prevFrame()");
+ stack.push("t.prev()");
break;
case a.GOTO_FRAME:
var frame = s.readUI16();
@@ -494,7 +500,7 @@
stack.push("t.getURL('" + url + "', '" + target + "')");
break;
case a.TOGGLE_QUALITY:
- stack.push("t.toggleHighQuality()");
+ stack.push("t.toggleQuality()");
break;
default:
s.seek(len);
@@ -731,12 +737,9 @@
return {
i: edge.i,
f: edge.f,
- x1: edge.x1,
- y1: edge.y1,
- cx: edge.cx,
- cy: edge.cy,
- x2: edge.x2,
- y2: edge.y2
+ x1: edge.x1, y1: edge.y1,
+ cx: edge.cx, cy: edge.cy,
+ x2: edge.x2, y2: edge.y2
};
}
@@ -763,7 +766,7 @@
};
}
- function calcPointKey(x, y){
+ function calcPtKey(x, y){
return (x + 50000) * 100000 + y;
}
View
@@ -271,7 +271,7 @@ Gordon.Stream.prototype = {
return this._readCxform();
},
- readCxformWithAlpha: function(){
+ readCxformA: function(){
return this._readCxform(true);
},
View
@@ -16,7 +16,7 @@
t.quality = quality || Gordon.qualityValues.HIGH;
t.scale = scale || Gordon.scaleValues.SHOW_ALL;
t.bgcolor = bgcolor;
- var n = t._node = t._createElement("svg");
+ var n = t.node = t._createElement("svg");
attr = {
width: width,
height: height
@@ -56,8 +56,7 @@
switch(quality){
case q.LOW:
var attr = {
- shape_rendering: "crispEdges",
- image_rendering: "optimizeSpeed",
+ shape_rendering: "crispEdges", image_rendering: "optimizeSpeed",
text_rendering: "optimizeSpeed",
color_rendering: "optimizeSpeed"
}
@@ -101,20 +100,16 @@
return t;
},
- getNode: function(){
- return this._node;
- },
-
setBgcolor: function(rgb){
var t = this;
if(!t.bgcolor){
- t._node.style.background = color2string(rgb);
+ t.node.style.background = color2string(rgb);
t.bgcolor = rgb;
}
return t;
},
- defineObject: function(obj){
+ define: function(obj){
var type = obj.type,
t = this,
node = null,
@@ -327,15 +322,15 @@
return node;
},
- placeCharacter: function(character){
+ place: function(character){
var depth = character.depth,
t = this,
d = t._displayList,
replace = d[depth];
if(!replace || replace.character !== character){
var node = t._buildCharacter(character),
s = t._stage;
- if(replace && replace.character !== character){ t.removeCharacter(depth); }
+ if(replace && replace.character !== character){ t.remove(depth); }
if(1 == depth){ s.insertBefore(node, s.firstChild); }
else{
var nextDepth = 0;
@@ -423,7 +418,7 @@
return node;
},
- removeCharacter: function(depth){
+ remove: function(depth){
var d = this._displayList,
node = d[depth].node;
node.parentNode.removeChild(node);

0 comments on commit 56e0273

Please sign in to comment.