From 46b493d02ea30a5a02afc03bcccdb8751f1b8b28 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 10 Apr 2015 13:01:00 -0700 Subject: [PATCH] minor blend changes. --- lib/widget.js | 38 ++++++++++++++++++++++++++++---------- test/widget-shadow.js | 8 ++++---- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 3df8f49..f984004 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -4171,6 +4171,7 @@ Element.prototype.render = function() { x = xl; for (; x < xl + 2; x++) { 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].dirty = true; } @@ -4181,6 +4182,7 @@ Element.prototype.render = function() { if (!lines[y]) continue; for (x = xi + 1; x < xl; x++) { 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].dirty = true; } @@ -8723,17 +8725,24 @@ function blend(attr, attr2) { if (bg2 === 0x1ff) bg2 = 0; bg = colors.mixColors(bg, bg2); } else { - if (bg < 8) { - bg += 8; + if (blend._cache[bg] != null) { + bg = blend._cache[bg]; + // } else if (bg < 8) { + // bg += 8; } else if (bg >= 8 && bg <= 15) { bg -= 8; } else { var name = colors.ncolors[bg]; if (name) { for (var i = 0; i < colors.ncolors.length; i++) { - if (name === colors.ncolors[i] && bg !== i) { - bg = i; - break; + if (name === colors.ncolors[i] && i !== bg) { + var c = colors.vcolors[bg]; + 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); } } else { - if (fg < 8) { - fg += 8; + if (blend._cache[fg] != null) { + fg = blend._cache[fg]; + // } else if (fg < 8) { + // fg += 8; } else if (fg >= 8 && fg <= 15) { fg -= 8; } else { var name = colors.ncolors[fg]; if (name) { for (var i = 0; i < colors.ncolors.length; i++) { - if (name === colors.ncolors[i] && fg !== i) { - fg = i; - break; + if (name === colors.ncolors[i] && i !== fg) { + var c = colors.vcolors[fg]; + 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; } +blend._cache = {}; + /** * Helpers */ diff --git a/test/widget-shadow.js b/test/widget-shadow.js index f4ecba9..5f66360 100644 --- a/test/widget-shadow.js +++ b/test/widget-shadow.js @@ -23,10 +23,10 @@ var bg = blessed.box({ var under = blessed.box({ parent: screen, shadow: true, - left: 2, - top: 2, - width: '30%', - height: '20%', + left: 10, + top: 4, + width: '40%', + height: '30%', style: { bg: 'yellow' },