Refactoring, Improved Description

master
OmegaRogue 2020-12-03 22:03:56 +01:00
parent 01dc955206
commit 2d82d8dbfe
3 changed files with 88 additions and 83 deletions

View File

@ -1421,8 +1421,8 @@
"name": "Digital Assistant, not EDITH", "name": "Digital Assistant, not EDITH",
"shortName": "DANE", "shortName": "DANE",
"icon": "app.png", "icon": "app.png",
"version": "0.10", "version": "0.11",
"description": "A Watchface inspired by Tony Stark's EDITH", "description": "A Watchface inspired by Tony Stark's EDITH and based on https://arwes.dev/",
"tags": "clock", "tags": "clock",
"type": "clock", "type": "clock",
"allow_emulator": true, "allow_emulator": true,

View File

@ -6,3 +6,4 @@
0.08: Removed Image, Reduced RAM usage 0.08: Removed Image, Reduced RAM usage
0.09: Added Unix Time 0.09: Added Unix Time
0.10: Added Counter, Added Battery Display 0.10: Added Counter, Added Battery Display
0.11: Code Refactoring, Improved Description

View File

@ -6,13 +6,13 @@ const smallFontSize = 2;
const yOffset = 23; const yOffset = 23;
const width = g.getWidth(); const width = g.getWidth();
const height = g.getHeight(); const height = g.getHeight();
const xyCenter = width/2+4; const xyCenter = width / 2 + 4;
const cornerSize = 14; const cornerSize = 14;
const cornerOffset = 3; const cornerOffset = 3;
const borderWidth = 1; const borderWidth = 1;
const yposTime = 27+yOffset; const yposTime = 27 + yOffset;
const yposDate = 65+yOffset+12; const yposDate = 65 + yOffset + 12;
const yposCounter = 58+yOffset+35+40; const yposCounter = 58 + yOffset + 35 + 40;
const mainColor = "#26dafd"; const mainColor = "#26dafd";
const mainColorDark = "#029dbb"; const mainColorDark = "#029dbb";
@ -31,6 +31,7 @@ const alert = "#ff0000";
// const alertLight = "#0f0606"; // const alertLight = "#0f0606";
let count = 100; let count = 100;
let oldCount = count;
// function getImg() { // function getImg() {
@ -46,67 +47,70 @@ let count = 100;
// } // }
function drawTopLeftCorner(x, y) {
function drawTopLeftCorner(x,y) {
g.setColor(mainColor); g.setColor(mainColor);
const x1 = x - cornerOffset; const x1 = x - cornerOffset;
const y1 = y - cornerOffset; const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1+cornerSize); g.fillRect(x1, y1, x1 + cornerSize, y1 + cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y+cornerSize-cornerOffset); g.fillRect(x, y, x + cornerSize - cornerOffset, y + cornerSize - cornerOffset);
} }
function drawTopRightCorner(x,y) {
function drawTopRightCorner(x, y) {
g.setColor(mainColor); g.setColor(mainColor);
const x1 = x + cornerOffset; const x1 = x + cornerOffset;
const y1 = y - cornerOffset; const y1 = y - cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1+cornerSize); g.fillRect(x1, y1, x1 - cornerSize, y1 + cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x-cornerSize-cornerOffset,y+cornerSize-cornerOffset); g.fillRect(x, y, x - cornerSize - cornerOffset, y + cornerSize - cornerOffset);
} }
function drawBottomLeftCorner(x,y) {
function drawBottomLeftCorner(x, y) {
g.setColor(mainColor); g.setColor(mainColor);
const x1 = x - cornerOffset; const x1 = x - cornerOffset;
const y1 = y + cornerOffset; const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1+cornerSize,y1-cornerSize); g.fillRect(x1, y1, x1 + cornerSize, y1 - cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x+cornerSize-cornerOffset,y-cornerSize+cornerOffset); g.fillRect(x, y, x + cornerSize - cornerOffset, y - cornerSize + cornerOffset);
} }
function drawBottomRightCorner(x,y) {
function drawBottomRightCorner(x, y) {
g.setColor(mainColor); g.setColor(mainColor);
const x1 = x + cornerOffset; const x1 = x + cornerOffset;
const y1 = y + cornerOffset; const y1 = y + cornerOffset;
g.fillRect(x1,y1,x1-cornerSize,y1-cornerSize); g.fillRect(x1, y1, x1 - cornerSize, y1 - cornerSize);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x,y,x-cornerSize+cornerOffset,y-cornerSize+cornerOffset); g.fillRect(x, y, x - cornerSize + cornerOffset, y - cornerSize + cornerOffset);
} }
function drawFrame(x1,y1,x2,y2) { function drawFrame(x1, y1, x2, y2) {
drawTopLeftCorner(x1,y1); drawTopLeftCorner(x1, y1);
drawTopRightCorner(x2,y1); drawTopRightCorner(x2, y1);
drawBottomLeftCorner(x1,y2); drawBottomLeftCorner(x1, y2);
drawBottomRightCorner(x2,y2); drawBottomRightCorner(x2, y2);
g.setColor(mainColorDark); g.setColor(mainColorDark);
g.drawRect(x1,y1,x2,y2); g.drawRect(x1, y1, x2, y2);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth); g.fillRect(x1 + borderWidth, y1 + borderWidth, x2 - borderWidth, y2 - borderWidth);
}
function drawTopFrame(x1,y1,x2,y2) {
drawBottomLeftCorner(x1,y2);
drawBottomRightCorner(x2,y2);
g.setColor(mainColorDark);
g.drawRect(x1,y1,x2,y2);
g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth);
} }
function drawFrameNoCorners(x1,y1,x2,y2) { function drawTopFrame(x1, y1, x2, y2) {
drawBottomLeftCorner(x1, y2);
drawBottomRightCorner(x2, y2);
g.setColor(mainColorDark); g.setColor(mainColorDark);
g.drawRect(x1,y1,x2,y2); g.drawRect(x1, y1, x2, y2);
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(x1+borderWidth,y1+borderWidth,x2-borderWidth,y2-borderWidth); g.fillRect(x1 + borderWidth, y1 + borderWidth, x2 - borderWidth, y2 - borderWidth);
} }
function drawFrameNoCorners(x1, y1, x2, y2) {
g.setColor(mainColorDark);
g.drawRect(x1, y1, x2, y2);
g.setColor("#000000");
g.fillRect(x1 + borderWidth, y1 + borderWidth, x2 - borderWidth, y2 - borderWidth);
}
// function drawBottomFrame(x1,y1,x2,y2) { // function drawBottomFrame(x1,y1,x2,y2) {
// drawTopLeftCorner(x1,y1); // drawTopLeftCorner(x1,y1);
// drawTopRightCorner(x2,y1); // drawTopRightCorner(x2,y1);
@ -121,8 +125,6 @@ function drawFrameNoCorners(x1,y1,x2,y2) {
// } // }
function drawTimeText(d) { function drawTimeText(d) {
const da = d.toString().split(" "); const da = d.toString().split(" ");
// var dutc = getUTCTime(d); // var dutc = getUTCTime(d);
@ -138,20 +140,21 @@ function drawTimeText(d) {
g.setFont(font, unixTimeFontSize); g.setFont(font, unixTimeFontSize);
g.setColor(secondaryColor); g.setColor(secondaryColor);
g.drawString(`${unix}`, xyCenter, yposTime +22, true); g.drawString(`${unix}`, xyCenter, yposTime + 22, true);
g.setFont(font, smallFontSize); g.setFont(font, smallFontSize);
} }
function drawDateText(d) { function drawDateText(d) {
g.setColor(mainColor); g.setColor(mainColor);
g.setFont(font, dateFontSize); g.setFont(font, dateFontSize);
g.drawString(`${d.getDate()}.${d.getMonth()+1}.${d.getFullYear()}`, xyCenter, yposDate, true); g.drawString(`${d.getDate()}.${d.getMonth() + 1}.${d.getFullYear()}`, xyCenter, yposDate, true);
} }
function drawCounterText() { function drawCounterText() {
if(count>999) count = 999; if (count > 255) count = 255;
if(count<0) count = 0; if (count < 0) count = 0;
g.setColor("#000000"); g.setColor("#000000");
g.fillRect(37,58+yOffset+36,203,58+80+yOffset+34); g.fillRect(37, 58 + yOffset + 36, 203, 58 + 80 + yOffset + 34);
g.setFontAlign(0, 0); g.setFontAlign(0, 0);
g.setColor(alert); g.setColor(alert);
g.setFont(font, 8); g.setFont(font, 8);
@ -170,25 +173,25 @@ function levelColor(l) {
function drawBattery() { function drawBattery() {
const l = E.getBattery(), c = levelColor(l); const l = E.getBattery(), c = levelColor(l);
const xl = 45+l*(194-46)/100; count = l;
g.setColor(c).fillRect(46,58+80+yOffset+37,xl, height-5); const xl = 45 + l * (194 - 46) / 100;
g.setColor(c).fillRect(46, 58 + 80 + yOffset + 37, xl, height - 5);
} }
function drawClock() { function drawClock() {
// main frame // main frame
drawFrame(3,10+yOffset,width-3,height-3); drawFrame(3, 10 + yOffset, width - 3, height - 3);
// time frame // time frame
drawTopFrame(20,10+yOffset,220,58+yOffset); drawTopFrame(20, 10 + yOffset, 220, 58 + yOffset);
// date frame // date frame
drawTopFrame(28,58+yOffset,212,58+yOffset+35); drawTopFrame(28, 58 + yOffset, 212, 58 + yOffset + 35);
// counter frame // counter frame
drawTopFrame(36,58+yOffset+35,204,58+80+yOffset+35); drawTopFrame(36, 58 + yOffset + 35, 204, 58 + 80 + yOffset + 35);
// battery frame // battery frame
drawFrameNoCorners(44,58+80+yOffset+35,196, height-3); drawFrameNoCorners(44, 58 + 80 + yOffset + 35, 196, height - 3);
updateClock(); updateClock();
@ -196,6 +199,7 @@ function drawClock() {
// const img = makeImg(); // const img = makeImg();
// g.drawImage(img,width/2-(img.width/2),height/2); // g.drawImage(img,width/2-(img.width/2),height/2);
} }
function updateClock() { function updateClock() {
g.setFontAlign(0, 0); g.setFontAlign(0, 0);
const date = new Date(); const date = new Date();
@ -206,12 +210,11 @@ function updateClock() {
} }
Bangle.on('lcdPower', function(on) { Bangle.on('lcdPower', function (on) {
if (on) drawClock(); if (on) drawClock();
}); });
g.clear(); g.clear();
Bangle.loadWidgets(); Bangle.loadWidgets();
@ -220,17 +223,18 @@ Bangle.drawWidgets();
drawClock(); drawClock();
setWatch(Bangle.showLauncher, BTN2, {repeat: false, edge: "falling"});
setWatch(Bangle.showLauncher, BTN2, {repeat:false,edge:"falling"}); // setWatch(function () {
// count++;
setWatch(function() { // drawCounterText();
count+=1; // }, BTN1, {repeat: true, edge: "falling"});
drawCounterText(); // setWatch(function () {
}, BTN1, {repeat:true,edge:"falling"}); // count--;
setWatch(function() { // drawCounterText();
count--; // }, BTN3, {repeat: true, edge: "falling"});
drawCounterText();
}, BTN3, {repeat:true,edge:"falling"});
// refesh every 100 milliseconds // refesh every 100 milliseconds
setInterval(updateClock, 500); setInterval(updateClock, 500);