Some tidy up to controller, identifies drag/clicks
This commit is contained in:
parent
28d2d49b1c
commit
7d69f037f1
|
@ -11,13 +11,7 @@ ascii.Position = function(x, y) {
|
||||||
/** type {Number} */ this.y = y;
|
/** type {Number} */ this.y = y;
|
||||||
};
|
};
|
||||||
|
|
||||||
goog.provide('ascii.Blah');
|
ascii.Position.prototype.equals = function(other) {
|
||||||
|
return (this.x == other.x)
|
||||||
/**
|
&& (this.y == other.y);
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
ascii.Blah = function(x, y) {
|
|
||||||
/** type {Number} */ this.x = x;
|
|
||||||
/** type {Number} */ this.y = y;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,29 +11,33 @@ goog.require('ascii.View');
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
ascii.Controller = function(view) {
|
ascii.Controller = function(view) {
|
||||||
/** type {ascii.View} */
|
/** type {ascii.View} */ this.view = view;
|
||||||
this.view = view;
|
/** type {ascii.StateControler */ this.stateController;
|
||||||
/** type {ascii.Position} */
|
/** type {ascii.Position} */ this.pressPosition;
|
||||||
this.clickPosition;
|
|
||||||
|
|
||||||
this.installDesktopBindings();
|
this.installDesktopBindings();
|
||||||
};
|
};
|
||||||
|
|
||||||
ascii.Controller.prototype.handlePress = function(x, y) {
|
ascii.Controller.prototype.handlePress = function(x, y) {
|
||||||
this.clickPosition = new ascii.Position(x, y);
|
this.pressPosition = new ascii.Position(x, y);
|
||||||
};
|
};
|
||||||
|
|
||||||
ascii.Controller.prototype.handleMove = function(x, y) {
|
ascii.Controller.prototype.handleMove = function(x, y) {
|
||||||
if (this.clickPosition) {
|
if (this.clickPosition) {
|
||||||
// Drag has started.
|
// Drag has started.
|
||||||
this.view.offset.x -= (x - this.clickPosition.x)/this.view.zoom;
|
this.view.offset.x -= (x - this.pressPosition.x)/this.view.zoom;
|
||||||
this.view.offset.y -= (y - this.clickPosition.y)/this.view.zoom;
|
this.view.offset.y -= (y - this.pressPosition.y)/this.view.zoom;
|
||||||
this.clickPosition = new ascii.Position(x, y);
|
this.clickPosition = new ascii.Position(x, y);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ascii.Controller.prototype.handleRelease = function(x, y) {
|
ascii.Controller.prototype.handleRelease = function(x, y) {
|
||||||
this.clickPosition = null;
|
if (this.pressPosition.equals(new ascii.Position(x, y))) {
|
||||||
|
// We should handle this as a 'click' as there was no dragging involved.
|
||||||
|
// Hand off to the state controller, as this will initiate a modification of the diagram itself.
|
||||||
|
// TODO: Work out how to pass off work into state-controller.
|
||||||
|
}
|
||||||
|
this.pressPosition = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
ascii.Controller.prototype.handleZoom = function(delta) {
|
ascii.Controller.prototype.handleZoom = function(delta) {
|
||||||
|
|
Loading…
Reference in New Issue