2020-04-13 02:10:18 +00:00
|
|
|
/**
|
|
|
|
* BangleJS Calculator
|
|
|
|
*
|
|
|
|
* Original Author: Frederic Rousseau https://github.com/fredericrous
|
|
|
|
* Created: April 2020
|
2022-11-07 10:04:52 +00:00
|
|
|
*
|
|
|
|
* Contributors: thyttan https://github.com/thyttan
|
2020-04-13 02:10:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
g.clear();
|
2021-08-18 15:10:04 +00:00
|
|
|
require("Font7x11Numeric7Seg").add(Graphics);
|
2020-04-13 02:10:18 +00:00
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
var DEFAULT_SELECTION_NUMBERS = '5', DEFAULT_SELECTION_OPERATORS = '=', DEFAULT_SELECTION_SPECIALS = 'R';
|
2020-04-13 02:10:18 +00:00
|
|
|
var RIGHT_MARGIN = 20;
|
2021-08-18 15:10:04 +00:00
|
|
|
var RESULT_HEIGHT = 40;
|
2024-09-10 13:18:25 +00:00
|
|
|
var RESULT_MAX_LEN = Math.floor((g.getWidth() - 20) / 14);
|
2020-04-13 02:10:18 +00:00
|
|
|
var COLORS = {
|
|
|
|
// [normal, selected]
|
|
|
|
DEFAULT: ['#7F8183', '#A6A6A7'],
|
|
|
|
OPERATOR: ['#F99D1C', '#CA7F2A'],
|
|
|
|
SPECIAL: ['#65686C', '#7F8183']
|
|
|
|
};
|
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
var KEY_AREA = [0, RESULT_HEIGHT, g.getWidth(), g.getHeight()];
|
|
|
|
|
|
|
|
var screen, screenColor;
|
|
|
|
var globalGrid = [4, 5];
|
|
|
|
var swipeEnabled;
|
|
|
|
|
|
|
|
var numbersGrid = [3, 4];
|
|
|
|
var numbers = {
|
|
|
|
'0': {grid: [1, 3], globalGrid: [1, 4], trbl: '2.00'},
|
|
|
|
'.': {grid: [2, 3], globalGrid: [2, 4], trbl: '3=.0'},
|
|
|
|
'1': {grid: [0, 2], globalGrid: [0, 3], trbl: '4201'},
|
|
|
|
'2': {grid: [1, 2], globalGrid: [1, 3], trbl: '5301'},
|
|
|
|
'3': {grid: [2, 2], globalGrid: [2, 3], trbl: '6+.2'},
|
|
|
|
'4': {grid: [0, 1], globalGrid: [0, 2], trbl: '7514'},
|
|
|
|
'5': {grid: [1, 1], globalGrid: [1, 2], trbl: '8624'},
|
|
|
|
'6': {grid: [2, 1], globalGrid: [2, 2], trbl: '9-35'},
|
|
|
|
'7': {grid: [0, 0], globalGrid: [0, 1], trbl: 'R847'},
|
|
|
|
'8': {grid: [1, 0], globalGrid: [1, 1], trbl: 'N957'},
|
|
|
|
'9': {grid: [2, 0], globalGrid: [2, 1], trbl: '%*68'},
|
|
|
|
};
|
|
|
|
|
|
|
|
var operatorsGrid = [2, 3];
|
|
|
|
var operators = {
|
|
|
|
'+': {grid: [0, 0], globalGrid: [3, 3], trbl: '-+=3'},
|
|
|
|
'-': {grid: [1, 0], globalGrid: [3, 2], trbl: '*-+6'},
|
|
|
|
'*': {grid: [0, 1], globalGrid: [3, 1], trbl: '/*-9'},
|
|
|
|
'/': {grid: [1, 1], globalGrid: [3, 0], trbl: '//*%'},
|
|
|
|
'=': {grid: [1, 2], globalGrid: [3, 4], trbl: '+==.'},
|
2020-04-13 02:10:18 +00:00
|
|
|
};
|
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
var specialsGrid = [2, 2];
|
|
|
|
var specials = {
|
|
|
|
'R': {grid: [0, 0], globalGrid: [0, 0], trbl: 'RN7R', val: 'AC'},
|
|
|
|
'N': {grid: [1, 0], globalGrid: [1, 0], trbl: 'N%8R', val: '+/-'},
|
|
|
|
'%': {grid: [0, 1], globalGrid: [2, 0], trbl: '%/9N'},
|
|
|
|
};
|
|
|
|
|
|
|
|
var selected = DEFAULT_SELECTION_NUMBERS;
|
|
|
|
var prevSelected = DEFAULT_SELECTION_NUMBERS;
|
2020-04-13 02:10:18 +00:00
|
|
|
var prevNumber = null;
|
|
|
|
var currNumber = null;
|
|
|
|
var operator = null;
|
|
|
|
var results = null;
|
|
|
|
var isDecimal = false;
|
|
|
|
var hasPressedEquals = false;
|
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
function prepareScreen(screen, grid, defaultColor) {
|
|
|
|
for (var k in screen) {
|
|
|
|
if (screen.hasOwnProperty(k)) {
|
|
|
|
screen[k].color = screen[k].color || defaultColor;
|
|
|
|
var position = [];
|
|
|
|
var xGrid = (KEY_AREA[2]-KEY_AREA[0])/grid[0];
|
|
|
|
var yGrid = (KEY_AREA[3]-KEY_AREA[1])/grid[1];
|
|
|
|
if (swipeEnabled) {
|
|
|
|
position[0] = KEY_AREA[0]+xGrid*screen[k].grid[0];
|
|
|
|
position[1] = KEY_AREA[1]+yGrid*screen[k].grid[1];
|
|
|
|
} else {
|
|
|
|
position[0] = KEY_AREA[0]+xGrid*screen[k].globalGrid[0];
|
|
|
|
position[1] = KEY_AREA[1]+yGrid*screen[k].globalGrid[1];
|
|
|
|
}
|
|
|
|
position[2] = position[0]+xGrid-1;
|
|
|
|
position[3] = position[1]+yGrid-1;
|
|
|
|
screen[k].xy = position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 02:10:18 +00:00
|
|
|
function drawKey(name, k, selected) {
|
|
|
|
var color = k.color || COLORS.DEFAULT;
|
|
|
|
g.setColor(color[selected ? 1 : 0]);
|
2021-08-18 15:10:04 +00:00
|
|
|
g.setFont('Vector', 20).setFontAlign(0,0);
|
2020-04-13 02:10:18 +00:00
|
|
|
g.fillRect(k.xy[0], k.xy[1], k.xy[2], k.xy[3]);
|
|
|
|
g.setColor(-1);
|
2021-08-18 15:10:04 +00:00
|
|
|
g.drawString(k.val || name, (k.xy[0] + k.xy[2])/2, (k.xy[1] + k.xy[3])/2);
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
function drawKeys() {
|
|
|
|
g.setColor(screenColor[0]);
|
|
|
|
g.fillRect(KEY_AREA[0], KEY_AREA[1], KEY_AREA[2], KEY_AREA[3]);
|
|
|
|
for (var k in screen) {
|
|
|
|
if (screen.hasOwnProperty(k)) {
|
|
|
|
drawKey(k, screen[k], k == selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function drawGlobal() {
|
|
|
|
screen = {};
|
|
|
|
screenColor = COLORS.DEFAULT;
|
|
|
|
prepareScreen(numbers, globalGrid, COLORS.DEFAULT);
|
|
|
|
for (var k in numbers) {
|
|
|
|
screen[k] = numbers[k];
|
|
|
|
}
|
|
|
|
prepareScreen(operators, globalGrid, COLORS.OPERATOR);
|
|
|
|
for (var k in operators) {
|
|
|
|
screen[k] = operators[k];
|
|
|
|
}
|
|
|
|
prepareScreen(specials, globalGrid, COLORS.SPECIAL);
|
|
|
|
for (var k in specials) {
|
|
|
|
screen[k] = specials[k];
|
|
|
|
}
|
|
|
|
drawKeys();
|
|
|
|
}
|
|
|
|
function drawNumbers() {
|
|
|
|
screen = numbers;
|
|
|
|
screenColor = COLORS.DEFAULT;
|
|
|
|
drawKeys();
|
|
|
|
}
|
|
|
|
function drawOperators() {
|
|
|
|
screen = operators;
|
|
|
|
screenColor =COLORS.OPERATOR;
|
|
|
|
drawKeys();
|
|
|
|
}
|
|
|
|
function drawSpecials() {
|
|
|
|
screen = specials;
|
|
|
|
screenColor = COLORS.SPECIAL;
|
|
|
|
drawKeys();
|
|
|
|
}
|
|
|
|
|
2020-04-18 15:30:05 +00:00
|
|
|
function getIntWithPrecision(x) {
|
|
|
|
var xStr = x.toString();
|
|
|
|
var xRadix = xStr.indexOf('.');
|
|
|
|
var xPrecision = xRadix === -1 ? 0 : xStr.length - xRadix - 1;
|
|
|
|
return {
|
|
|
|
num: Number(xStr.replace('.', '')),
|
|
|
|
p: xPrecision
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function multiply(x, y) {
|
|
|
|
var xNum = getIntWithPrecision(x);
|
|
|
|
var yNum = getIntWithPrecision(y);
|
|
|
|
return xNum.num * yNum.num / Math.pow(10, xNum.p + yNum.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
function divide(x, y) {
|
|
|
|
var xNum = getIntWithPrecision(x);
|
|
|
|
var yNum = getIntWithPrecision(y);
|
|
|
|
return xNum.num / yNum.num / Math.pow(10, xNum.p - yNum.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sum(x, y) {
|
|
|
|
let xNum = getIntWithPrecision(x);
|
|
|
|
let yNum = getIntWithPrecision(y);
|
|
|
|
|
|
|
|
let diffPrecision = Math.abs(xNum.p - yNum.p);
|
|
|
|
if (diffPrecision > 0) {
|
|
|
|
if (xNum.p > yNum.p) {
|
|
|
|
yNum.num = yNum.num * Math.pow(10, diffPrecision);
|
|
|
|
} else {
|
|
|
|
xNum.num = xNum.num * Math.pow(10, diffPrecision);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (xNum.num + yNum.num) / Math.pow(10, Math.max(xNum.p, yNum.p));
|
|
|
|
}
|
|
|
|
|
|
|
|
function subtract(x, y) {
|
|
|
|
return sum(x, -y);
|
|
|
|
}
|
|
|
|
|
2020-04-13 02:10:18 +00:00
|
|
|
function doMath(x, y, operator) {
|
|
|
|
switch (operator) {
|
|
|
|
case '/':
|
2020-04-18 15:30:05 +00:00
|
|
|
return divide(x, y);
|
2020-04-13 02:10:18 +00:00
|
|
|
case '*':
|
2020-04-18 15:30:05 +00:00
|
|
|
return multiply(x, y);
|
2020-04-13 02:10:18 +00:00
|
|
|
case '+':
|
2020-04-18 15:30:05 +00:00
|
|
|
return sum(x, y);
|
2020-04-13 02:10:18 +00:00
|
|
|
case '-':
|
2020-04-18 15:30:05 +00:00
|
|
|
return subtract(x, y);
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayOutput(num) {
|
2021-09-23 10:43:38 +00:00
|
|
|
g.setBgColor(0).clearRect(0, 0, g.getWidth(), RESULT_HEIGHT-1);
|
2020-04-13 02:10:18 +00:00
|
|
|
g.setColor(-1);
|
|
|
|
if (num === Infinity || num === -Infinity || isNaN(num)) {
|
|
|
|
// handle division by 0
|
|
|
|
if (num === Infinity) {
|
|
|
|
num = 'INFINITY';
|
|
|
|
} else if (num === -Infinity) {
|
|
|
|
num = '-INFINITY';
|
|
|
|
} else {
|
|
|
|
num = 'NOT A NUMBER';
|
|
|
|
}
|
|
|
|
currNumber = null;
|
|
|
|
results = null;
|
|
|
|
isDecimal = false;
|
|
|
|
hasPressedEquals = false;
|
|
|
|
prevNumber = null;
|
|
|
|
operator = null;
|
2021-12-27 14:06:40 +00:00
|
|
|
specials.R.val = 'AC';
|
|
|
|
if (!swipeEnabled) drawKey('R', specials.R);
|
2020-04-13 02:10:18 +00:00
|
|
|
g.setFont('Vector', 22);
|
|
|
|
} else {
|
|
|
|
// might not be a number due to display of dot "."
|
|
|
|
var numNumeric = Number(num);
|
|
|
|
|
|
|
|
if (typeof num === 'string') {
|
|
|
|
if (num.indexOf('.') !== -1) {
|
|
|
|
// display a 0 before a lonely dot
|
|
|
|
if (numNumeric == 0) {
|
|
|
|
num = '0.';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// remove preceding 0
|
|
|
|
while (num.length > 1 && num[0] === '0')
|
|
|
|
num = num.substr(1);
|
|
|
|
}
|
|
|
|
}
|
2021-08-18 15:10:04 +00:00
|
|
|
num = num.toString();
|
|
|
|
num = num.replace("-","- "); // fix padding for '-'
|
2020-04-13 02:10:18 +00:00
|
|
|
g.setFont('7x11Numeric7Seg', 2);
|
2024-09-10 13:18:25 +00:00
|
|
|
if (num.length > RESULT_MAX_LEN) {
|
|
|
|
num = num.substr(0, RESULT_MAX_LEN - 1)+'-';
|
|
|
|
}
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2021-08-18 15:10:04 +00:00
|
|
|
g.setFontAlign(1,0);
|
|
|
|
g.drawString(num, g.getWidth()-20, RESULT_HEIGHT/2);
|
2021-09-23 10:43:38 +00:00
|
|
|
if (operator) {
|
|
|
|
g.setFont('Vector', 22).setFontAlign(1,0);
|
|
|
|
g.drawString(operator, g.getWidth()-1, RESULT_HEIGHT/2);
|
|
|
|
}
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
var wasPressedEquals = false;
|
|
|
|
var hasPressedNumber = false;
|
2020-04-13 02:10:18 +00:00
|
|
|
function calculatorLogic(x) {
|
2020-04-18 15:30:05 +00:00
|
|
|
if (wasPressedEquals && hasPressedNumber !== false) {
|
2020-04-13 02:10:18 +00:00
|
|
|
prevNumber = null;
|
2020-04-18 15:30:05 +00:00
|
|
|
currNumber = hasPressedNumber;
|
|
|
|
wasPressedEquals = false;
|
|
|
|
hasPressedNumber = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hasPressedEquals) {
|
|
|
|
if (hasPressedNumber) {
|
|
|
|
prevNumber = null;
|
|
|
|
hasPressedNumber = false;
|
|
|
|
operator = null;
|
|
|
|
} else {
|
|
|
|
currNumber = null;
|
|
|
|
prevNumber = results;
|
|
|
|
}
|
2020-04-13 02:10:18 +00:00
|
|
|
hasPressedEquals = false;
|
2020-04-18 15:30:05 +00:00
|
|
|
wasPressedEquals = true;
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
|
|
|
|
if (currNumber == null && operator != null && '/*-+'.indexOf(x) !== -1) {
|
|
|
|
operator = x;
|
|
|
|
displayOutput(prevNumber);
|
|
|
|
} else if (prevNumber != null && currNumber != null && operator != null) {
|
2020-04-13 02:10:18 +00:00
|
|
|
// we execute the calculus only when there was a previous number entered before and an operator
|
|
|
|
results = doMath(prevNumber, currNumber, operator);
|
|
|
|
operator = x;
|
|
|
|
prevNumber = results;
|
|
|
|
currNumber = null;
|
|
|
|
displayOutput(results);
|
|
|
|
} else if (prevNumber == null && currNumber != null && operator == null) {
|
|
|
|
// no operator yet, save the current number for later use when an operator is pressed
|
|
|
|
operator = x;
|
|
|
|
prevNumber = currNumber;
|
|
|
|
currNumber = null;
|
|
|
|
displayOutput(prevNumber);
|
|
|
|
} else if (prevNumber == null && currNumber == null && operator == null) {
|
|
|
|
displayOutput(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function buttonPress(val) {
|
|
|
|
switch (val) {
|
|
|
|
case 'R':
|
|
|
|
currNumber = null;
|
|
|
|
results = null;
|
|
|
|
isDecimal = false;
|
|
|
|
hasPressedEquals = false;
|
2021-12-27 14:06:40 +00:00
|
|
|
if (specials.R.val == 'AC') {
|
2020-04-13 02:10:18 +00:00
|
|
|
prevNumber = null;
|
|
|
|
operator = null;
|
|
|
|
} else {
|
2021-12-27 14:06:40 +00:00
|
|
|
specials.R.val = 'AC';
|
|
|
|
drawKey('R', specials.R, true);
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
wasPressedEquals = false;
|
|
|
|
hasPressedNumber = false;
|
2020-04-13 02:10:18 +00:00
|
|
|
displayOutput(0);
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
if (results != null) {
|
|
|
|
displayOutput(results /= 100);
|
|
|
|
} else if (currNumber != null) {
|
|
|
|
displayOutput(currNumber /= 100);
|
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
hasPressedNumber = false;
|
2020-04-13 02:10:18 +00:00
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
if (results != null) {
|
|
|
|
displayOutput(results *= -1);
|
2020-04-18 15:30:05 +00:00
|
|
|
} else {
|
2020-04-13 02:10:18 +00:00
|
|
|
displayOutput(currNumber *= -1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
case '*':
|
|
|
|
case '-':
|
|
|
|
case '+':
|
|
|
|
calculatorLogic(val);
|
2020-04-18 15:30:05 +00:00
|
|
|
hasPressedNumber = false;
|
2021-12-27 14:06:40 +00:00
|
|
|
if (swipeEnabled) drawNumbers();
|
2020-04-13 02:10:18 +00:00
|
|
|
break;
|
|
|
|
case '.':
|
2021-12-27 14:06:40 +00:00
|
|
|
specials.R.val = 'C';
|
|
|
|
if (!swipeEnabled) drawKey('R', specials.R);
|
2020-04-13 02:10:18 +00:00
|
|
|
isDecimal = true;
|
|
|
|
displayOutput(currNumber == null ? 0 + '.' : currNumber + '.');
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
if (prevNumber != null && currNumber != null && operator != null) {
|
|
|
|
results = doMath(prevNumber, currNumber, operator);
|
|
|
|
prevNumber = results;
|
|
|
|
displayOutput(results);
|
2020-04-18 15:30:05 +00:00
|
|
|
hasPressedEquals = 1;
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
hasPressedNumber = false;
|
2020-04-13 02:10:18 +00:00
|
|
|
break;
|
2024-02-10 15:51:46 +00:00
|
|
|
default: {
|
2021-12-27 14:06:40 +00:00
|
|
|
specials.R.val = 'C';
|
|
|
|
if (!swipeEnabled) drawKey('R', specials.R);
|
2020-04-18 15:30:05 +00:00
|
|
|
const is0Negative = (currNumber === 0 && 1/currNumber === -Infinity);
|
2020-04-13 02:10:18 +00:00
|
|
|
if (isDecimal) {
|
2020-04-18 15:30:05 +00:00
|
|
|
currNumber = currNumber == null || hasPressedEquals === 1 ? 0 + '.' + val : currNumber + '.' + val;
|
2020-04-13 02:10:18 +00:00
|
|
|
isDecimal = false;
|
|
|
|
} else {
|
2020-04-18 15:30:05 +00:00
|
|
|
currNumber = currNumber == null || hasPressedEquals === 1 ? val : (is0Negative ? '-' + val : currNumber + val);
|
|
|
|
}
|
|
|
|
if (hasPressedEquals === 1) {
|
|
|
|
hasPressedEquals = 2;
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
2020-04-18 15:30:05 +00:00
|
|
|
hasPressedNumber = currNumber;
|
2020-04-13 02:10:18 +00:00
|
|
|
displayOutput(currNumber);
|
|
|
|
break;
|
2024-02-10 15:51:46 +00:00
|
|
|
}
|
2020-04-13 02:10:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 15:30:05 +00:00
|
|
|
function moveDirection(d) {
|
2021-12-27 14:06:40 +00:00
|
|
|
drawKey(selected, screen[selected]);
|
2020-04-13 02:10:18 +00:00
|
|
|
prevSelected = selected;
|
2021-12-27 14:06:40 +00:00
|
|
|
selected = (d === 0 && selected == '0' && prevSelected === '1') ? '1' : screen[selected].trbl[d];
|
|
|
|
drawKey(selected, screen[selected], true);
|
2020-04-18 15:30:05 +00:00
|
|
|
}
|
2020-04-13 02:10:18 +00:00
|
|
|
|
2021-12-27 14:06:40 +00:00
|
|
|
if (process.env.HWVERSION==1) {
|
2021-08-18 15:10:04 +00:00
|
|
|
setWatch(_ => moveDirection(0), BTN1, {repeat: true, debounce: 100});
|
|
|
|
setWatch(_ => moveDirection(2), BTN3, {repeat: true, debounce: 100});
|
|
|
|
setWatch(_ => moveDirection(3), BTN4, {repeat: true, debounce: 100});
|
|
|
|
setWatch(_ => moveDirection(1), BTN5, {repeat: true, debounce: 100});
|
|
|
|
setWatch(_ => buttonPress(selected), BTN2, {repeat: true, debounce: 100});
|
2021-12-27 14:06:40 +00:00
|
|
|
swipeEnabled = false;
|
|
|
|
drawGlobal();
|
2021-08-18 15:10:04 +00:00
|
|
|
} else { // touchscreen?
|
2022-11-07 10:04:52 +00:00
|
|
|
selected = "NONE";
|
2021-12-27 14:06:40 +00:00
|
|
|
swipeEnabled = true;
|
|
|
|
prepareScreen(numbers, numbersGrid, COLORS.DEFAULT);
|
|
|
|
prepareScreen(operators, operatorsGrid, COLORS.OPERATOR);
|
|
|
|
prepareScreen(specials, specialsGrid, COLORS.SPECIAL);
|
|
|
|
drawNumbers();
|
2022-11-07 10:04:52 +00:00
|
|
|
|
|
|
|
Bangle.setUI({
|
|
|
|
mode : 'custom',
|
|
|
|
back : load, // Clicking physical button or pressing upper left corner turns off (where red back button would be)
|
|
|
|
touch : (n,e)=>{
|
|
|
|
for (var key in screen) {
|
|
|
|
if (typeof screen[key] == "undefined") break;
|
|
|
|
var r = screen[key].xy;
|
|
|
|
if (e.x>=r[0] && e.y>=r[1] && e.x<r[2] && e.y<r[3]) {
|
|
|
|
//print("Press "+key);
|
|
|
|
buttonPress(""+key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
swipe : (LR, UD) => {
|
|
|
|
if (LR == 1) { // right
|
|
|
|
drawSpecials();
|
|
|
|
}
|
|
|
|
if (LR == -1) { // left
|
|
|
|
drawOperators();
|
|
|
|
}
|
|
|
|
if (UD == 1) { // down
|
|
|
|
drawNumbers();
|
|
|
|
}
|
|
|
|
if (UD == -1) { // up
|
|
|
|
drawNumbers();
|
2021-08-18 15:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-11-07 10:04:52 +00:00
|
|
|
|
2021-08-18 15:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
displayOutput(0);
|