commit
1be93fe5e3
|
|
@ -1,3 +1,4 @@
|
||||||
0.01: New App!
|
0.01: New App!
|
||||||
0.02: Added decrement and touch functions
|
0.02: Added decrement and touch functions
|
||||||
0.03: Set color - ensures widgets don't end up coloring the counter's text
|
0.03: Set color - ensures widgets don't end up coloring the counter's text
|
||||||
|
0.04: Adopted for BangleJS 2
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,104 @@
|
||||||
var counter = 0;
|
var counter = 0;
|
||||||
|
const BANGLEJS2 = process.env.HWVERSION == 2;
|
||||||
|
|
||||||
|
if (BANGLEJS2) {
|
||||||
|
var drag;
|
||||||
|
var y = 45;
|
||||||
|
var x = 5;
|
||||||
|
} else {
|
||||||
|
var y = 100;
|
||||||
|
var x = 25;
|
||||||
|
}
|
||||||
|
|
||||||
function updateScreen() {
|
function updateScreen() {
|
||||||
g.clearRect(0, 50, 250, 150);
|
if (BANGLEJS2) {
|
||||||
g.setColor(0xFFFF);
|
g.clearRect(0, 50, 250, 130);
|
||||||
|
} else {
|
||||||
|
g.clearRect(0, 50, 250, 150);
|
||||||
|
}
|
||||||
|
g.setBgColor(g.theme.bg).setColor(g.theme.fg);
|
||||||
g.setFont("Vector",40).setFontAlign(0,0);
|
g.setFont("Vector",40).setFontAlign(0,0);
|
||||||
g.drawString(Math.floor(counter), g.getWidth()/2, 100);
|
g.drawString(Math.floor(counter), g.getWidth()/2, 100);
|
||||||
g.drawString('-', 45, 100);
|
if (!BANGLEJS2) {
|
||||||
g.drawString('+', 185, 100);
|
g.drawString('-', 45, 100);
|
||||||
|
g.drawString('+', 185, 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// add a count by using BTN1 or BTN5
|
if (BANGLEJS2) {
|
||||||
setWatch(() => {
|
setWatch(() => {
|
||||||
counter += 1;
|
counter = 0;
|
||||||
updateScreen();
|
updateScreen();
|
||||||
}, BTN1, {repeat:true});
|
}, BTN1, {repeat:true});
|
||||||
|
Bangle.on("drag", e => {
|
||||||
|
if (!drag) { // start dragging
|
||||||
|
drag = {x: e.x, y: e.y};
|
||||||
|
} else if (!e.b) { // released
|
||||||
|
const dx = e.x-drag.x, dy = e.y-drag.y;
|
||||||
|
drag = null;
|
||||||
|
if (Math.abs(dx)>Math.abs(dy)+10) {
|
||||||
|
// horizontal
|
||||||
|
if (dx < dy) {
|
||||||
|
//console.log("left " + dx + " " + dy);
|
||||||
|
} else {
|
||||||
|
//console.log("right " + dx + " " + dy);
|
||||||
|
}
|
||||||
|
} else if (Math.abs(dy)>Math.abs(dx)+10) {
|
||||||
|
// vertical
|
||||||
|
if (dx < dy) {
|
||||||
|
//console.log("down " + dx + " " + dy);
|
||||||
|
if (counter > 0) counter -= 1;
|
||||||
|
updateScreen();
|
||||||
|
} else {
|
||||||
|
//console.log("up " + dx + " " + dy);
|
||||||
|
counter += 1;
|
||||||
|
updateScreen();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//console.log("tap " + e.x + " " + e.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
setWatch(() => {
|
// add a count by using BTN1 or BTN5
|
||||||
counter += 1;
|
setWatch(() => {
|
||||||
updateScreen();
|
counter += 1;
|
||||||
}, BTN5, {repeat:true});
|
updateScreen();
|
||||||
|
}, BTN1, {repeat:true});
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
counter += 1;
|
||||||
|
updateScreen();
|
||||||
|
}, BTN5, {repeat:true});
|
||||||
|
|
||||||
|
// subtract a count by using BTN3 or BTN4
|
||||||
|
setWatch(() => {
|
||||||
|
if (counter > 0) counter -= 1;
|
||||||
|
updateScreen();
|
||||||
|
}, BTN4, {repeat:true});
|
||||||
|
|
||||||
|
setWatch(() => {
|
||||||
|
if (counter > 0) counter -= 1;
|
||||||
|
updateScreen();
|
||||||
|
}, BTN3, {repeat:true});
|
||||||
|
|
||||||
|
// reset by using BTN2
|
||||||
|
setWatch(() => {
|
||||||
|
counter = 0;
|
||||||
|
updateScreen();
|
||||||
|
}, BTN2, {repeat:true});
|
||||||
|
}
|
||||||
|
|
||||||
// subtract a count by using BTN3 or BTN4
|
|
||||||
setWatch(() => {
|
|
||||||
counter -= 1;
|
|
||||||
updateScreen();
|
|
||||||
}, BTN4, {repeat:true});
|
|
||||||
|
|
||||||
setWatch(() => {
|
|
||||||
counter -= 1;
|
|
||||||
updateScreen();
|
|
||||||
}, BTN3, {repeat:true});
|
|
||||||
|
|
||||||
// reset by using BTN2
|
|
||||||
setWatch(() => {
|
|
||||||
counter = 0;
|
|
||||||
updateScreen();
|
|
||||||
}, BTN2, {repeat:true});
|
|
||||||
|
|
||||||
g.clear(1).setFont("6x8");
|
g.clear(1).setFont("6x8");
|
||||||
g.drawString('Tap right or BTN1 to increase\nTap left or BTN3 to decrease\nPress BTN2 to reset.', 25, 200);
|
g.setBgColor(g.theme.bg).setColor(g.theme.fg);
|
||||||
|
if (BANGLEJS2) {
|
||||||
|
g.drawString('Swipe up to increase\nSwipe down to decrease\nPress button to reset.', x, 100 + y);
|
||||||
|
} else {
|
||||||
|
g.drawString('Tap right or BTN1 to increase\nTap left or BTN3 to decrease\nPress BTN2 to reset.', x, 100 + y);
|
||||||
|
}
|
||||||
|
|
||||||
Bangle.loadWidgets();
|
Bangle.loadWidgets();
|
||||||
Bangle.drawWidgets();
|
Bangle.drawWidgets();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"id": "counter",
|
"id": "counter",
|
||||||
"name": "Counter",
|
"name": "Counter",
|
||||||
"version": "0.03",
|
"version": "0.04",
|
||||||
"description": "Simple counter",
|
"description": "Simple counter",
|
||||||
"icon": "counter_icon.png",
|
"icon": "counter_icon.png",
|
||||||
"tags": "tool",
|
"tags": "tool",
|
||||||
"supports": ["BANGLEJS"],
|
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||||
"screenshots": [{"url":"bangle1-counter-screenshot.png"}],
|
"screenshots": [{"url":"bangle1-counter-screenshot.png"}],
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
"storage": [
|
"storage": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue