From a76225dc7f8ec707fc2dc563a796c65620b1c5a4 Mon Sep 17 00:00:00 2001 From: timb Date: Wed, 22 Jul 2015 00:25:07 -0700 Subject: finally hook up undo --- js/matrix.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'js/matrix.js') diff --git a/js/matrix.js b/js/matrix.js index 5c56bd4..6994327 100644 --- a/js/matrix.js +++ b/js/matrix.js @@ -4,6 +4,8 @@ function Matrix (w,h,f){ this.w = w this.h = h this.f = f + this.focus_x = 0 + this.focus_y = 0 this.initialize() } Matrix.prototype.initialize = function(f){ @@ -23,6 +25,7 @@ Matrix.prototype.rebuild = function (){ this.append() this.bind() this.generate && this.generate() + this.focus_clamp() check_if_lost_focus() } Matrix.prototype.clone = function () { @@ -70,6 +73,24 @@ Matrix.prototype.forEach = function(f){ }) }) } +Matrix.prototype.focus_clamp = function(){ + this.focus_x = clamp(this.focus_x, 0, this.w - 1) + this.focus_y = clamp(this.focus_y, 0, this.h - 1) +} +Matrix.prototype.focus_add = function(x, y){ + this.focus(this.focus_x + x, this.focus_y + y) +} +Matrix.prototype.focus = function(x, y){ + if (x === undefined) x = this.focus_x + if (y === undefined) y = this.focus_y + x = mod(x, this.w) + y = mod(y, this.h) + this.focus_x = x + this.focus_y = y + + //focused_input = this + this.aa[y][x].focus() +} Matrix.prototype.focusLex = function(y,x){ if (x < 0) { y -= 1 @@ -181,7 +202,7 @@ Matrix.prototype.resize = function(w,h){ this.w = w this.h = h this.bind && this.bind() - + this.focus_clamp() if (this.rapper && this.rapper.parentNode != document.body) { this.resize_rapper() } -- cgit v1.2.3-70-g09d2