widclkscrl: Draw only in draw method
parent
7d82b39a71
commit
9ea1fe4dcf
|
|
@ -16,49 +16,49 @@
|
||||||
pos: 10,
|
pos: 10,
|
||||||
dir: -1,
|
dir: -1,
|
||||||
eventHandlerSet: false,
|
eventHandlerSet: false,
|
||||||
draw: function() {
|
draw: function(_w, scroll) {
|
||||||
if (!this.eventHandlerSet) {
|
if (!this.eventHandlerSet) {
|
||||||
Bangle.on('lock', (on) => {
|
Bangle.on('lock', (on) => {
|
||||||
this.run(!on);
|
this.run(!on);
|
||||||
});
|
});
|
||||||
this.eventHandlerSet = true;
|
this.eventHandlerSet = true;
|
||||||
}
|
}
|
||||||
|
if (scroll) {
|
||||||
|
const buf = Graphics.createArrayBuffer(WIDTH,24,1,{msb:true}).setFont("Teletext5x9Ascii:1x2").setFontAlign(-1, 0);
|
||||||
|
buf.drawString(this.text, this.pos, 12);
|
||||||
|
|
||||||
|
if (this.dir === 1 && this.pos === 0 || this.dir === -1 && Math.abs(this.pos) === buf.stringWidth(this.text) - WIDTH) {
|
||||||
|
if (CONTINOUS) {
|
||||||
|
this.dir*=-1;
|
||||||
|
this.text = getDateText();
|
||||||
|
} else {
|
||||||
|
this.pos = 0;
|
||||||
|
this.run(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.pos+=this.dir;
|
||||||
|
|
||||||
|
g.reset().drawImage({
|
||||||
|
width:buf.getWidth(), height:buf.getHeight(),
|
||||||
|
bpp:buf.getBPP(),
|
||||||
|
buffer:buf.buffer
|
||||||
|
}, this.x+1, this.y);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
run: function (on) {
|
run: function (on) {
|
||||||
if (!Bangle.CLOCK && on && !this.interval) {
|
if (!Bangle.CLOCK && on && !this.interval) {
|
||||||
this.text = getDateText();
|
this.text = getDateText();
|
||||||
this.interval = setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
this.scroll();
|
this.draw(this, true);
|
||||||
}, 100);
|
}, 100);
|
||||||
this.width = WIDTH+2; Bangle.drawWidgets();
|
this.width = WIDTH+2; Bangle.drawWidgets();
|
||||||
} else if (!on && this.interval) {
|
} else if (!on && this.interval) {
|
||||||
clearInterval(this.interval);
|
clearInterval(this.interval);
|
||||||
this.interval = undefined;
|
delete this.interval;
|
||||||
this.width = 0; Bangle.drawWidgets();
|
|
||||||
delete this.text;
|
delete this.text;
|
||||||
|
this.width = 0; Bangle.drawWidgets();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
scroll: function() {
|
|
||||||
const buf = Graphics.createArrayBuffer(WIDTH,24,1,{msb:true}).setFont("Teletext5x9Ascii:1x2").setFontAlign(-1, 0);
|
|
||||||
buf.drawString(this.text, this.pos, 12);
|
|
||||||
|
|
||||||
if (this.dir === 1 && this.pos === 0 || this.dir === -1 && Math.abs(this.pos) === buf.stringWidth(this.text) - WIDTH) {
|
|
||||||
if (CONTINOUS) {
|
|
||||||
this.dir*=-1;
|
|
||||||
this.text = getDateText();
|
|
||||||
} else {
|
|
||||||
this.pos = 0;
|
|
||||||
this.run(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.pos+=this.dir;
|
|
||||||
|
|
||||||
g.reset().drawImage({
|
|
||||||
width:buf.getWidth(), height:buf.getHeight(),
|
|
||||||
bpp:buf.getBPP(),
|
|
||||||
buffer:buf.buffer
|
|
||||||
}, this.x+1, this.y);
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue