Skip to content

Commit

Permalink
Merge branch 'master' into interactive-attr
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG
  • Loading branch information
David Aurelio committed Nov 6, 2012
2 parents 8f7c1e6 + 4ac85d2 commit d863cc3
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 44 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
v0.4.2
-------------------
* Add support for an `interactive` attribute on all DisplayObjects which allows
pointer-events to be received (true) or to pass through (false)
pointer-events to be received (true) or to pass through (false)
* Setting an attribute to the actual value won't trigger a render message.

v0.4.1 / 2012-10-26
-------------------
Expand All @@ -15,7 +16,7 @@ v0.4.1 / 2012-10-26
* Fixed examples to be in line with the documentation.
* Fix out-of-range hsl color values
* Fix out-of-range alpha values when parsing rgba() strings
* Add additional method signature for new Matrix([a, b, c, d, tx, ty])
* Add additional method signature for new Matrix([a, b, c, d, tx, ty])
* Add Matrix.fromString() method to create new Matrix instance from a string.
* Rename DisplayObject#getComputed to DisplayObject#getBoundingBox and improve
implementation for calculating the bounding box of paths
Expand Down
12 changes: 11 additions & 1 deletion src/point.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ define(function() {
* @returns {Point} The current Point instance
*/
proto.normalize = function(length) {
var curlen = sqrt(this.x * this.x + this.y * this.y);
var fact = length / this.length;
this.x = this.x * fact;
this.y = this.y * fact;
Expand Down Expand Up @@ -160,6 +159,17 @@ define(function() {
return sqrt(hside * hside + vside * vside);
};


/**
* Returns the angle in radians of the slope between pt1 and pt2
*
* @param {Point} toPoint
* @returns {Number} angle
*/
proto.angle = function(toPoint) {
return Math.atan2(this.y - toPoint.y, this.x - toPoint.x);
};

// static methods

/**
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/svg/svg_event_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ define([
event = cloneBasicEvent(event);
this.emit('userevent', event, trueTargetId);
}
if (!touchData.touchMoveHappened) {
// If the touch hasn't moved then it is a click:
if (!isMulti && !touchData.touchMoveHappened) {
// If the touch hasn't moved then it is a click (only for the first finger):
event = cloneBasicEvent(event);
event.type = 'click';
this.emit('userevent', event, targetId);
Expand Down
14 changes: 7 additions & 7 deletions src/runner/animation/keyframe_animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ define([
return this;
},

/**
* Event listener for the clock's tick event, delegates to _step()
/**
* Event listener for the clock's tick event, delegates to step()
* @private
*/
_onStep: function(_, frameNumber, timelineIsFinished) {
Expand All @@ -186,7 +186,7 @@ define([
this.frame + ((frameNumber - this.prevFrame) || 1)
) : this.frame + 1;

this._step(frame / duration);
this.step(frame / duration);

if (
(this.isTimelineBound && timelineIsFinished) ||
Expand All @@ -202,16 +202,16 @@ define([
}
return;
}

this.prevFrame = frameNumber;
},

/**
/**
* Runs a single step of the keyframe-animation, setting changed values
* on their respective subjects
* @private
*/
_step: function(progress) {
step: function(progress) {

var realProgress = progress;

Expand All @@ -227,7 +227,7 @@ define([
// assume that we can continue with progress > 1
if (phaseProgress > 1 && this.currentTweenIndex + 1 < tweensLength) {
this.currentTweenIndex += 1;
return this._step(realProgress);
return this.step(realProgress);
}

var subjects = this.subjects;
Expand Down
44 changes: 26 additions & 18 deletions src/runner/display_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,31 @@ define([
}

function setX(x) {
var s = this._scaleX;
if (s === 1) {
this._matrix.tx = x;
} else {
this._matrix.tx += x - this.matrix.tx;
if (isfinite(x)) {
var s = this._scaleX;
if (s === 1) {
this._matrix.tx = x;
} else {
this._matrix.tx += x - this.matrix.tx;
}
this._owner._mutatedAttributes.matrix = true;
}
this._owner._mutatedAttributes.matrix = true;
}

function getY() {
return this.matrix.ty;
}

function setY(y) {
var s = this._scaleY;
if (s === 1) {
this._matrix.ty = y;
} else {
this._matrix.ty += y - this.matrix.ty;
if (isfinite(y)) {
var s = this._scaleY;
if (s === 1) {
this._matrix.ty = y;
} else {
this._matrix.ty += y - this.matrix.ty;
}
this._owner._mutatedAttributes.matrix = true;
}
this._owner._mutatedAttributes.matrix = true;
}

function getScaleX() {
Expand Down Expand Up @@ -543,6 +547,7 @@ define([
attr: function(attr, value) {
var copy,
name,
hasChange = false,
attributes = this._attributes;

switch (arguments.length) {
Expand All @@ -561,21 +566,24 @@ define([
attributes[attr] : void 0;
}
for (name in attr) {
if (name in attributes && name.charAt(0) != '_') {
attributes[name] = attr[name];
this._mutatedAttributes[name] = true;
value = attr[name]; // value parameter is unused in this branch
if (name in attributes && name.charAt(0) != '_' && attributes[name] !== value) {
attributes[name] = value;
hasChange = this._mutatedAttributes[name] = true;
}
}
break;

case 2: // set at single attribute
if (attr in attributes && attr.charAt(0) != '_') {
if (attr in attributes && attr.charAt(0) != '_' && attributes[attr] !== value) {
attributes[attr] = value;
this._mutatedAttributes[attr] = true;
hasChange = this._mutatedAttributes[attr] = true;
}
break;
}
this.markUpdate();
if (hasChange) {
this.markUpdate();
}
return this;
},

Expand Down
4 changes: 3 additions & 1 deletion src/runner/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ define([

movie = movies[i];
if (movie) {
if (movie.isPlaying) {
moviesToIncrement.push(movie);
}
movie.emitFrame();
moviesToIncrement.push(movie);
}

i += 1;
Expand Down
9 changes: 4 additions & 5 deletions src/runner/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ define([
* Increments the frame
*/
incrementFrame: function() {
if (this.isPlaying) {
// If length if not defined, we we assume an infinite length.
var length = this._length == null ? Infinity : this._length;
this.currentFrame = (this.currentFrame + 1) % length || 0;
}
// If length if not defined, we we assume an infinite length.
var length = this._length == null ? Infinity : this._length;
this.currentFrame = (this.currentFrame + 1) % length || 0;
return this;
},

/**
Expand Down
12 changes: 6 additions & 6 deletions test/animation/keyframe_animation-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ define([
}, { subjects: subject });
// Regardless of progress passed, our custom easing function always
// returns .5, meaning that y should always be half way between 0 and -20
animation._step(0);
animation.step(0);
expect(subject.attr().y).toBe(-10);
animation._step(1);
animation.step(1);
expect(subject.attr().y).toBe(-10);
animation._step(.8);
animation.step(.8);
expect(subject.attr().y).toBe(-10);

var subject = wrappedSubject({ y: 0 });
Expand All @@ -107,11 +107,11 @@ define([
}, { subjects: subject });
// Regardless of progress passed, our custom easing function always
// returns .5, meaning that y should always be half way between 0 and -20
animation._step(0);
animation.step(0);
expect(subject.attr().y).toBe(10);
animation._step(1);
animation.step(1);
expect(subject.attr().y).toBe(60);
animation._step(.8);
animation.step(.8);
expect(subject.attr().y).toBe(50);
});

Expand Down
17 changes: 15 additions & 2 deletions test/media_display_object-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@ require([
expect(a.play()).toBe(a);
});

it('play(time) sends `time` to the renderer', function() {
var a = new MediaDisplayObject();
var time = 2; // cannot be 0, that's the initial value
a.play(time);
expect(a.composeRenderMessage().attributes.time).toBe(time);
});

it('play(undefined) does not send `time` to the renderer', function() {
var a = new MediaDisplayObject();
a.play(0);
expect(a.composeRenderMessage().attributes.time).toBe(0);
a.play();
expect(a.composeRenderMessage().attributes.time).not.toBeDefined();
});

it('should send `time` to the renderer for `play(0)`', function() {
var a = new MediaDisplayObject();
a.attr('time', 2); // needs to be different from 0;

a.play(0);
expect(a.composeRenderMessage().attributes.time).toBe(0);
});

it('Can play(time)', function() {
var a = new MediaDisplayObject();
expect(a.attr('playing')).toBe(false);
Expand Down
11 changes: 11 additions & 0 deletions test/point-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ define([
});
});

describe('angle', function() {

it('Returns the radians between two points', function() {
var a = new Point(0, 0),
b = new Point(180, 180),
radians = Math.atan2(0 - 180, 0 - 180);
expect(a.angle(b)).toBe(radians);
});

});

// Linear Interpolation between two points a and b
describe('lerp', function() {
it('it is a class method', function() {
Expand Down

0 comments on commit d863cc3

Please sign in to comment.