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;
|
||||
};
|
||||
|
||||
goog.provide('ascii.Blah');
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
ascii.Blah = function(x, y) {
|
||||
/** type {Number} */ this.x = x;
|
||||
/** type {Number} */ this.y = y;
|
||||
ascii.Position.prototype.equals = function(other) {
|
||||
return (this.x == other.x)
|
||||
&& (this.y == other.y);
|
||||
};
|
||||
|
||||
|
|
|
@ -11,29 +11,33 @@ goog.require('ascii.View');
|
|||
* @constructor
|
||||
*/
|
||||
ascii.Controller = function(view) {
|
||||
/** type {ascii.View} */
|
||||
this.view = view;
|
||||
/** type {ascii.Position} */
|
||||
this.clickPosition;
|
||||
/** type {ascii.View} */ this.view = view;
|
||||
/** type {ascii.StateControler */ this.stateController;
|
||||
/** type {ascii.Position} */ this.pressPosition;
|
||||
|
||||
this.installDesktopBindings();
|
||||
};
|
||||
|
||||
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) {
|
||||
if (this.clickPosition) {
|
||||
// Drag has started.
|
||||
this.view.offset.x -= (x - this.clickPosition.x)/this.view.zoom;
|
||||
this.view.offset.y -= (y - this.clickPosition.y)/this.view.zoom;
|
||||
this.view.offset.x -= (x - this.pressPosition.x)/this.view.zoom;
|
||||
this.view.offset.y -= (y - this.pressPosition.y)/this.view.zoom;
|
||||
this.clickPosition = new ascii.Position(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) {
|
||||
|
|
Loading…
Reference in New Issue