messagesoverlay - Refactor rendering code, only render short messages centered
parent
ccdf14e3b6
commit
5485d270cf
|
|
@ -11,7 +11,7 @@ var settings = Object.assign(
|
||||||
settings = Object.assign({
|
settings = Object.assign({
|
||||||
fontSmall:"6x8",
|
fontSmall:"6x8",
|
||||||
fontMedium:"Vector:14",
|
fontMedium:"Vector:14",
|
||||||
fontBig:"Vector:20",
|
fontBig:g.getFonts().includes("Vector") ? "Vector:20" : "6x8:3",
|
||||||
fontLarge:"Vector:30",
|
fontLarge:"Vector:30",
|
||||||
reemit: true
|
reemit: true
|
||||||
}, settings);
|
}, settings);
|
||||||
|
|
@ -107,6 +107,8 @@ let drawScreen = function(ovr, title, titleFont, src, iconcolor, icon){
|
||||||
ovr.setBgColor(ovr.theme.bg2);
|
ovr.setBgColor(ovr.theme.bg2);
|
||||||
ovr.clearRect(2,2,ovr.getWidth()-3,37);
|
ovr.clearRect(2,2,ovr.getWidth()-3,37);
|
||||||
|
|
||||||
|
ovr.drawRect(2,38,ovr.getWidth()-2,39);
|
||||||
|
|
||||||
ovr.setColor(ovr.theme.fg2);
|
ovr.setColor(ovr.theme.fg2);
|
||||||
ovr.setFont(settings.fontSmall);
|
ovr.setFont(settings.fontSmall);
|
||||||
ovr.setFontAlign(0,-1);
|
ovr.setFontAlign(0,-1);
|
||||||
|
|
@ -139,7 +141,6 @@ let drawScreen = function(ovr, title, titleFont, src, iconcolor, icon){
|
||||||
|
|
||||||
let showMessage = function(ovr, msg) {
|
let showMessage = function(ovr, msg) {
|
||||||
LOG("showMessage");
|
LOG("showMessage");
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
|
||||||
|
|
||||||
if (typeof msg.CanscrollDown === "undefined")
|
if (typeof msg.CanscrollDown === "undefined")
|
||||||
msg.CanscrollDown = false;
|
msg.CanscrollDown = false;
|
||||||
|
|
@ -162,12 +163,12 @@ let showMessage = function(ovr, msg) {
|
||||||
|
|
||||||
drawScreen(ovr, title, titleFont, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
drawScreen(ovr, title, titleFont, msg.src || /*LANG*/ "Message", require("messageicons").getColor(msg), require("messageicons").getImage(msg));
|
||||||
|
|
||||||
|
drawMessage(ovr, msg);
|
||||||
|
|
||||||
if (!isQuiet() && msg.new) {
|
if (!isQuiet() && msg.new) {
|
||||||
msg.new = false;
|
msg.new = false;
|
||||||
Bangle.buzz();
|
Bangle.buzz();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawMessage(ovr, msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawBorder = function(img) {
|
let drawBorder = function(img) {
|
||||||
|
|
@ -251,12 +252,10 @@ let stopCallBuzz = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawTriangleUp = function(ovr) {
|
let drawTriangleUp = function(ovr) {
|
||||||
ovr.reset();
|
|
||||||
ovr.fillPoly([ovr.getWidth()-9, 46,ovr.getWidth()-14, 56,ovr.getWidth()-4, 56]);
|
ovr.fillPoly([ovr.getWidth()-9, 46,ovr.getWidth()-14, 56,ovr.getWidth()-4, 56]);
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawTriangleDown = function(ovr) {
|
let drawTriangleDown = function(ovr) {
|
||||||
ovr.reset();
|
|
||||||
ovr.fillPoly([ovr.getWidth()-9, ovr.getHeight()-6, ovr.getWidth()-14, ovr.getHeight()-16, ovr.getWidth()-4, ovr.getHeight()-16]);
|
ovr.fillPoly([ovr.getWidth()-9, ovr.getHeight()-6, ovr.getWidth()-14, ovr.getHeight()-16, ovr.getWidth()-4, ovr.getHeight()-16]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -292,35 +291,55 @@ let scrollDown = function(ovr) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let drawMessage = function(ovr, msg) {
|
let drawMessage = function(ovr, msg) {
|
||||||
let MyWrapString = function(str, maxWidth) {
|
let wrapString = function(str, maxWidth) {
|
||||||
str = str.replace("\r\n", "\n").replace("\r", "\n");
|
str = str.replace("\r\n", "\n").replace("\r", "\n");
|
||||||
return ovr.wrapString(str, maxWidth);
|
return ovr.wrapString(str, maxWidth);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof msg.FirstLine === "undefined") msg.FirstLine = 0;
|
if (typeof msg.FirstLine === "undefined") msg.FirstLine = 0;
|
||||||
|
|
||||||
let bodyFont = typeof msg.bodyFont === "undefined" ? settings.fontMedium : msg.bodyFont;
|
let padding = eventQueue.length > 1 ? (eventQueue.length > 3 ? 7 : 5) : 3;
|
||||||
let Padding = 3 + eventQueue.length > 1 ? 2 : 0;
|
|
||||||
if (typeof msg.lines === "undefined") {
|
|
||||||
ovr.setFont(bodyFont);
|
|
||||||
msg.lines = MyWrapString(msg.body, ovr.getWidth() - (Padding * 2));
|
|
||||||
if (msg.lines.length <= 2) {
|
|
||||||
bodyFont = ovr.getFonts().includes("Vector") ? "Vector:20" : "6x8:3";
|
|
||||||
ovr.setFont(bodyFont);
|
|
||||||
msg.lines = MyWrapString(msg.body, ovr.getWidth() - (Padding * 2));
|
|
||||||
msg.bodyFont = bodyFont;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let NumLines = 7;
|
|
||||||
|
|
||||||
let linesToPrint = (msg.lines.length > NumLines) ? msg.lines.slice(msg.FirstLine, msg.FirstLine + NumLines) : msg.lines;
|
|
||||||
|
|
||||||
let yText = 40;
|
let yText = 40;
|
||||||
|
let yLine = yText + 3;
|
||||||
|
|
||||||
|
if (typeof msg.lines === "undefined") {
|
||||||
|
let bodyFont = settings.fontBig;
|
||||||
|
ovr.setFont(bodyFont);
|
||||||
|
msg.lines = wrapString(msg.body, ovr.getWidth() - 4 - padding);
|
||||||
|
if (msg.lines.length * (ovr.getFontHeight() + 1) > ovr.getHeight() - yLine - padding) {
|
||||||
|
bodyFont = settings.fontMedium;
|
||||||
|
ovr.setFont(bodyFont);
|
||||||
|
msg.lines = wrapString(msg.body, ovr.getWidth() - 4 - padding);
|
||||||
|
}
|
||||||
|
msg.bodyFont = bodyFont;
|
||||||
|
}
|
||||||
|
|
||||||
|
ovr.setFont(msg.bodyFont);
|
||||||
|
|
||||||
|
let textHeight = ovr.getFontHeight() + 1;
|
||||||
|
|
||||||
|
let numLines = Math.floor((ovr.getHeight() - yText - padding - 4)/textHeight);
|
||||||
|
|
||||||
|
let linesToPrint = (msg.lines.length > numLines) ? msg.lines.slice(msg.FirstLine, msg.FirstLine + numLines + 1) : msg.lines;
|
||||||
|
|
||||||
ovr.setBgColor(ovr.theme.bg);
|
ovr.setBgColor(ovr.theme.bg);
|
||||||
ovr.setColor(ovr.theme.fg);
|
ovr.setColor(ovr.theme.fg);
|
||||||
ovr.clearRect(2, yText, ovrw-3, ovrh-3);
|
ovr.clearRect(2, yText, ovr.getWidth()-3, ovr.getHeight()-3);
|
||||||
|
|
||||||
|
let xText = 4;
|
||||||
|
|
||||||
|
if (msg.bodyFont == settings.fontBig) {
|
||||||
|
ovr.setFontAlign(0, -1);
|
||||||
|
xText = Math.round(ovr.getWidth() / 2 - (padding - 3) / 2) + 1;
|
||||||
|
yLine = (ovr.getHeight() + yLine) / 2 - (textHeight * msg.lines.length / 2);
|
||||||
|
} else
|
||||||
|
ovr.setFontAlign(-1, -1);
|
||||||
|
|
||||||
|
linesToPrint.forEach((line, i) => {
|
||||||
|
ovr.drawString(line, xText, yLine);
|
||||||
|
yLine += textHeight;
|
||||||
|
});
|
||||||
|
|
||||||
if (eventQueue.length > 1){
|
if (eventQueue.length > 1){
|
||||||
ovr.drawLine(ovr.getWidth()-4,ovr.getHeight()/2,ovr.getWidth()-4,ovr.getHeight()-4);
|
ovr.drawLine(ovr.getWidth()-4,ovr.getHeight()/2,ovr.getWidth()-4,ovr.getHeight()-4);
|
||||||
|
|
@ -331,24 +350,7 @@ let 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
let xText = Padding;
|
ovr.setColor(ovr.theme.fg2);
|
||||||
yText += Padding;
|
|
||||||
ovr.setFont(bodyFont);
|
|
||||||
let HText = ovr.getFontHeight();
|
|
||||||
|
|
||||||
yText = ((ovrh - yText) / 2) - (linesToPrint.length * HText / 2) + yText;
|
|
||||||
|
|
||||||
if (linesToPrint.length <= 3) {
|
|
||||||
ovr.setFontAlign(0, -1);
|
|
||||||
xText = ovr.getWidth() / 2;
|
|
||||||
} else
|
|
||||||
ovr.setFontAlign(-1, -1);
|
|
||||||
|
|
||||||
|
|
||||||
linesToPrint.forEach((line, i) => {
|
|
||||||
ovr.drawString(line, xText, yText + HText * i);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (msg.FirstLine != 0) {
|
if (msg.FirstLine != 0) {
|
||||||
msg.CanscrollUp = true;
|
msg.CanscrollUp = true;
|
||||||
drawTriangleUp(ovr);
|
drawTriangleUp(ovr);
|
||||||
|
|
@ -360,6 +362,7 @@ let drawMessage = function(ovr, msg) {
|
||||||
drawTriangleDown(ovr);
|
drawTriangleDown(ovr);
|
||||||
} else
|
} else
|
||||||
msg.CanscrollDown = false;
|
msg.CanscrollDown = false;
|
||||||
|
|
||||||
show(ovr);
|
show(ovr);
|
||||||
if (!isQuiet()) Bangle.setLCDPower(1);
|
if (!isQuiet()) Bangle.setLCDPower(1);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue