Add new draw styles, tidy up draw functionality

master
Gordon Williams 2020-06-24 10:13:00 +01:00
parent c449a258f1
commit 7647a7a921
4 changed files with 45 additions and 27 deletions

View File

@ -1333,7 +1333,7 @@
"name": "Numerals Clock", "name": "Numerals Clock",
"shortName": "Numerals Clock", "shortName": "Numerals Clock",
"icon": "numerals.png", "icon": "numerals.png",
"version":"0.07", "version":"0.08",
"description": "A simple big numerals clock", "description": "A simple big numerals clock",
"tags": "numerals,clock", "tags": "numerals,clock",
"type":"clock", "type":"clock",

View File

@ -4,4 +4,5 @@
0.04: Don't overwrite existing settings on app update 0.04: Don't overwrite existing settings on app update
0.05: Fix settings issue 0.05: Fix settings issue
0.06: Improve rendering of Numeral 1, fix issue with alarms not showing up 0.06: Improve rendering of Numeral 1, fix issue with alarms not showing up
0.07: Add date on touch and some improvements (see settings and readme) 0.07: Add date on touch and some improvements (see settings and readme)
0.08: Add new draw styles, tidy up draw functionality

View File

@ -8,7 +8,7 @@
var numerals = { var numerals = {
0:[[9,1,82,1,90,9,90,92,82,100,9,100,1,92,1,9],[30,25,61,25,69,33,69,67,61,75,30,75,22,67,22,33]], 0:[[9,1,82,1,90,9,90,92,82,100,9,100,1,92,1,9],[30,25,61,25,69,33,69,67,61,75,30,75,22,67,22,33]],
1:[[50,1,82,1,90,9,90,92,82,100,73,100,65,92,65,27,50,27,42,19,42,9]], 1:[[50,1,82,1,90,9,90,92,82,100,73,100,65,92,65,27,50,27,42,19,42,9]],
2:[[9,1,82,1,90,9,90,53,82,61,21,61,21,74,82,74,90,82,90,92,82,100,9,100,1,92,1,48,9,40,70,40,70,27,9,27,1,19,1,9]], 2:[[9,1,82,1,90,9,90,53,82,61,21,61,21,74,82,74,90,82,90,92,82,100,9,100,1,92,1,48,9,40,70,40,70,27,9,27,1,19,1,9]],
3:[[9,1,82,1,90,9,90,92,82,100,9,100,1,92,1,82,9,74,70,74,70,61,9,61,1,53,1,48,9,40,70,40,70,27,9,27,1,19,1,9]], 3:[[9,1,82,1,90,9,90,92,82,100,9,100,1,92,1,82,9,74,70,74,70,61,9,61,1,53,1,48,9,40,70,40,70,27,9,27,1,19,1,9]],
4:[[9,1,14,1,22,9,22,36,69,36,69,9,77,1,82,1,90,9,90,92,82,100,78,100,70,92,70,61,9,61,1,53,1,9]], 4:[[9,1,14,1,22,9,22,36,69,36,69,9,77,1,82,1,90,9,90,92,82,100,78,100,70,92,70,61,9,61,1,53,1,9]],
@ -24,18 +24,33 @@ var _mCol = ["#55ff55","#ffffff","#00EFEF","#FFBF00"];
var _rCol = 0; var _rCol = 0;
var interval = 0; var interval = 0;
const REFRESH_RATE = 10E3; const REFRESH_RATE = 10E3;
var drawFuncs = {
fill : function(poly,isHole){
if (isHole) g.setColor(0);
g.fillPoly(poly,true);
},
framefill : function(poly,isHole){
var c = g.getColor();
g.setColor(isHole ? 0 : ((c&0b1111011111011110)>>1)); // 16 bit half bright
g.fillPoly(poly,true);
g.setColor(c);
g.drawPoly(poly,true);
},
frame : function(poly,isHole){
g.drawPoly(poly,true);
},
thickframe : function(poly,isHole){
g.drawPoly(poly,true);
g.drawPoly(translate(1,0,poly),true);
g.drawPoly(translate(1,1,poly),true);
g.drawPoly(translate(0,1,poly),true);
}
};
function translate(tx, ty, p){ function translate(tx, ty, p){
return p.map((x, i)=> x+((i%2)?ty:tx)); return p.map((x, i)=> x+((i&1)?ty:tx));
} }
function fill(poly){
return g.fillPoly(poly,true);
}
function frame(poly){
return g.drawPoly(poly,true);
}
let settings = require('Storage').readJSON('numerals.json',1); let settings = require('Storage').readJSON('numerals.json',1);
if (!settings) { if (!settings) {
@ -47,13 +62,13 @@ if (!settings) {
}; };
} }
function drawNum(num,col,x,y,func){ function drawNum(num,col,x,y,func,funcName){
g.setColor(col); g.setColor(col);
let tx = x*100+25; let tx = x*100+25;
let ty = y*104+32; let ty = y*104+32;
for (let i=0;i<numerals[num].length;i++){ for (let i=0;i<numerals[num].length;i++){
if (i>0) g.setColor((func==fill)?"#000000":col); g.setColor(col);
func(translate(tx,ty,numerals[num][i])); func(translate(tx,ty,numerals[num][i]), i>0);
} }
} }
@ -69,11 +84,13 @@ function draw(date){
l1 = ("0"+(_12hour?d.getHours()%12:d.getHours())).substr(-2); l1 = ("0"+(_12hour?d.getHours()%12:d.getHours())).substr(-2);
l2 = ("0"+d.getMinutes()).substr(-2); l2 = ("0"+d.getMinutes()).substr(-2);
} }
var drawFunc = drawFuncs[settings.drawMode];
if (drawFunc==undefined) drawFunc=drawFuncs.fill;
g.clearRect(0,24,240,240); g.clearRect(0,24,240,240);
drawNum(l1[0],_hCol[_rCol],0,0,eval(settings.drawMode)); drawNum(l1[0],_hCol[_rCol],0,0,drawFunc);
drawNum(l1[1],_hCol[_rCol],1,0,eval(settings.drawMode)); drawNum(l1[1],_hCol[_rCol],1,0,drawFunc);
drawNum(l2[0],_mCol[_rCol],0,1,eval(settings.drawMode)); drawNum(l2[0],_mCol[_rCol],0,1,drawFunc);
drawNum(l2[1],_mCol[_rCol],1,1,eval(settings.drawMode)); drawNum(l2[1],_mCol[_rCol],1,1,drawFunc);
} }
function setUpdateInt(set){ function setUpdateInt(set){
@ -100,4 +117,4 @@ Bangle.on('lcdPower', function(on){
}); });
Bangle.loadWidgets(); Bangle.loadWidgets();
Bangle.drawWidgets(); Bangle.drawWidgets();

View File

@ -1,5 +1,5 @@
(function(back) { (function(back) {
function updateSettings() { function updateSettings() {
storage.write('numerals.json', numeralsSettings); storage.write('numerals.json', numeralsSettings);
} }
function resetSettings() { function resetSettings() {
@ -14,26 +14,26 @@
let numeralsSettings = storage.readJSON('numerals.json',1); let numeralsSettings = storage.readJSON('numerals.json',1);
if (!numeralsSettings) resetSettings(); if (!numeralsSettings) resetSettings();
if (numeralsSettings.menuButton===undefined) numeralsSettings.menuButton=22; if (numeralsSettings.menuButton===undefined) numeralsSettings.menuButton=22;
let dm = ["fill","frame"]; let dm = ["fill","frame","framefill","thickframe"];
let col = ["rnd","r/g","y/w","o/c","b/y"]; let col = ["rnd","r/g","y/w","o/c","b/y"];
let btn = [[24,"BTN1"],[22,"BTN2"],[23,"BTN3"],[11,"BTN4"],[16,"BTN5"]]; let btn = [[24,"BTN1"],[22,"BTN2"],[23,"BTN3"],[11,"BTN4"],[16,"BTN5"]];
var menu={ var menu={
"" : { "title":"Numerals"}, "" : { "title":"Numerals"},
"Colors": { "Colors": {
value: 0|numeralsSettings.color, value: 0|numeralsSettings.color,
min:0,max:4, min:0,max:col.length-1,
format: v=>col[v], format: v=>col[v],
onchange: v=> { numeralsSettings.color=v; updateSettings();} onchange: v=> { numeralsSettings.color=v; updateSettings();}
}, },
"Draw mode": { "Draw": {
value: 0|dm.indexOf(numeralsSettings.drawMode), value: 0|dm.indexOf(numeralsSettings.drawMode),
min:0,max:1, min:0,max:dm.length-1,
format: v=>dm[v], format: v=>dm[v],
onchange: v=> { numeralsSettings.drawMode=dm[v]; updateSettings();} onchange: v=> { numeralsSettings.drawMode=dm[v]; updateSettings();}
}, },
"Menu button": { "Menu button": {
value: btn.findIndex(e=>e[0]==numeralsSettings.menuButton), value: btn.findIndex(e=>e[0]==numeralsSettings.menuButton),
min:0,max:4, min:0,max:btn.length-1,
format: v=>btn[v][1], format: v=>btn[v][1],
onchange: v=> { numeralsSettings.menuButton=btn[v][0]; updateSettings();} onchange: v=> { numeralsSettings.menuButton=btn[v][0]; updateSettings();}
}, },
@ -46,4 +46,4 @@
"< back": back "< back": back
}; };
E.showMenu(menu); E.showMenu(menu);
}) })