minor blend changes.

This commit is contained in:
Christopher Jeffrey 2015-04-10 13:01:00 -07:00
parent eebbcdd702
commit 46b493d02e
2 changed files with 32 additions and 14 deletions

View File

@ -4171,6 +4171,7 @@ Element.prototype.render = function() {
x = xl; x = xl;
for (; x < xl + 2; x++) { for (; x < xl + 2; x++) {
if (!lines[y][x]) continue; if (!lines[y][x]) continue;
// lines[y][x][0] = blend(this.dattr, lines[y][x][0]);
lines[y][x][0] = blend(lines[y][x][0]); lines[y][x][0] = blend(lines[y][x][0]);
lines[y].dirty = true; lines[y].dirty = true;
} }
@ -4181,6 +4182,7 @@ Element.prototype.render = function() {
if (!lines[y]) continue; if (!lines[y]) continue;
for (x = xi + 1; x < xl; x++) { for (x = xi + 1; x < xl; x++) {
if (!lines[y][x]) continue; if (!lines[y][x]) continue;
// lines[y][x][0] = blend(this.dattr, lines[y][x][0]);
lines[y][x][0] = blend(lines[y][x][0]); lines[y][x][0] = blend(lines[y][x][0]);
lines[y].dirty = true; lines[y].dirty = true;
} }
@ -8723,17 +8725,24 @@ function blend(attr, attr2) {
if (bg2 === 0x1ff) bg2 = 0; if (bg2 === 0x1ff) bg2 = 0;
bg = colors.mixColors(bg, bg2); bg = colors.mixColors(bg, bg2);
} else { } else {
if (bg < 8) { if (blend._cache[bg] != null) {
bg += 8; bg = blend._cache[bg];
// } else if (bg < 8) {
// bg += 8;
} else if (bg >= 8 && bg <= 15) { } else if (bg >= 8 && bg <= 15) {
bg -= 8; bg -= 8;
} else { } else {
var name = colors.ncolors[bg]; var name = colors.ncolors[bg];
if (name) { if (name) {
for (var i = 0; i < colors.ncolors.length; i++) { for (var i = 0; i < colors.ncolors.length; i++) {
if (name === colors.ncolors[i] && bg !== i) { if (name === colors.ncolors[i] && i !== bg) {
bg = i; var c = colors.vcolors[bg];
break; var nc = colors.vcolors[i];
if (nc[0] + nc[1] + nc[2] < c[0] + c[1] + c[2]) {
blend._cache[bg] = i;
bg = i;
break;
}
} }
} }
} }
@ -8756,17 +8765,24 @@ function blend(attr, attr2) {
fg = colors.mixColors(fg, fg2); fg = colors.mixColors(fg, fg2);
} }
} else { } else {
if (fg < 8) { if (blend._cache[fg] != null) {
fg += 8; fg = blend._cache[fg];
// } else if (fg < 8) {
// fg += 8;
} else if (fg >= 8 && fg <= 15) { } else if (fg >= 8 && fg <= 15) {
fg -= 8; fg -= 8;
} else { } else {
var name = colors.ncolors[fg]; var name = colors.ncolors[fg];
if (name) { if (name) {
for (var i = 0; i < colors.ncolors.length; i++) { for (var i = 0; i < colors.ncolors.length; i++) {
if (name === colors.ncolors[i] && fg !== i) { if (name === colors.ncolors[i] && i !== fg) {
fg = i; var c = colors.vcolors[fg];
break; var nc = colors.vcolors[i];
if (nc[0] + nc[1] + nc[2] < c[0] + c[1] + c[2]) {
blend._cache[fg] = i;
fg = i;
break;
}
} }
} }
} }
@ -8779,6 +8795,8 @@ function blend(attr, attr2) {
return attr; return attr;
} }
blend._cache = {};
/** /**
* Helpers * Helpers
*/ */

View File

@ -23,10 +23,10 @@ var bg = blessed.box({
var under = blessed.box({ var under = blessed.box({
parent: screen, parent: screen,
shadow: true, shadow: true,
left: 2, left: 10,
top: 2, top: 4,
width: '30%', width: '40%',
height: '20%', height: '30%',
style: { style: {
bg: 'yellow' bg: 'yellow'
}, },