reorganize more code.

This commit is contained in:
Christopher Jeffrey 2015-05-01 00:47:39 -07:00
parent 0b6fceec23
commit d2586089c8

View File

@ -701,6 +701,60 @@ Screen.prototype.enableInput = function(el) {
this._listenKeys(el);
};
Screen.prototype._initHover = function() {
var self = this;
if (this._hoverText) {
return;
}
this._hoverText = new Box({
screen: this,
left: 0,
top: 0,
tags: false,
height: 'shrink',
width: 'shrink',
border: 'line',
style: {
border: {
fg: 'default'
},
bg: 'default',
fg: 'default'
}
});
this.on('mousemove', function(data) {
if (self._hoverText.detached) return;
self._hoverText.rleft = data.x + 1;
self._hoverText.rtop = data.y;
self.render();
});
this.on('element mouseover', function(el, data) {
if (!el._hoverOptions) return;
self._hoverText.parseTags = el.parseTags;
self._hoverText.setContent(el._hoverOptions.text);
self.append(self._hoverText);
self._hoverText.rleft = data.x + 1;
self._hoverText.rtop = data.y;
self.render();
});
this.on('element mouseout', function() {
if (self._hoverText.detached) return;
self._hoverText.detach();
self.render();
});
this.on('element mouseup', function(el, data) {
if (!el._hoverOptions) return;
self.append(self._hoverText);
self.render();
});
};
Screen.prototype.__defineGetter__('cols', function() {
return this.program.cols;
});
@ -972,6 +1026,70 @@ Screen.prototype.cleanSides = function(el) {
return pos._cleanSides = true;
};
Screen.prototype._dockBorders = function() {
var lines = this.lines
, stops = this._borderStops
, i
, y
, x
, ch;
// var keys, stop;
//
// keys = Object.keys(this._borderStops)
// .map(function(k) { return +k; })
// .sort(function(a, b) { return a - b; });
//
// for (i = 0; i < keys.length; i++) {
// y = keys[i];
// if (!lines[y]) continue;
// stop = this._borderStops[y];
// for (x = stop.xi; x < stop.xl; x++) {
stops = Object.keys(stops)
.map(function(k) { return +k; })
.sort(function(a, b) { return a - b; });
for (i = 0; i < stops.length; i++) {
y = stops[i];
if (!lines[y]) continue;
for (x = 0; x < this.width; x++) {
ch = lines[y][x][1];
if (angles[ch]) {
lines[y][x][1] = this._getAngle(lines, x, y);
}
}
}
};
Screen.prototype._getAngle = function(lines, x, y) {
var angle = 0
, attr = lines[y][x][0]
, ch = lines[y][x][1];
if (lines[y][x - 1] && langles[lines[y][x - 1][1]]) {
if (lines[y][x - 1][0] !== attr) return ch;
angle |= 1 << 3;
}
if (lines[y - 1] && uangles[lines[y - 1][x][1]]) {
if (lines[y - 1][x][0] !== attr) return ch;
angle |= 1 << 2;
}
if (lines[y][x + 1] && rangles[lines[y][x + 1][1]]) {
if (lines[y][x + 1][0] !== attr) return ch;
angle |= 1 << 1;
}
if (lines[y + 1] && dangles[lines[y + 1][x][1]]) {
if (lines[y + 1][x][0] !== attr) return ch;
angle |= 1 << 0;
}
return angleTable[angle] || ch;
};
Screen.prototype.draw = function(start, end) {
// this.emit('predraw');
@ -2099,6 +2217,14 @@ Screen.prototype.screenshot = function(xi, xl, yi, yl, term) {
return main;
};
/**
* Positioning
*/
Screen.prototype._getPos = function() {
return this;
};
/**
* Element
*/
@ -3012,60 +3138,6 @@ Element.prototype.removeHover = function() {
this.screen.render();
};
Screen.prototype._initHover = function() {
var self = this;
if (this._hoverText) {
return;
}
this._hoverText = new Box({
screen: this,
left: 0,
top: 0,
tags: false,
height: 'shrink',
width: 'shrink',
border: 'line',
style: {
border: {
fg: 'default'
},
bg: 'default',
fg: 'default'
}
});
this.on('mousemove', function(data) {
if (self._hoverText.detached) return;
self._hoverText.rleft = data.x + 1;
self._hoverText.rtop = data.y;
self.render();
});
this.on('element mouseover', function(el, data) {
if (!el._hoverOptions) return;
self._hoverText.parseTags = el.parseTags;
self._hoverText.setContent(el._hoverOptions.text);
self.append(self._hoverText);
self._hoverText.rleft = data.x + 1;
self._hoverText.rtop = data.y;
self.render();
});
this.on('element mouseout', function() {
if (self._hoverText.detached) return;
self._hoverText.detach();
self.render();
});
this.on('element mouseup', function(el, data) {
if (!el._hoverOptions) return;
self.append(self._hoverText);
self.render();
});
};
/**
* Positioning
*/
@ -3085,10 +3157,6 @@ Screen.prototype._initHover = function() {
// position (since that might be wrong because
// it doesn't handle content shrinkage).
Screen.prototype._getPos = function() {
return this;
};
Element.prototype._getPos = function() {
var pos = this.lpos;
@ -4401,42 +4469,6 @@ Element.prototype.render = function() {
return coords;
};
Screen.prototype._dockBorders = function() {
var lines = this.lines
, stops = this._borderStops
, i
, y
, x
, ch;
// var keys, stop;
//
// keys = Object.keys(this._borderStops)
// .map(function(k) { return +k; })
// .sort(function(a, b) { return a - b; });
//
// for (i = 0; i < keys.length; i++) {
// y = keys[i];
// if (!lines[y]) continue;
// stop = this._borderStops[y];
// for (x = stop.xi; x < stop.xl; x++) {
stops = Object.keys(stops)
.map(function(k) { return +k; })
.sort(function(a, b) { return a - b; });
for (i = 0; i < stops.length; i++) {
y = stops[i];
if (!lines[y]) continue;
for (x = 0; x < this.width; x++) {
ch = lines[y][x][1];
if (angles[ch]) {
lines[y][x][1] = getAngle(lines, x, y);
}
}
}
};
Element.prototype._render = Element.prototype.render;
/**
@ -9025,34 +9057,6 @@ Object.keys(angleTable).forEach(function(key) {
delete angleTable[key];
});
function getAngle(lines, x, y) {
var angle = 0
, attr = lines[y][x][0]
, ch = lines[y][x][1];
if (lines[y][x - 1] && langles[lines[y][x - 1][1]]) {
if (lines[y][x - 1][0] !== attr) return ch;
angle |= 1 << 3;
}
if (lines[y - 1] && uangles[lines[y - 1][x][1]]) {
if (lines[y - 1][x][0] !== attr) return ch;
angle |= 1 << 2;
}
if (lines[y][x + 1] && rangles[lines[y][x + 1][1]]) {
if (lines[y][x + 1][0] !== attr) return ch;
angle |= 1 << 1;
}
if (lines[y + 1] && dangles[lines[y + 1][x][1]]) {
if (lines[y + 1][x][0] !== attr) return ch;
angle |= 1 << 0;
}
return angleTable[angle] || ch;
}
/**
* Helpers
*/