forked from FOSS/BangleApps
kbswipe: Bug fixes
parent
39860e9bb2
commit
6324ffb378
|
@ -1,5 +1,5 @@
|
|||
const INPUT_MODE_ALPHA = 0;
|
||||
const INPUT_MODE_NUM = 1;
|
||||
exports.INPUT_MODE_ALPHA = 0;
|
||||
exports.INPUT_MODE_NUM = 1;
|
||||
|
||||
/* To make your own strokes, type:
|
||||
|
||||
|
@ -8,7 +8,7 @@ Bangle.on('stroke',print)
|
|||
on the left of the IDE, then do a stroke and copy out the Uint8Array line
|
||||
*/
|
||||
exports.getStrokes = function(mode, cb) {
|
||||
if (mode === INPUT_MODE_ALPHA) {
|
||||
if (mode === exports.INPUT_MODE_ALPHA) {
|
||||
cb("a", new Uint8Array([58, 159, 58, 155, 62, 144, 69, 127, 77, 106, 86, 90, 94, 77, 101, 68, 108, 62, 114, 59, 121, 59, 133, 61, 146, 70, 158, 88, 169, 107, 176, 124, 180, 135, 183, 144, 185, 152]));
|
||||
cb("b", new Uint8Array([51, 47, 51, 77, 56, 123, 60, 151, 65, 163, 68, 164, 68, 144, 67, 108, 67, 76, 72, 43, 104, 51, 121, 74, 110, 87, 109, 95, 131, 117, 131, 140, 109, 152, 88, 157]));
|
||||
cb("c", new Uint8Array([153, 62, 150, 62, 145, 62, 136, 62, 123, 62, 106, 65, 85, 70, 65, 75, 50, 82, 42, 93, 37, 106, 36, 119, 36, 130, 40, 140, 49, 147, 61, 153, 72, 156, 85, 157, 106, 158, 116, 158]));
|
||||
|
@ -35,18 +35,18 @@ exports.getStrokes = function(mode, cb) {
|
|||
cb("x", new Uint8Array([56, 63, 56, 67, 57, 74, 60, 89, 66, 109, 74, 129, 85, 145, 96, 158, 107, 164, 117, 167, 128, 164, 141, 155, 151, 140, 159, 122, 166, 105, 168, 89, 170, 81, 170, 73, 169, 66, 161, 63, 141, 68, 110, 83, 77, 110, 55, 134, 47, 145]));
|
||||
cb("y", new Uint8Array([42, 56, 42, 70, 48, 97, 62, 109, 85, 106, 109, 90, 126, 65, 134, 47, 137, 45, 137, 75, 127, 125, 98, 141, 70, 133, 65, 126, 92, 137, 132, 156, 149, 166]));
|
||||
cb("z", new Uint8Array([29, 62, 35, 62, 43, 62, 63, 62, 87, 62, 110, 62, 125, 62, 134, 62, 138, 62, 136, 63, 122, 68, 103, 77, 85, 91, 70, 107, 59, 120, 50, 132, 47, 138, 43, 143, 41, 148, 42, 151, 53, 155, 80, 157, 116, 158, 146, 158, 163, 158]));
|
||||
cb("SHIFT", new Uint8Array([106, 184, 106, 182, 106, 175, 106, 165, 106, 151, 106, 135, 106, 120, 106, 106, 106, 95, 106, 87, 106, 82, 106, 78, 106, 73, 106, 70, 106, 68, 106, 66, 106, 64]));
|
||||
} else if (mode === INPUT_MODE_NUM) {
|
||||
cb("0", new Uint8Array([105, 63, 97, 63, 80, 63, 62, 64, 52, 69, 47, 79, 47, 94, 48, 111, 55, 125, 74, 138, 100, 141, 126, 137, 148, 129, 158, 119, 161, 107, 161, 98, 159, 92, 154, 87, 149, 82]));
|
||||
cb("1", new Uint8Array([123, 59, 123, 60, 123, 63, 123, 67, 123, 70, 122, 73, 121, 78, 119, 83, 118, 91, 117, 100, 116, 108, 115, 117, 114, 126, 113, 135, 112, 143, 111, 149, 111, 155, 110, 159]));
|
||||
cb("2", new Uint8Array([61, 99, 61, 94, 61, 88, 61, 80, 65, 71, 73, 66, 83, 62, 97, 62, 109, 62, 126, 62, 141, 62, 149, 65, 151, 74, 151, 87, 150, 95, 143, 108, 130, 118, 117, 127, 100, 138, 84, 146, 67, 151, 55, 157, 52, 159, 73, 159, 117, 159, 163, 159, 183, 159]));
|
||||
cb("3", new Uint8Array([69, 62, 78, 56, 98, 49, 121, 49, 141, 54, 149, 58, 150, 65, 148, 74, 143, 82, 126, 92, 114, 98, 119, 100, 135, 105, 143, 117, 142, 135, 123, 149, 105, 155]));
|
||||
cb("4", new Uint8Array([78, 45, 78, 47, 78, 50, 78, 56, 78, 64, 78, 75, 78, 88, 78, 103, 78, 119, 78, 132, 78, 144, 78, 148, 80, 149, 84, 149, 96, 149, 112, 148, 127, 147, 144, 144, 163, 140, 175, 137]));
|
||||
cb("5", new Uint8Array([142, 49, 134, 47, 121, 44, 104, 44, 88, 45, 75, 46, 68, 48, 64, 52, 64, 59, 64, 73, 64, 86, 64, 100, 67, 105, 82, 105, 106, 105, 130, 105, 143, 105, 149, 105, 151, 110, 148, 125, 138, 144, 118, 157, 92, 164, 76, 165, 65, 165, 60, 165]));
|
||||
cb("6", new Uint8Array([161, 47, 151, 47, 133, 47, 108, 48, 85, 52, 65, 59, 53, 72, 46, 89, 44, 107, 49, 133, 71, 151, 100, 156, 118, 152, 120, 141, 108, 132, 84, 127, 70, 126]));
|
||||
cb("7", new Uint8Array([43, 53, 53, 49, 72, 45, 96, 40, 116, 38, 129, 38, 138, 38, 144, 38, 147, 39, 149, 47, 143, 75, 127, 121, 114, 147, 107, 158, 104, 162, 98, 168, 93, 171]));
|
||||
cb("8", new Uint8Array([148, 66, 135, 58, 113, 49, 97, 43, 84, 40, 74, 40, 66, 43, 62, 47, 62, 51, 67, 61, 84, 75, 101, 88, 111, 101, 113, 115, 110, 135, 98, 149, 84, 156, 73, 157, 63, 157, 58, 154, 52, 144, 52, 133, 54, 122, 65, 111, 81, 100, 97, 92, 110, 86, 121, 81, 129, 80, 137, 80, 145, 79, 151, 78]));
|
||||
cb("9", new Uint8Array([146, 57, 146, 52, 146, 46, 143, 42, 135, 41, 123, 41, 107, 45, 92, 49, 83, 53, 78, 62, 89, 82, 110, 94, 126, 94, 139, 88, 147, 81, 151, 74, 152, 75, 152, 80, 152, 88, 152, 101, 152, 121, 152, 140, 152, 154, 152, 165, 152, 171]));
|
||||
cb("SHIFT", new Uint8Array([100, 160, 100, 50]));
|
||||
} else if (mode === exports.INPUT_MODE_NUM) {
|
||||
cb("0", new Uint8Array([127, 67, 125, 67, 121, 67, 111, 67, 98, 67, 83, 68, 72, 70, 64, 74, 58, 79, 54, 86, 51, 96, 50, 107, 50, 116, 50, 125, 53, 132, 59, 141, 66, 146, 75, 150, 93, 155, 112, 157, 132, 154, 147, 146, 158, 126, 160, 113, 159, 103, 155, 94, 149, 89, 142, 85]));
|
||||
cb("1", new Uint8Array([100, 50, 100, 160]));
|
||||
cb("2", new Uint8Array([63, 80, 65, 78, 68, 75, 72, 71, 79, 67, 87, 62, 97, 59, 106, 58, 115, 58, 122, 58, 126, 61, 128, 66, 129, 72, 127, 84, 123, 100, 115, 116, 110, 126, 103, 136, 95, 146, 93, 149, 98, 150, 114, 150, 136, 150, 154, 150]));
|
||||
cb("3", new Uint8Array([100, 62, 102, 62, 105, 62, 109, 62, 114, 62, 121, 62, 127, 62, 131, 62, 135, 62, 137, 63, 138, 66, 138, 68, 138, 70, 137, 72, 135, 74, 133, 77, 132, 79, 129, 81, 126, 84, 123, 86, 119, 86, 122, 90, 129, 93, 142, 101, 150, 107, 154, 117, 154, 126, 150, 135, 142, 142, 131, 147, 122, 150]));
|
||||
cb("4", new Uint8Array([93, 61, 93, 63, 93, 68, 93, 75, 93, 84, 93, 93, 93, 101, 93, 113, 93, 126, 93, 137, 93, 144, 93, 149, 93, 151, 93, 154, 93, 156, 94, 157, 96, 157, 103, 157, 120, 157, 141, 157, 161, 157, 176, 157, 182, 157, 185, 157]));
|
||||
cb("5", new Uint8Array([151, 57, 144, 55, 130, 55, 110, 56, 94, 59, 83, 61, 78, 69, 78, 78, 78, 86, 78, 93, 83, 100, 103, 103, 127, 106, 143, 114, 148, 128, 141, 142, 125, 152, 107, 159, 90, 162, 81, 163]));
|
||||
cb("6", new Uint8Array([147, 35, 145, 35, 141, 36, 136, 38, 130, 42, 123, 47, 115, 51, 106, 57, 97, 64, 88, 73, 81, 82, 76, 89, 73, 95, 71, 101, 70, 108, 70, 114, 70, 118, 71, 124, 74, 131, 80, 137, 87, 140, 96, 143, 103, 143, 108, 141, 113, 138, 116, 134, 118, 127, 118, 120, 118, 114, 116, 107, 113, 103, 109, 100]));
|
||||
cb("7", new Uint8Array([66, 69, 69, 69, 75, 67, 83, 66, 95, 66, 108, 63, 121, 61, 132, 61, 141, 61, 147, 61, 151, 61, 154, 61, 156, 61, 158, 61, 160, 61, 162, 61, 162, 63, 161, 67, 156, 85, 147, 112, 137, 135, 129, 151, 124, 158]));
|
||||
cb("8", new Uint8Array([148, 59, 145, 55, 137, 52, 125, 52, 112, 52, 100, 54, 92, 56, 84, 60, 81, 66, 81, 76, 90, 82, 109, 90, 128, 98, 136, 106, 137, 121, 126, 140, 107, 151, 92, 151, 81, 143, 81, 122, 92, 94, 108, 75, 124, 65]));
|
||||
cb("9", new Uint8Array([129, 72, 127, 72, 125, 72, 122, 72, 117, 72, 111, 72, 104, 74, 100, 77, 95, 79, 94, 81, 94, 83, 94, 87, 96, 90, 101, 92, 105, 94, 111, 94, 115, 94, 121, 92, 130, 89, 136, 85, 140, 82, 144, 79, 146, 79, 147, 83, 149, 97, 149, 118, 149, 135, 149, 149, 149, 158]));
|
||||
}
|
||||
cb("\b", new Uint8Array([183, 103, 182, 103, 180, 103, 176, 103, 169, 103, 159, 103, 147, 103, 133, 103, 116, 103, 101, 103, 85, 103, 73, 103, 61, 103, 52, 103, 38, 103, 34, 103, 29, 103, 27, 103, 26, 103, 25, 103, 24, 103]));
|
||||
cb(" ", new Uint8Array([39, 118, 40, 118, 41, 118, 44, 118, 47, 118, 52, 118, 58, 118, 66, 118, 74, 118, 84, 118, 94, 118, 104, 117, 114, 116, 123, 116, 130, 116, 144, 116, 149, 116, 154, 116, 158, 116, 161, 116, 163, 116]));
|
||||
|
@ -54,7 +54,7 @@ exports.getStrokes = function(mode, cb) {
|
|||
|
||||
exports.input = function(options) {
|
||||
options = options||{};
|
||||
let input_mode = INPUT_MODE_ALPHA;
|
||||
let input_mode = exports.INPUT_MODE_ALPHA;
|
||||
var text = options.text;
|
||||
if ("string"!=typeof text) text="";
|
||||
|
||||
|
@ -72,6 +72,7 @@ exports.input = function(options) {
|
|||
var Ry2;
|
||||
let flashInterval;
|
||||
let shift = false;
|
||||
let lastDrag;
|
||||
|
||||
function findMarker(strArr) {
|
||||
if (strArr.length == 0) {
|
||||
|
@ -140,6 +141,20 @@ exports.input = function(options) {
|
|||
});
|
||||
}
|
||||
|
||||
function isInside(rect, e) {
|
||||
return e.x>=rect.x && e.x<rect.x+rect.w
|
||||
&& e.y>=rect.y && e.y<=rect.y+rect.h;
|
||||
}
|
||||
|
||||
function isStrokeInAppRect(stroke, rect) {
|
||||
for(let i=0; i < stroke.length; i+=2) {
|
||||
if (!isInside(rect, {x: stroke[i], y: stroke[i+1]})) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function strokeHandler(o) {
|
||||
//print(o);
|
||||
if (!flashInterval)
|
||||
|
@ -147,13 +162,14 @@ exports.input = function(options) {
|
|||
flashToggle = !flashToggle;
|
||||
draw(false);
|
||||
}, 1000);
|
||||
if (o.stroke!==undefined) {
|
||||
if (o.stroke!==undefined && o.xy.length >= 6 && isStrokeInAppRect(o.xy, R)) {
|
||||
var ch = o.stroke;
|
||||
if (ch=="\b") text = text.slice(0,-1);
|
||||
else if (ch==="SHIFT") { shift=!shift; Bangle.drawWidgets(); }
|
||||
else text += shift ? ch.toUpperCase() : ch;
|
||||
g.clearRect(R);
|
||||
}
|
||||
lastDrag = undefined;
|
||||
g.clearRect(R);
|
||||
flashToggle = true;
|
||||
draw(false);
|
||||
}
|
||||
|
@ -161,7 +177,7 @@ exports.input = function(options) {
|
|||
// Switches between alphabetic and numeric input
|
||||
function cycleInput() {
|
||||
input_mode++;
|
||||
if (input_mode > INPUT_MODE_NUM) input_mode = 0;
|
||||
if (input_mode > exports.INPUT_MODE_NUM) input_mode = 0;
|
||||
shift = false;
|
||||
setupStrokes();
|
||||
show();
|
||||
|
@ -181,26 +197,27 @@ exports.input = function(options) {
|
|||
g.reset();
|
||||
g.setFont("6x8:2x3");
|
||||
g.setColor("#f00");
|
||||
if (input_mode === INPUT_MODE_ALPHA) {
|
||||
if (input_mode === exports.INPUT_MODE_ALPHA) {
|
||||
g.drawString(shift ? "ABC" : "abc", this.x, this.y);
|
||||
} else if (input_mode === INPUT_MODE_NUM) {
|
||||
} else if (input_mode === exports.INPUT_MODE_NUM) {
|
||||
g.drawString("123", this.x, this.y);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise((resolve,reject) => {
|
||||
var l;//last event
|
||||
Bangle.setUI({mode:"custom", drag:e=>{
|
||||
"ram";
|
||||
if (l) g.reset().setColor("#f00").drawLine(l.x,l.y,e.x,e.y);
|
||||
l = e.b ? e : 0;
|
||||
if (isInside(R, e)) {
|
||||
if (lastDrag) g.reset().setColor("#f00").drawLine(lastDrag.x,lastDrag.y,e.x,e.y);
|
||||
lastDrag = e.b ? e : 0;
|
||||
}
|
||||
},touch:(n,e) => {
|
||||
if (WIDGETS.kbswipe && e.x>=WIDGETS.kbswipe.x && e.x<WIDGETS.kbswipe.x+WIDGETS.kbswipe.width
|
||||
&& e.y>=WIDGETS.kbswipe.y && e.y<=WIDGETS.kbswipe.y+24) {
|
||||
if (WIDGETS.kbswipe && isInside({x: WIDGETS.kbswipe.x, y: WIDGETS.kbswipe.y, w: WIDGETS.kbswipe.width, h: 24}, e)) {
|
||||
// touch inside widget
|
||||
cycleInput();
|
||||
} else {
|
||||
} else if (isInside(R, e)) {
|
||||
// touch inside app area
|
||||
show();
|
||||
}
|
||||
}, back:()=>{
|
||||
|
|
Loading…
Reference in New Issue