-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateButtons.js
122 lines (94 loc) · 3.34 KB
/
createButtons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
function createButtons(inputHandler){
let list = [];
let posY = 0;
let posX = 1;
let defaultButtonWidth = 30;
//let creatingButton;
const buttonFromParams = function(label, text, size, x, y){
let creatingButton = new Clickable();
creatingButton.label = label;
creatingButton.text = text;
creatingButton.resize(size, size);
creatingButton.pos = {'x': x, 'y' : y}
creatingButton.locate(...coordsFromPos(x, y));
return creatingButton;
}
const coordsFromPos = function(x, y){
return [width - x*defaultButtonWidth - 5*x, 5+y*(defaultButtonWidth + 5)];
}
for(let label of Object.keys(Expression.expressionMap)){
if('ao'.includes(label)){continue;}
list[label] = buttonFromParams(label, Expression.expressionMap[label], defaultButtonWidth, posX, posY);
posY ++;
}
posY = 0;
posX++;
for(let i = "A".charCodeAt(0); i < "A".charCodeAt(0)+8; i++){
let label = "0" + String.fromCharCode(i);
list[label] = buttonFromParams(label, String.fromCharCode(i), defaultButtonWidth, posX, posY);
posY ++;
}
posY = 0;
posX++;
//variables
for(let i = "a".charCodeAt(0); i < "a".charCodeAt(0)+8; i++){
let label = "v" + String.fromCharCode(i);
list[label] = buttonFromParams(label, String.fromCharCode(i), defaultButtonWidth, posX, posY);
posY ++;
}
for(let i = "x".charCodeAt(0); i < "x".charCodeAt(0)+3; i++){
let label = "v" + String.fromCharCode(i);
list[label] = buttonFromParams(label, String.fromCharCode(i), defaultButtonWidth, posX, posY);
posY ++;
}
posY = 0;
posX++;
for(let method of Object.keys(Statement.sourceAmount)){
let label = method;
list[label] = buttonFromParams(label, `${method[0]}. ${Expression.expressionMap[method[1]]}`, defaultButtonWidth, posX, posY);
posY ++;
}
posY = 0;
posX ++;
for(let number = 1; number <= 15; number ++){
let label = number;
list[label] = buttonFromParams(label, number, defaultButtonWidth, posX, posY);
posY ++;
}
posY = 0
posX++;
list['d0'] = buttonFromParams('d0', '[^]', defaultButtonWidth, posX, posY);
posY ++;
list['d1'] = buttonFromParams('d1', '[<]', defaultButtonWidth, posX, posY);
posY ++;
list['d2'] = buttonFromParams('d3', '[>]', defaultButtonWidth, posX, posY);
posY ++;
list['d3'] = buttonFromParams('d2', '[v]', defaultButtonWidth, posX, posY);
posY ++;
list['mode'] = buttonFromParams('mode', 'mode', defaultButtonWidth, posX, posY);
posY ++;
list['del'] = buttonFromParams('del', 'del', defaultButtonWidth, posX, posY);
posY ++;
posY = 0;
posX ++;
for(let i of Object.keys(list)){
if(list[i].label == 'mode'){
list[i].color = "#ffff00";
list[i].onPress = inputHandler;
list[i].onHover = function(){
rect(mouseX - 120, mouseY, 120, 180);
text(`yellow (default) - insert mode - will insert the next expression below the pointer
blue - replace mode - will replace the expresson of the current line`, mouseX + 10 - 120, mouseY + 10, 100, 300);
}
continue;
}
list[i].onHover = function(){
this.color = "#999999";
};
list[i].onPress = inputHandler;
list[i].onOutside = function(){
this.color = "#b4b4c8";
};
}
return list;
}