refactor. stop usign xi_, yi_.

This commit is contained in:
Christopher Jeffrey 2013-07-17 03:57:30 -05:00
parent 566b800a04
commit 6f8ab54a4f
1 changed files with 107 additions and 107 deletions

View File

@ -1953,9 +1953,9 @@ Box.prototype._getShrinkSize = function(content) {
}; };
}; };
Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) { Box.prototype._getShrinkBox = function(xi, xl, yi, yl) {
if (!this.children.length) { if (!this.children.length) {
return { xi: xi_, xl: xi_, yi: yi_, yl: yi_ }; return { xi: xi, xl: xi, yi: yi, yl: yi };
//return { xi: Infinity, xl: 0, yi: Infinity, yl: 0 }; //return { xi: Infinity, xl: 0, yi: Infinity, yl: 0 };
} }
@ -1975,13 +1975,13 @@ Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) {
var xll = xl, yll = yl; var xll = xl, yll = yl;
if (this.options.left == null && this.options.right != null) { if (this.options.left == null && this.options.right != null) {
if (this.options.width == null) xi_ = xl - (mxl - mxi); if (this.options.width == null) xi = xl - (mxl - mxi);
} else { } else {
if (this.options.width == null) xl = mxl; if (this.options.width == null) xl = mxl;
} }
if (this.options.top == null && this.options.bottom != null) { if (this.options.top == null && this.options.bottom != null) {
if (this.options.height == null) yi_ = yl - (myl - myi); if (this.options.height == null) yi = yl - (myl - myi);
} else { } else {
if (this.options.height == null) yl = myl; if (this.options.height == null) yl = myl;
} }
@ -1989,20 +1989,20 @@ Box.prototype._getShrinkBox = function(xi_, xl, yi_, yl) {
// Recenter shrunken elements. // Recenter shrunken elements.
if (xl < xll && this.options.left === 'center') { if (xl < xll && this.options.left === 'center') {
xll = (xll - xl) / 2 | 0; xll = (xll - xl) / 2 | 0;
xi_ += xll; xi += xll;
xl += xll; xl += xll;
} }
if (yl < yll && this.options.top === 'center') { if (yl < yll && this.options.top === 'center') {
yll = (yll - yl) / 2 | 0; yll = (yll - yl) / 2 | 0;
yi_ += yll; yi += yll;
yl += yll; yl += yll;
} }
return { xi: xi_, xl: xl, yi: yi_, yl: yl }; return { xi: xi, xl: xl, yi: yi, yl: yl };
}; };
Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) { Box.prototype._getShrinkContent = function(xi, xl, yi, yl, content) {
var hw = this._getShrinkSize(content) var hw = this._getShrinkSize(content)
, h = hw.height , h = hw.height
, w = hw.width , w = hw.width
@ -2013,9 +2013,9 @@ Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) {
&& (this.options.left == null && (this.options.left == null
|| this.options.right == null)) { || this.options.right == null)) {
if (this.options.left == null && this.options.right != null) { if (this.options.left == null && this.options.right != null) {
xi_ = xl - w - (this.border ? 2 : 0) - this.padding * 2; xi = xl - w - (this.border ? 2 : 0) - this.padding * 2;
} else { } else {
xl = xi_ + w + (this.border ? 2 : 0) + this.padding * 2; xl = xi + w + (this.border ? 2 : 0) + this.padding * 2;
} }
} }
@ -2024,40 +2024,40 @@ Box.prototype._getShrinkContent = function(xi_, xl, yi_, yl, content) {
|| this.options.bottom == null) || this.options.bottom == null)
&& this.childBase == null) { && this.childBase == null) {
if (this.options.top == null && this.options.bottom != null) { if (this.options.top == null && this.options.bottom != null) {
yi_ = yl - h - (this.border ? 2 : 0) - this.padding * 2; yi = yl - h - (this.border ? 2 : 0) - this.padding * 2;
} else { } else {
yl = yi_ + h + (this.border ? 2 : 0) + this.padding * 2; yl = yi + h + (this.border ? 2 : 0) + this.padding * 2;
} }
} }
// Recenter shrunken elements. // Recenter shrunken elements.
if (xl < xll && this.options.left === 'center') { if (xl < xll && this.options.left === 'center') {
xll = (xll - xl) / 2 | 0; xll = (xll - xl) / 2 | 0;
xi_ += xll; xi += xll;
xl += xll; xl += xll;
} }
if (yl < yll && this.options.top === 'center') { if (yl < yll && this.options.top === 'center') {
yll = (yll - yl) / 2 | 0; yll = (yll - yl) / 2 | 0;
yi_ += yll; yi += yll;
yl += yll; yl += yll;
} }
return { xi: xi_, xl: xl, yi: yi_, yl: yl }; return { xi: xi, xl: xl, yi: yi, yl: yl };
}; };
Box.prototype._getShrink = function(xi_, xl, yi_, yl, content) { Box.prototype._getShrink = function(xi, xl, yi, yl, content) {
var shrinkBox = this._getShrinkBox(xi_, xl, yi_, yl) var shrinkBox = this._getShrinkBox(xi, xl, yi, yl)
, shrinkContent = this._getShrinkContent(xi_, xl, yi_, yl, content); , shrinkContent = this._getShrinkContent(xi, xl, yi, yl, content);
if (this.options.left == null && this.options.right != null) { if (this.options.left == null && this.options.right != null) {
xi_ = Math.min(shrinkBox.xi, shrinkContent.xi); xi = Math.min(shrinkBox.xi, shrinkContent.xi);
} else { } else {
xl = Math.max(shrinkBox.xl, shrinkContent.xl); xl = Math.max(shrinkBox.xl, shrinkContent.xl);
} }
if (this.options.top == null && this.options.bottom != null) { if (this.options.top == null && this.options.bottom != null) {
yi_ = Math.min(shrinkBox.yi, shrinkContent.yi); yi = Math.min(shrinkBox.yi, shrinkContent.yi);
} else { } else {
yl = Math.max(shrinkBox.yl, shrinkContent.yl); yl = Math.max(shrinkBox.yl, shrinkContent.yl);
} }
@ -2065,18 +2065,18 @@ Box.prototype._getShrink = function(xi_, xl, yi_, yl, content) {
// Add padding if we're shrinking. // Add padding if we're shrinking.
if (this.padding) { if (this.padding) {
if (this.options.left == null && this.options.right != null) { if (this.options.left == null && this.options.right != null) {
if (this.options.width == null) xi_ -= this.padding * 2; if (this.options.width == null) xi -= this.padding * 2;
} else { } else {
if (this.options.width == null) xl += this.padding * 2; if (this.options.width == null) xl += this.padding * 2;
} }
if (this.options.top == null && this.options.bottom != null) { if (this.options.top == null && this.options.bottom != null) {
if (this.options.height == null) yi_ -= this.padding * 2; if (this.options.height == null) yi -= this.padding * 2;
} else { } else {
if (this.options.height == null) yl += this.padding * 2; if (this.options.height == null) yl += this.padding * 2;
} }
} }
return { xi: xi_, xl: xl, yi: yi_, yl: yl }; return { xi: xi, xl: xl, yi: yi, yl: yl };
}; };
// Here be dragons. // Here be dragons.
@ -2089,11 +2089,11 @@ Box.prototype.render = function(stop) {
this.parseContent(); this.parseContent();
var lines = this.screen.lines var lines = this.screen.lines
, xi_ = this.left , xi = this.left
, xi , x
, xl = this.screen.cols - this.right , xl = this.screen.cols - this.right
, yi_ = this.top , yi = this.top
, yi , y
, yl = this.screen.rows - this.bottom , yl = this.screen.rows - this.bottom
, cell , cell
, attr , attr
@ -2111,11 +2111,11 @@ Box.prototype.render = function(stop) {
, cci; , cci;
if (this.position.width) { if (this.position.width) {
xl = xi_ + this.width; xl = xi + this.width;
} }
if (this.position.height) { if (this.position.height) {
yl = yi_ + this.height; yl = yi + this.height;
} }
// Check to make sure we're visible and inside of the visible scroll area. // Check to make sure we're visible and inside of the visible scroll area.
@ -2123,7 +2123,7 @@ Box.prototype.render = function(stop) {
rtop = this.rtop - (this.parent.border ? 1 : 0); rtop = this.rtop - (this.parent.border ? 1 : 0);
visible = this.parent.height - (this.parent.border ? 2 : 0); visible = this.parent.height - (this.parent.border ? 2 : 0);
yi_ -= this.parent.childBase; yi -= this.parent.childBase;
yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0)); yl = Math.min(yl, this.screen.rows - this.parent.bottom - (this.parent.border ? 1 : 0));
if (rtop - this.parent.childBase < 0) { if (rtop - this.parent.childBase < 0) {
@ -2140,17 +2140,17 @@ Box.prototype.render = function(stop) {
// TODO: Check for 'center', recalculate yi, and xi. Better // TODO: Check for 'center', recalculate yi, and xi. Better
// yet, simply move this check into this.left/width/etc. // yet, simply move this check into this.left/width/etc.
if (this.shrink) { if (this.shrink) {
ret = this._getShrink(xi_, xl, yi_, yl, content); ret = this._getShrink(xi, xl, yi, yl, content);
xi_ = ret.xi, xl = ret.xl, yi_ = ret.yi, yl = ret.yl; xi = ret.xi, xl = ret.xl, yi = ret.yi, yl = ret.yl;
} }
// TODO: // TODO:
// Calculate whether we moved/resized by checking the previous _lastPos. // Calculate whether we moved/resized by checking the previous _lastPos.
// Maybe clear based on that. Possibly emit events here. // Maybe clear based on that. Possibly emit events here.
ret = { ret = {
xi: xi_, xi: xi,
xl: xl, xl: xl,
yi: yi_, yi: yi,
yl: yl yl: yl
}; };
@ -2178,20 +2178,20 @@ Box.prototype.render = function(stop) {
} }
} }
if (this.border) yi_++, yl--, xi_++, xl--; if (this.border) yi++, yl--, xi++, xl--;
if (this.padding || this.options.valign) { if (this.padding || this.options.valign) {
this.screen.fillRegion(dattr, ' ', xi_, xl, yi_, yl); this.screen.fillRegion(dattr, ' ', xi, xl, yi, yl);
} }
if (this.padding) { if (this.padding) {
yi_ += this.padding, yl -= this.padding; yi += this.padding, yl -= this.padding;
xi_ += this.padding, xl -= this.padding; xi += this.padding, xl -= this.padding;
} }
if (this.options.valign === 'middle' || this.options.valign === 'bottom') { if (this.options.valign === 'middle' || this.options.valign === 'bottom') {
//visible = (yl - yi_) - (this.border ? 2 : 0) - this.padding; //visible = (yl - yi) - (this.border ? 2 : 0) - this.padding;
visible = yl - yi_; visible = yl - yi;
if (this._clines.length < visible) { if (this._clines.length < visible) {
if (this.options.valign === 'middle') { if (this.options.valign === 'middle') {
visible = visible / 2 | 0; visible = visible / 2 | 0;
@ -2199,15 +2199,15 @@ Box.prototype.render = function(stop) {
} else if (this.options.valign === 'bottom') { } else if (this.options.valign === 'bottom') {
visible -= this._clines.length; visible -= this._clines.length;
} }
yi_ += visible; yi += visible;
} }
} }
outer: outer:
for (yi = yi_; yi < yl; yi++) { for (y = yi; y < yl; y++) {
if (!lines[yi]) break; if (!lines[y]) break;
for (xi = xi_; xi < xl; xi++) { for (x = xi; x < xl; x++) {
cell = lines[yi][xi]; cell = lines[y][x];
if (!cell) break; if (!cell) break;
ch = content[ci++] || ' '; ch = content[ci++] || ' ';
@ -2230,20 +2230,20 @@ outer:
// If we're on the first cell and we find a newline and the last cell // If we're on the first cell and we find a newline and the last cell
// of the last line was not a newline, let's just treat this like the // of the last line was not a newline, let's just treat this like the
// newline was already "counted". // newline was already "counted".
if (xi === xi_ && yi !== yi_ && content[ci-2] !== '\n') { if (x === xi && y !== yi && content[ci-2] !== '\n') {
xi--; x--;
continue; continue;
} }
// this.screen.fillRegion(attr, ' ', xi, xl, yi, yi + 1); // this.screen.fillRegion(attr, ' ', x, xl, y, y + 1);
// continue outer; // continue outer;
ch = ' '; ch = ' ';
for (; xi < xl; xi++) { for (; x < xl; x++) {
cell = lines[yi][xi]; cell = lines[y][x];
if (!cell) break; if (!cell) break;
if (attr !== cell[0] || ch !== cell[1]) { if (attr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = attr; lines[y][x][0] = attr;
lines[yi][xi][1] = ch; lines[y][x][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
continue; continue;
@ -2251,26 +2251,26 @@ outer:
// if (ch < ' ') ch = ' '; // if (ch < ' ') ch = ' ';
if (attr !== cell[0] || ch !== cell[1]) { if (attr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = attr; lines[y][x][0] = attr;
lines[yi][xi][1] = ch; lines[y][x][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
} }
h = this.items ? this.items.length : this._clines.length; h = this.items ? this.items.length : this._clines.length;
if (this.scrollbar && (yl - yi_) < h) { if (this.scrollbar && (yl - yi) < h) {
xi = xl - 1; x = xl - 1;
if (this.scrollbar.ignoreBorder && this.border) xi++; if (this.scrollbar.ignoreBorder && this.border) x++;
if (this.selected == null) { if (this.selected == null) {
// TODO: Fix this - doesn't work with lists (and possibly scrollabletext). // TODO: Fix this - doesn't work with lists (and possibly scrollabletext).
yi = h - (yl - yi_) - (this.border ? 2 : 0) - this.padding * 2; y = h - (yl - yi) - (this.border ? 2 : 0) - this.padding * 2;
yi = yi_ + (((yl - yi_) * (this.childBase / yi)) | 0); y = yi + (((yl - yi) * (this.childBase / y)) | 0);
} else { } else {
yi = this.selected / h; y = this.selected / h;
yi = yi_ + ((yl - yi_) * yi | 0); y = yi + ((yl - yi) * y | 0);
} }
cell = lines[yi] && lines[yi][xi]; cell = lines[y] && lines[y][x];
if (cell) { if (cell) {
ch = this.scrollbar.ch || ' '; ch = this.scrollbar.ch || ' ';
//attr = this.sattr(this.style, //attr = this.sattr(this.style,
@ -2280,20 +2280,20 @@ outer:
this.style.scrollbar.fg || this.style.fg, this.style.scrollbar.fg || this.style.fg,
this.style.scrollbar.bg || this.style.bg); this.style.scrollbar.bg || this.style.bg);
if (attr !== cell[0] || ch !== cell[1]) { if (attr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = attr; lines[y][x][0] = attr;
lines[yi][xi][1] = ch; lines[y][x][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
} }
// This seems redundant, but we need to draw the // This seems redundant, but we need to draw the
// border second because of the `shrink` option. // border second because of the `shrink` option.
if (this.border) yi_--, yl++, xi_--, xl++; if (this.border) yi--, yl++, xi--, xl++;
if (this.padding) { if (this.padding) {
yi_ -= this.padding, yl += this.padding; yi -= this.padding, yl += this.padding;
xi_ -= this.padding, xl += this.padding; xi -= this.padding, xl += this.padding;
} }
/* /*
@ -2302,89 +2302,89 @@ outer:
// dattr = (dattr & ~0x1ff) | colors.convert('green'); // dattr = (dattr & ~0x1ff) | colors.convert('green');
// top // top
this.screen.fillRegion(dattr, ' ', this.screen.fillRegion(dattr, ' ',
xi_ + (this.border ? 1 : 0), xi + (this.border ? 1 : 0),
xl - (this.border ? 1 : 0), xl - (this.border ? 1 : 0),
yi_ + (this.border ? 1 : 0), yi + (this.border ? 1 : 0),
yi_ + 0 + (this.border ? 1 : 0) + this.padding); yi + 0 + (this.border ? 1 : 0) + this.padding);
// bottom // bottom
this.screen.fillRegion(dattr, ' ', this.screen.fillRegion(dattr, ' ',
xi_ + (this.border ? 1 : 0), xi + (this.border ? 1 : 0),
xl - (this.border ? 1 : 0), xl - (this.border ? 1 : 0),
yl - 0 - (this.border ? 1 : 0) - this.padding, yl - 0 - (this.border ? 1 : 0) - this.padding,
yl - (this.border ? 1 : 0)); yl - (this.border ? 1 : 0));
// left // left
this.screen.fillRegion(dattr, ' ', this.screen.fillRegion(dattr, ' ',
xi_ + (this.border ? 1 : 0), xi + (this.border ? 1 : 0),
xi_ + 0 + (this.border ? 1 : 0) + this.padding, xi + 0 + (this.border ? 1 : 0) + this.padding,
yi_ + (this.border ? 1 : 0), yi + (this.border ? 1 : 0),
yl - (this.border ? 1 : 0)); yl - (this.border ? 1 : 0));
// right // right
this.screen.fillRegion(dattr, ' ', this.screen.fillRegion(dattr, ' ',
xl - 0 - (this.border ? 1 : 0) - this.padding, xl - 0 - (this.border ? 1 : 0) - this.padding,
xl - (this.border ? 1 : 0), xl - (this.border ? 1 : 0),
yi_ + (this.border ? 1 : 0), yi + (this.border ? 1 : 0),
yl - (this.border ? 1 : 0)); yl - (this.border ? 1 : 0));
} }
*/ */
if (this.border) { if (this.border) {
yi = yi_; y = yi;
for (xi = xi_; xi < xl; xi++) { for (x = xi; x < xl; x++) {
if (!lines[yi]) break; if (!lines[y]) break;
if (this.border.type === 'line') { if (this.border.type === 'line') {
if (xi === xi_) ch = '┌'; if (x === xi) ch = '┌';
else if (xi === xl - 1) ch = '┐'; else if (x === xl - 1) ch = '┐';
else ch = '─'; else ch = '─';
} else if (this.border.type === 'bg') { } else if (this.border.type === 'bg') {
ch = this.border.ch; ch = this.border.ch;
} }
cell = lines[yi][xi]; cell = lines[y][x];
if (!cell) break; if (!cell) break;
if (battr !== cell[0] || ch !== cell[1]) { if (battr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = battr; lines[y][x][0] = battr;
lines[yi][xi][1] = ch; lines[y][x][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
yi = yi_ + 1; y = yi + 1;
for (; yi < yl; yi++) { for (; y < yl; y++) {
if (!lines[yi]) break; if (!lines[y]) break;
if (this.border.type === 'line') { if (this.border.type === 'line') {
ch = '│'; ch = '│';
} else if (this.border.type === 'bg') { } else if (this.border.type === 'bg') {
ch = this.border.ch; ch = this.border.ch;
} }
cell = lines[yi][xi_]; cell = lines[y][xi];
if (!cell) break; if (!cell) break;
if (battr !== cell[0] || ch !== cell[1]) { if (battr !== cell[0] || ch !== cell[1]) {
lines[yi][xi_][0] = battr; lines[y][xi][0] = battr;
lines[yi][xi_][1] = ch; lines[y][xi][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
cell = lines[yi][xl - 1]; cell = lines[y][xl - 1];
if (!cell) break; if (!cell) break;
if (battr !== cell[0] || ch !== cell[1]) { if (battr !== cell[0] || ch !== cell[1]) {
lines[yi][xl - 1][0] = battr; lines[y][xl - 1][0] = battr;
lines[yi][xl - 1][1] = ch; lines[y][xl - 1][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
yi = yl - 1; y = yl - 1;
for (xi = xi_; xi < xl; xi++) { for (x = xi; x < xl; x++) {
if (!lines[yi]) break; if (!lines[y]) break;
if (this.border.type === 'line') { if (this.border.type === 'line') {
if (xi === xi_) ch = '└'; if (x === xi) ch = '└';
else if (xi === xl - 1) ch = '┘'; else if (x === xl - 1) ch = '┘';
else ch = '─'; else ch = '─';
} else if (this.border.type === 'bg') { } else if (this.border.type === 'bg') {
ch = this.border.ch; ch = this.border.ch;
} }
cell = lines[yi][xi]; cell = lines[y][x];
if (!cell) break; if (!cell) break;
if (battr !== cell[0] || ch !== cell[1]) { if (battr !== cell[0] || ch !== cell[1]) {
lines[yi][xi][0] = battr; lines[y][x][0] = battr;
lines[yi][xi][1] = ch; lines[y][x][1] = ch;
lines[yi].dirty = true; lines[y].dirty = true;
} }
} }
} }