mirror of https://github.com/espruino/BangleApps
messagesoverlay - Use 16 bit buffer to correctly handle theme colors
parent
c33f677d1d
commit
5b5982c255
|
@ -1,5 +1,6 @@
|
||||||
let lockListener;
|
let lockListener;
|
||||||
let quiet;
|
let ovr;
|
||||||
|
let clearingTimeout;
|
||||||
|
|
||||||
// Converts a espruino version to a semantiv versioning object
|
// Converts a espruino version to a semantiv versioning object
|
||||||
const toSemantic = function (v){
|
const toSemantic = function (v){
|
||||||
|
@ -41,30 +42,28 @@ let LOG=()=>{};
|
||||||
//LOG = function() { print.apply(null, arguments);};
|
//LOG = function() { print.apply(null, arguments);};
|
||||||
|
|
||||||
const isQuiet = function(){
|
const isQuiet = function(){
|
||||||
if (quiet == undefined) quiet = (require('Storage').readJSON('setting.json', 1) || {}).quiet;
|
return (require('Storage').readJSON('setting.json', 1) || {}).quiet;
|
||||||
return quiet;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let eventQueue = [];
|
let eventQueue = [];
|
||||||
let callInProgress = false;
|
let callInProgress = false;
|
||||||
let buzzing = false;
|
let buzzing = false;
|
||||||
|
|
||||||
const show = function(ovr){
|
const show = function(){
|
||||||
let img = ovr;
|
let img = ovr.asImage();
|
||||||
LOG("show", img.getBPP());
|
LOG("show", img.bpp);
|
||||||
if (ovr.getBPP() == 1) {
|
if (ovr.getBPP() == 1) {
|
||||||
img = ovr.asImage();
|
|
||||||
img.palette = new Uint16Array([g.theme.fg,g.theme.bg]);
|
img.palette = new Uint16Array([g.theme.fg,g.theme.bg]);
|
||||||
}
|
}
|
||||||
Bangle.setLCDOverlay(img, ovrx, ovry);
|
Bangle.setLCDOverlay(img, ovrx, ovry);
|
||||||
};
|
};
|
||||||
|
|
||||||
const manageEvent = function(ovr, event) {
|
const manageEvent = function(event) {
|
||||||
event.new = true;
|
event.new = true;
|
||||||
|
|
||||||
LOG("manageEvent");
|
LOG("manageEvent");
|
||||||
if (event.id == "call") {
|
if (event.id == "call") {
|
||||||
showCall(ovr, event);
|
showCall(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (event.t) {
|
switch (event.t) {
|
||||||
|
@ -72,7 +71,7 @@ const manageEvent = function(ovr, event) {
|
||||||
eventQueue.unshift(event);
|
eventQueue.unshift(event);
|
||||||
|
|
||||||
if (!callInProgress)
|
if (!callInProgress)
|
||||||
showMessage(ovr, event);
|
showMessage(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "modify": {
|
case "modify": {
|
||||||
|
@ -87,15 +86,15 @@ const manageEvent = function(ovr, event) {
|
||||||
eventQueue.unshift(event);
|
eventQueue.unshift(event);
|
||||||
|
|
||||||
if (!callInProgress)
|
if (!callInProgress)
|
||||||
showMessage(ovr, event);
|
showMessage(event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "remove":
|
case "remove":
|
||||||
if (eventQueue.length == 0 && !callInProgress)
|
if (eventQueue.length == 0 && !callInProgress)
|
||||||
next(ovr);
|
next();
|
||||||
|
|
||||||
if (!callInProgress && eventQueue[0] !== undefined && eventQueue[0].id == event.id)
|
if (!callInProgress && eventQueue[0] !== undefined && eventQueue[0].id == event.id)
|
||||||
next(ovr);
|
next();
|
||||||
else
|
else
|
||||||
eventQueue = [];
|
eventQueue = [];
|
||||||
|
|
||||||
|
@ -103,7 +102,7 @@ const manageEvent = function(ovr, event) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const roundedRect = function(ovr, x,y,w,h,filled){
|
const roundedRect = function(x,y,w,h,filled){
|
||||||
var poly = [
|
var poly = [
|
||||||
x,y+4,
|
x,y+4,
|
||||||
x+4,y,
|
x+4,y,
|
||||||
|
@ -126,9 +125,7 @@ const roundedRect = function(ovr, x,y,w,h,filled){
|
||||||
|
|
||||||
const DIVIDER = 38;
|
const DIVIDER = 38;
|
||||||
|
|
||||||
const drawScreen = function(ovr, title, src, iconcolor, icon){
|
const drawScreen = function(title, src, iconcolor, icon){
|
||||||
ovr.setColor(ovr.theme.fg2);
|
|
||||||
ovr.setBgColor(ovr.theme.bg2);
|
|
||||||
ovr.clearRect(2,2,ovr.getWidth()-3, DIVIDER - 1);
|
ovr.clearRect(2,2,ovr.getWidth()-3, DIVIDER - 1);
|
||||||
|
|
||||||
ovr.setFont(settings.fontSmall);
|
ovr.setFont(settings.fontSmall);
|
||||||
|
@ -144,19 +141,24 @@ const drawScreen = function(ovr, title, src, iconcolor, icon){
|
||||||
if (src)
|
if (src)
|
||||||
drawSource(src, textCenter, w, 2, -1);
|
drawSource(src, textCenter, w, 2, -1);
|
||||||
|
|
||||||
ovr.setColor(ovr.theme.fg);
|
if (ovr.getBPP() > 1) {
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
let old = ovr.getBgColor();
|
||||||
|
ovr.setBgColor("#888");
|
||||||
|
roundedRect(4, 5, 30, 30,true);
|
||||||
|
ovr.setBgColor(old);
|
||||||
|
old = ovr.getColor();
|
||||||
|
ovr.setColor(iconcolor);
|
||||||
|
ovr.drawImage(icon,7,8);
|
||||||
|
ovr.setColor(old);
|
||||||
|
} else {
|
||||||
|
roundedRect(4, 5, 30, 30,true);
|
||||||
|
ovr.drawImage(icon,7,8);
|
||||||
|
}
|
||||||
|
|
||||||
roundedRect(ovr, ovr.getWidth()-26,5,22,30,true);
|
roundedRect(ovr.getWidth()-26,5,22,30,true);
|
||||||
ovr.setFontAlign(0,0);
|
ovr.setFontAlign(0,0);
|
||||||
ovr.setFont("Vector:16");
|
ovr.setFont("Vector:16");
|
||||||
ovr.drawString("X",ovr.getWidth()-14,20);
|
ovr.drawString("X",ovr.getWidth()-14,20);
|
||||||
|
|
||||||
ovr.setBgColor("#888");
|
|
||||||
roundedRect(ovr, 4, 5, 30, 30,true);
|
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
|
||||||
ovr.setColor(ovr.getBPP() != 1 ? iconcolor : ovr.theme.fg);
|
|
||||||
ovr.drawImage(icon,7,8);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawSource = function(src, center, w, y, align) {
|
const drawSource = function(src, center, w, y, align) {
|
||||||
|
@ -198,13 +200,28 @@ const drawTitle = function(title, center, w, y, h) {
|
||||||
ovr.drawString(title, center, dh);
|
ovr.drawString(title, center, dh);
|
||||||
};
|
};
|
||||||
|
|
||||||
const showMessage = function(ovr, msg) {
|
const showMessage = function(msg) {
|
||||||
LOG("showMessage");
|
LOG("showMessage");
|
||||||
|
|
||||||
ovr.setClipRect(0,0,ovr.getWidth(),ovr.getHeight());
|
ovr.setClipRect(0,0,ovr.getWidth(),ovr.getHeight());
|
||||||
drawScreen(ovr, msg.title, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
|
||||||
|
|
||||||
drawMessage(ovr, msg);
|
if (Bangle.isLocked()){
|
||||||
|
ovr.setColor(ovr.theme.fg);
|
||||||
|
ovr.setBgColor(ovr.theme.bg);
|
||||||
|
} else {
|
||||||
|
ovr.setColor(ovr.theme.fg2);
|
||||||
|
ovr.setBgColor(ovr.theme.bg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawScreen(msg.title, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
||||||
|
|
||||||
|
|
||||||
|
if (!Bangle.isLocked()){
|
||||||
|
ovr.setColor(ovr.theme.fg);
|
||||||
|
ovr.setBgColor(ovr.theme.bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
drawMessage(msg);
|
||||||
|
|
||||||
if (!isQuiet() && msg.new) {
|
if (!isQuiet() && msg.new) {
|
||||||
msg.new = false;
|
msg.new = false;
|
||||||
|
@ -216,37 +233,34 @@ const showMessage = function(ovr, msg) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getBorderColor = function() {
|
const drawBorder = function() {
|
||||||
if (Bangle.isLocked())
|
|
||||||
return ovr.theme.fg;
|
|
||||||
else
|
|
||||||
return ovr.theme.fgH;
|
|
||||||
};
|
|
||||||
|
|
||||||
const drawBorder = function(img) {
|
|
||||||
LOG("drawBorder", isQuiet());
|
LOG("drawBorder", isQuiet());
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
if (Bangle.isLocked()){
|
||||||
if (img) ovr=img;
|
ovr.setColor(ovr.theme.fg);
|
||||||
ovr.setColor(getBorderColor());
|
ovr.setBgColor(ovr.theme.bg);
|
||||||
|
} else {
|
||||||
|
ovr.setColor(ovr.theme.fg2);
|
||||||
|
ovr.setBgColor(ovr.theme.bg2);
|
||||||
|
}
|
||||||
ovr.drawRect(0,0,ovr.getWidth()-1,ovr.getHeight()-1);
|
ovr.drawRect(0,0,ovr.getWidth()-1,ovr.getHeight()-1);
|
||||||
ovr.drawRect(1,1,ovr.getWidth()-2,ovr.getHeight()-2);
|
ovr.drawRect(1,1,ovr.getWidth()-2,ovr.getHeight()-2);
|
||||||
ovr.drawRect(2,DIVIDER,ovr.getWidth()-2,DIVIDER+1);
|
ovr.drawRect(2,DIVIDER,ovr.getWidth()-2,DIVIDER+1);
|
||||||
show(ovr);
|
show();
|
||||||
};
|
};
|
||||||
|
|
||||||
const showCall = function(ovr, msg) {
|
const showCall = function(msg) {
|
||||||
LOG("showCall");
|
LOG("showCall");
|
||||||
LOG(msg);
|
LOG(msg);
|
||||||
|
|
||||||
if (msg.t == "remove") {
|
if (msg.t == "remove") {
|
||||||
LOG("hide call screen");
|
LOG("hide call screen");
|
||||||
next(ovr); //dont shift
|
next(); //dont shift
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
callInProgress = true;
|
callInProgress = true;
|
||||||
|
|
||||||
drawScreen(ovr, msg.title, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
drawScreen(msg.title, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
||||||
|
|
||||||
stopCallBuzz();
|
stopCallBuzz();
|
||||||
if (!isQuiet()) {
|
if (!isQuiet()) {
|
||||||
|
@ -260,10 +274,10 @@ const showCall = function(ovr, msg) {
|
||||||
Bangle.buzz(500);
|
Bangle.buzz(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawMessage(ovr, msg);
|
drawMessage(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
const next = function(ovr) {
|
const next = function() {
|
||||||
LOG("next");
|
LOG("next");
|
||||||
stopCallBuzz();
|
stopCallBuzz();
|
||||||
|
|
||||||
|
@ -277,7 +291,7 @@ const next = function(ovr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage(ovr, eventQueue[0]);
|
showMessage(eventQueue[0]);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -289,36 +303,36 @@ const stopCallBuzz = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawTriangleUp = function(ovr) {
|
const drawTriangleUp = function() {
|
||||||
ovr.fillPoly([ovr.getWidth()-10, 46,ovr.getWidth()-15, 56,ovr.getWidth()-5, 56]);
|
ovr.fillPoly([ovr.getWidth()-10, 46,ovr.getWidth()-15, 56,ovr.getWidth()-5, 56]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawTriangleDown = function(ovr) {
|
const drawTriangleDown = function() {
|
||||||
ovr.fillPoly([ovr.getWidth()-10, ovr.getHeight()-6, ovr.getWidth()-15, ovr.getHeight()-16, ovr.getWidth()-5, ovr.getHeight()-16]);
|
ovr.fillPoly([ovr.getWidth()-10, ovr.getHeight()-6, ovr.getWidth()-15, ovr.getHeight()-16, ovr.getWidth()-5, ovr.getHeight()-16]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const scrollUp = function(ovr) {
|
const scrollUp = function() {
|
||||||
const msg = eventQueue[0];
|
const msg = eventQueue[0];
|
||||||
LOG("up", msg);
|
LOG("up", msg);
|
||||||
|
|
||||||
if (!msg.CanscrollUp) return;
|
if (!msg.CanscrollUp) return;
|
||||||
|
|
||||||
msg.FirstLine = msg.FirstLine > 0 ? msg.FirstLine - 1 : 0;
|
msg.FirstLine = msg.FirstLine > 0 ? msg.FirstLine - 1 : 0;
|
||||||
drawMessage(ovr, msg);
|
drawMessage(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
const scrollDown = function(ovr) {
|
const scrollDown = function() {
|
||||||
const msg = eventQueue[0];
|
const msg = eventQueue[0];
|
||||||
LOG("down", msg);
|
LOG("down", msg);
|
||||||
|
|
||||||
if (!msg.CanscrollDown) return;
|
if (!msg.CanscrollDown) return;
|
||||||
|
|
||||||
msg.FirstLine = msg.FirstLine + 1;
|
msg.FirstLine = msg.FirstLine + 1;
|
||||||
drawMessage(ovr, msg);
|
drawMessage(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawMessage = function(ovr, msg) {
|
const drawMessage = function(msg) {
|
||||||
const getStringHeight = function(str){
|
const getStringHeight = function(str){
|
||||||
"jit";
|
"jit";
|
||||||
const metrics = ovr.stringMetrics(str);
|
const metrics = ovr.stringMetrics(str);
|
||||||
|
@ -341,9 +355,6 @@ const drawMessage = function(ovr, msg) {
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
ovr.setColor(ovr.theme.fg);
|
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
|
||||||
|
|
||||||
if (msg.FirstLine === undefined) msg.FirstLine = 0;
|
if (msg.FirstLine === undefined) msg.FirstLine = 0;
|
||||||
|
|
||||||
const padding = eventQueue.length > 1 ? (eventQueue.length > 3 ? 7 : 5) : 3;
|
const padding = eventQueue.length > 1 ? (eventQueue.length > 3 ? 7 : 5) : 3;
|
||||||
|
@ -375,8 +386,6 @@ const drawMessage = function(ovr, msg) {
|
||||||
LOG("Prepared message", msg);
|
LOG("Prepared message", msg);
|
||||||
|
|
||||||
ovr.setFont(msg.bodyFont);
|
ovr.setFont(msg.bodyFont);
|
||||||
ovr.setColor(ovr.theme.fg);
|
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
|
||||||
ovr.clearRect(2, yText, ovr.getWidth()-3, ovr.getHeight()-3);
|
ovr.clearRect(2, yText, ovr.getWidth()-3, ovr.getHeight()-3);
|
||||||
|
|
||||||
let xText = 4;
|
let xText = 4;
|
||||||
|
@ -410,36 +419,35 @@ const drawMessage = function(ovr, msg) {
|
||||||
ovr.drawLine(ovr.getWidth()*0.6,ovr.getHeight()-6,ovr.getWidth()-6,ovr.getHeight()-6);
|
ovr.drawLine(ovr.getWidth()*0.6,ovr.getHeight()-6,ovr.getWidth()-6,ovr.getHeight()-6);
|
||||||
}
|
}
|
||||||
|
|
||||||
ovr.setColor(ovr.theme.fg);
|
|
||||||
if (msg.FirstLine != 0) {
|
if (msg.FirstLine != 0) {
|
||||||
msg.CanscrollUp = true;
|
msg.CanscrollUp = true;
|
||||||
drawTriangleUp(ovr);
|
drawTriangleUp();
|
||||||
} else
|
} else
|
||||||
msg.CanscrollUp = false;
|
msg.CanscrollUp = false;
|
||||||
|
|
||||||
if (currentLine < msg.lines.length) {
|
if (currentLine < msg.lines.length) {
|
||||||
msg.CanscrollDown = true;
|
msg.CanscrollDown = true;
|
||||||
drawTriangleDown(ovr);
|
drawTriangleDown();
|
||||||
} else
|
} else
|
||||||
msg.CanscrollDown = false;
|
msg.CanscrollDown = false;
|
||||||
|
|
||||||
show(ovr);
|
show();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDragHandler = function(ovr){
|
const getDragHandler = function(){
|
||||||
return (e) => {
|
return (e) => {
|
||||||
if (e.dy > 0) {
|
if (e.dy > 0) {
|
||||||
scrollUp(ovr);
|
scrollUp();
|
||||||
} else if (e.dy < 0){
|
} else if (e.dy < 0){
|
||||||
scrollDown(ovr);
|
scrollDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTouchHandler = function(ovr){
|
const getTouchHandler = function(){
|
||||||
return (_, xy) => {
|
return (_, xy) => {
|
||||||
if (xy.y < ovry + DIVIDER){
|
if (xy.y < ovry + DIVIDER){
|
||||||
next(ovr);
|
next();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -571,14 +579,14 @@ const cleanup = function(){
|
||||||
|
|
||||||
const backup = {};
|
const backup = {};
|
||||||
|
|
||||||
const main = function(ovr, event) {
|
const main = function(event) {
|
||||||
LOG("Main", event.t);
|
LOG("Main", event.t);
|
||||||
const didBackup = backupHandlers();
|
const didBackup = backupHandlers();
|
||||||
|
|
||||||
if (!lockListener) {
|
if (!lockListener) {
|
||||||
lockListener = function (e){
|
lockListener = function (e){
|
||||||
updateClearingTimeout();
|
updateClearingTimeout();
|
||||||
drawBorder();
|
showMessage(eventQueue[eventQueue.length - 1]);
|
||||||
};
|
};
|
||||||
LOG("Add overlay lock handlers");
|
LOG("Add overlay lock handlers");
|
||||||
origOn.call(Bangle, 'lock', lockListener);
|
origOn.call(Bangle, 'lock', lockListener);
|
||||||
|
@ -591,17 +599,13 @@ const main = function(ovr, event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event !== undefined){
|
if (event !== undefined){
|
||||||
manageEvent(ovr, event);
|
manageEvent(event);
|
||||||
drawBorder(ovr);
|
|
||||||
} else {
|
} else {
|
||||||
LOG("No event given");
|
LOG("No event given");
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let ovr;
|
|
||||||
let clearingTimeout;
|
|
||||||
|
|
||||||
const updateClearingTimeout = ()=>{
|
const updateClearingTimeout = ()=>{
|
||||||
LOG("updateClearingTimeout");
|
LOG("updateClearingTimeout");
|
||||||
if (settings.autoclear <= 0)
|
if (settings.autoclear <= 0)
|
||||||
|
@ -614,7 +618,7 @@ const updateClearingTimeout = ()=>{
|
||||||
LOG("setNewTimeout");
|
LOG("setNewTimeout");
|
||||||
const event = eventQueue.pop();
|
const event = eventQueue.pop();
|
||||||
if (event)
|
if (event)
|
||||||
drawMessage(ovr, event);
|
showMessage(event);
|
||||||
if (eventQueue.length > 0){
|
if (eventQueue.length > 0){
|
||||||
LOG("still got elements");
|
LOG("still got elements");
|
||||||
updateClearingTimeout();
|
updateClearingTimeout();
|
||||||
|
@ -635,8 +639,8 @@ exports.message = function(type, event) {
|
||||||
if(event.handled) return;
|
if(event.handled) return;
|
||||||
if(event.messagesoverlayignore) return;
|
if(event.messagesoverlayignore) return;
|
||||||
|
|
||||||
bpp = 4;
|
bpp = 16;
|
||||||
if (process.memory().free < settings.lowmwm)
|
if (process.memory().free < settings.lowmem)
|
||||||
bpp = 1;
|
bpp = 1;
|
||||||
|
|
||||||
while (process.memory().free < settings.minfreemem && eventQueue.length > 0){
|
while (process.memory().free < settings.minfreemem && eventQueue.length > 0){
|
||||||
|
@ -652,12 +656,17 @@ exports.message = function(type, event) {
|
||||||
|
|
||||||
ovr.reset();
|
ovr.reset();
|
||||||
|
|
||||||
if (bpp == 4)
|
if (bpp > 1){
|
||||||
ovr.theme = g.theme;
|
ovr.theme = g.theme;
|
||||||
else
|
}
|
||||||
ovr.theme = { fg:0, bg:1, fg2:1, bg2:0, fgH:1, bgH:0 };
|
else {
|
||||||
|
if (g.theme.dark)
|
||||||
|
ovr.theme = { fg:1, bg:0, fg2:0, bg2:1, fgH:0, bgH:1 };
|
||||||
|
else
|
||||||
|
ovr.theme = { fg:0, bg:1, fg2:1, bg2:0, fgH:1, bgH:0 };
|
||||||
|
}
|
||||||
|
|
||||||
main(ovr, event);
|
main(event);
|
||||||
|
|
||||||
updateClearingTimeout();
|
updateClearingTimeout();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue