Skip to content

Commit

Permalink
better touch experience
Browse files Browse the repository at this point in the history
updated BVTouchable to fancier version
TKAdjustableNumber shows help text on click in addition to rollover
  • Loading branch information
worrydream committed Jun 15, 2011
1 parent 78e2bf3 commit c1e289a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
56 changes: 41 additions & 15 deletions TangleKit/BVTouchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var BVTouchable = this.BVTouchable = new Class ({
this.setTouchable(true);
},


//----------------------------------------------------------------------------------
//
// touches
Expand Down Expand Up @@ -50,7 +51,6 @@ var BVTouchable = this.BVTouchable = new Class ({
touchDidGoDown: function (touches) { this.delegate.touchDidGoDown(touches); },
touchDidMove: function (touches) { this.delegate.touchDidMove(touches); },
touchDidGoUp: function (touches) { this.delegate.touchDidGoUp(touches); },


_mouseDown: function (event) {
event.stop();
Expand All @@ -65,14 +65,13 @@ var BVTouchable = this.BVTouchable = new Class ({

_mouseMove: function (event) {
event.stop();
this.touches.updateWithEvent(event);
this.touches._updateWithEvent(event);
this.touchDidMove(this.touches);
},

_mouseUp: function (event) {
event.stop();
this.touches.updateWithEvent(event);
this.touches.count = 0;
this.touches._goUpWithEvent(event);
this.touchDidGoUp(this.touches);

delete this.touches;
Expand Down Expand Up @@ -100,15 +99,15 @@ var BVTouchable = this.BVTouchable = new Class ({
event.stop();
if (!this.touches) { return; }

this.touches.updateWithEvent(event);
this.touches._updateWithEvent(event);
this.touchDidMove(this.touches);
},

_touchEnd: function (event) {
event.stop();
if (!this.touches) { return; }

this.touches.count = 0;
this.touches._goUpWithEvent(event);
this.touchDidGoUp(this.touches);

delete this.touches;
Expand Down Expand Up @@ -137,20 +136,47 @@ var BVTouches = this.BVTouches = new Class({
this.globalPoint = { x:event.page.x, y:-event.page.y };
this.translation = { x:0, y:0 };
this.deltaTranslation = { x:0, y:0 };
this.velocity = { x:0, y:0 };
this.count = 1;
this.event = event;
this.timestamp = event.event.timeStamp;
this.downTimestamp = this.timestamp;
},

updateWithEvent: function (event) {
var dx = event.page.x - this.globalPoint.x; // todo, transform to local coordinate space?
var dy = -event.page.y - this.globalPoint.y;
this.translation.x += dx;
this.translation.y += dy;
this.deltaTranslation.x += dx;
this.deltaTranslation.y += dy;
this.globalPoint.x = event.page.x;
this.globalPoint.y = -event.page.y;
_updateWithEvent: function (event, isRemoving) {
this.event = event;
if (!isRemoving) {
var dx = event.page.x - this.globalPoint.x; // todo, transform to local coordinate space?
var dy = -event.page.y - this.globalPoint.y;
this.translation.x += dx;
this.translation.y += dy;
this.deltaTranslation.x += dx;
this.deltaTranslation.y += dy;
this.globalPoint.x = event.page.x;
this.globalPoint.y = -event.page.y;
}

var timestamp = event.event.timeStamp;
var dt = timestamp - this.timestamp;
var isSamePoint = isRemoving || (dx === 0 && dy === 0);
var isStopped = (isSamePoint && dt > 150);

this.velocity.x = isStopped ? 0 : (isSamePoint || dt === 0) ? this.velocity.x : (dx / dt * 1000);
this.velocity.y = isStopped ? 0 : (isSamePoint || dt === 0) ? this.velocity.y : (dy / dt * 1000);
this.timestamp = timestamp;
},

_goUpWithEvent: function (event) {
this._updateWithEvent(event, true);
this.count = 0;

var didMove = Math.abs(this.translation.x) > 10 || Math.abs(this.translation.y) > 10;
var wasMoving = Math.abs(this.velocity.x) > 400 || Math.abs(this.velocity.y) > 400;
this.wasTap = !didMove && !wasMoving && (this.getTimeSinceGoingDown() < 300);
},

getTimeSinceGoingDown: function () {
return this.timestamp - this.downTimestamp;
},

resetDeltaTranslation: function () {
Expand Down
2 changes: 1 addition & 1 deletion TangleKit/TangleKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ Tangle.classes.TKAdjustableNumber = {
},

touchDidGoUp: function (touches) {
this.helpElement.setStyle("display", "none");
this.isDragging = false;
isAnyAdjustableNumberDragging = false;
this.updateRolloverEffects();
this.updateStyle();
this.helpElement.setStyle("display", touches.wasTap ? "block" : "none");
}
};

Expand Down

0 comments on commit c1e289a

Please sign in to comment.