Add theme support and unknown icon

pull/814/head
Ben Whittaker 2021-09-18 13:59:22 -04:00
parent cc2e1bbd5f
commit 2f3c996396
5 changed files with 32 additions and 25 deletions

View File

@ -571,7 +571,7 @@
{ "id": "weather", { "id": "weather",
"name": "Weather", "name": "Weather",
"icon": "icon.png", "icon": "icon.png",
"version":"0.06", "version":"0.07",
"description": "Show Gadgetbridge weather report", "description": "Show Gadgetbridge weather report",
"readme": "readme.md", "readme": "readme.md",
"tags": "widget,outdoors", "tags": "widget,outdoors",

View File

@ -3,3 +3,4 @@
0.04: Adjust "weather unknown" message according to Bluetooth connection. 0.04: Adjust "weather unknown" message according to Bluetooth connection.
0.05: Add wind direction. 0.05: Add wind direction.
0.06: Use setUI for launcher. 0.06: Use setUI for launcher.
0.07: Add theme support and unknown icon.

View File

@ -12,12 +12,12 @@
function draw() { function draw() {
let w = weather.current; let w = weather.current;
g.reset(); g.reset();
g.setColor(0).fillRect(0, 24, 239, 239); g.clearRect(0, 24, 239, 239);
weather.drawIcon(w.txt, 65, 90, 55); weather.drawIcon(w.txt, 65, 90, 55);
const locale = require("locale"); const locale = require("locale");
g.setColor(-1); g.reset();
const temp = locale.temp(w.temp-273.15).match(/^(\D*\d*)(.*)$/); const temp = locale.temp(w.temp-273.15).match(/^(\D*\d*)(.*)$/);
let width = g.setFont("Vector", 40).stringWidth(temp[1]); let width = g.setFont("Vector", 40).stringWidth(temp[1]);
@ -54,8 +54,8 @@
if (!weather.current || !weather.current.time) return; if (!weather.current || !weather.current.time) return;
let text = `Last update received ${formatDuration(Date.now() - weather.current.time)} ago`; let text = `Last update received ${formatDuration(Date.now() - weather.current.time)} ago`;
g.reset(); g.reset();
g.setColor(0).fillRect(0, 202, 239, 210); g.clearRect(0, 202, 239, 210);
g.setColor(-1).setFont("6x8", 1).setFontAlign(0, 0, 0); g.setFont("6x8", 1).setFontAlign(0, 0, 0);
g.drawString(text, 120, 206); g.drawString(text, 120, 206);
} }

View File

@ -68,13 +68,13 @@ setCurrentWeather(storage.readJSON('weather.json')||{});
exports.drawIcon = function(cond, x, y, r) { exports.drawIcon = function(cond, x, y, r) {
function drawSun(x, y, r) { function drawSun(x, y, r) {
g.setColor("#FF7700"); g.setColor(g.theme.dark ? "#FE0" : "#FC0");
g.fillCircle(x, y, r); g.fillCircle(x, y, r);
} }
function drawCloud(x, y, r, c) { function drawCloud(x, y, r, c) {
const u = r/12; const u = r/12;
if (c==null) c = "#EEEEEE"; if (c==null) c = g.theme.dark ? "#BBB" : "#AAA";
g.setColor(c); g.setColor(c);
g.fillCircle(x-8*u, y+3*u, 4*u); g.fillCircle(x-8*u, y+3*u, 4*u);
g.fillCircle(x-4*u, y-2*u, 5*u); g.fillCircle(x-4*u, y-2*u, 5*u);
@ -91,7 +91,7 @@ exports.drawIcon = function(cond, x, y, r) {
} }
function drawBrokenClouds(x, y, r) { function drawBrokenClouds(x, y, r) {
drawCloud(x+1/8*r, y-1/8*r, 7/8*r, "#777777"); drawCloud(x+1/8*r, y-1/8*r, 7/8*r, "#777");
drawCloud(x-1/8*r, y+1/8*r, 7/8*r); drawCloud(x-1/8*r, y+1/8*r, 7/8*r);
} }
@ -101,24 +101,25 @@ exports.drawIcon = function(cond, x, y, r) {
} }
function drawRainLines(x, y, r) { function drawRainLines(x, y, r) {
g.setColor("#FFFFFF"); g.setColor(g.theme.dark ? "#0CF" : "#07F");
const y1 = y+1/2*r; const y1 = y+1/2*r;
const y2 = y+1*r; const y2 = y+1*r;
g.fillPoly([
x-6/12*r+1, y1, g.fillPolyAA([
x-8/12*r+1, y2, x-6/12*r, y1,
x-8/12*r, y2,
x-7/12*r, y2, x-7/12*r, y2,
x-5/12*r, y1, x-5/12*r, y1,
]); ]);
g.fillPoly([ g.fillPolyAA([
x-2/12*r+1, y1, x-2/12*r, y1,
x-4/12*r+1, y2, x-4/12*r, y2,
x-3/12*r, y2, x-3/12*r, y2,
x-1/12*r, y1, x-1/12*r, y1,
]); ]);
g.fillPoly([ g.fillPolyAA([
x+2/12*r+1, y1, x+2/12*r, y1,
x+0/12*r+1, y2, x+0/12*r, y2,
x+1/12*r, y2, x+1/12*r, y2,
x+3/12*r, y1, x+3/12*r, y1,
]); ]);
@ -136,7 +137,7 @@ exports.drawIcon = function(cond, x, y, r) {
function drawThunderstorm(x, y, r) { function drawThunderstorm(x, y, r) {
function drawLightning(x, y, r) { function drawLightning(x, y, r) {
g.setColor("#FF7700"); g.setColor(g.theme.dark ? "#FE0" : "#FC0");
g.fillPoly([ g.fillPoly([
x-2/6*r, y-r, x-2/6*r, y-r,
x-4/6*r, y+1/6*r, x-4/6*r, y+1/6*r,
@ -164,7 +165,7 @@ exports.drawIcon = function(cond, x, y, r) {
} }
} }
g.setColor("#FFFFFF"); g.setColor(g.theme.dark ? "#FFF" : "#CCC");
const w = 1/12*r; const w = 1/12*r;
for(let i = 0; i<=6; ++i) { for(let i = 0; i<=6; ++i) {
const points = [ const points = [
@ -199,7 +200,7 @@ exports.drawIcon = function(cond, x, y, r) {
[-0.2, 0.3], [-0.2, 0.3],
]; ];
g.setColor("#FFFFFF"); g.setColor(g.theme.dark ? "#FFF" : "#CCC");
for(let i = 0; i<5; ++i) { for(let i = 0; i<5; ++i) {
g.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r, g.fillRect(x+layers[i][0]*r, y+(0.4*i-0.9)*r, x+layers[i][1]*r,
y+(0.4*i-0.7)*r-1); y+(0.4*i-0.7)*r-1);
@ -208,6 +209,11 @@ exports.drawIcon = function(cond, x, y, r) {
} }
} }
function drawUnknown(x, y, r) {
drawCloud(x, y, r, "#777");
g.setColor(g.theme.fg).setFontAlign(0, 0).setFont('Vector', r*2).drawString("?", x+r/10, y+r/6);
}
function chooseIcon(condition) { function chooseIcon(condition) {
if (!condition) return () => {}; if (!condition) return () => {};
condition = condition.toLowerCase(); condition = condition.toLowerCase();
@ -225,7 +231,7 @@ exports.drawIcon = function(cond, x, y, r) {
if (condition.includes("few clouds")) return drawFewClouds; if (condition.includes("few clouds")) return drawFewClouds;
if (condition.includes("scattered clouds")) return drawCloud; if (condition.includes("scattered clouds")) return drawCloud;
if (condition.includes("clouds")) return drawBrokenClouds; if (condition.includes("clouds")) return drawBrokenClouds;
return drawMist; return drawUnknown;
} }
chooseIcon(cond)(x, y, r); chooseIcon(cond)(x, y, r);

View File

@ -5,16 +5,16 @@
const w = weather.current; const w = weather.current;
if (!w) return; if (!w) return;
g.reset(); g.reset();
g.setColor(0).fillRect(this.x, this.y, this.x+this.width-1, this.y+23); g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
if (w.txt) { if (w.txt) {
weather.drawIcon(w.txt, this.x+10, this.y+8, 7.5); weather.drawIcon(w.txt, this.x+10, this.y+8, 7.5);
} }
if (w.temp) { if (w.temp) {
let t = require('locale').temp(w.temp-273.15); // applies conversion let t = require('locale').temp(w.temp-273.15); // applies conversion
t = t.match(/[\d\-]*/)[0]; // but we have no room for units t = t.match(/[\d\-]*/)[0]; // but we have no room for units
g.reset();
g.setFontAlign(0, 1); // center horizontally at bottom of widget g.setFontAlign(0, 1); // center horizontally at bottom of widget
g.setFont('6x8', 1); g.setFont('6x8', 1);
g.setColor(-1);
g.drawString(t, this.x+10, this.y+24); g.drawString(t, this.x+10, this.y+24);
} }
} }