-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
161 lines (143 loc) · 3.92 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
var inputStr = '';
Include('./ui/uiapp.js');
Include('./demos/dlgdemo.js');
Include('./demos/scrdemo.js');
Include('./demos/ascdemo.js');
Include('./demos/wdgdemo.js');
function Setup() {
inputStr = ''
SetFramerate(60);
MouseShowCursor(true);
MouseSetCursorMode(1);
//SetExitKey(KEY.Code.KEY_F12);
SetExitKey(KEY.Code.NO_KEY);
// setup screen
app = new UIApp();
app.showFps = false;
app.showMemStats = false;
app.enableDebugWindow = true;
app.showLastDrawTick = false;
app.init();
/**
* Demos that the user can test/see
*/
var demoExamples = [
{
label: 'Component/widget showcase',
keyCode: 7170,
keyLabel: 'Ctrl+1',
onClick: function() {
if (app.doesWindowExistsById('widgetsDemo')) {
app.showWindow('widgetsDemo')
} else {
app.addWindow(new WidgetsDemo());
}
}
},
{
label: 'Text input example',
keyCode: 7426,
keyLabel: 'Ctrl+2',
onClick: function() {
app.showWindow('window2')
}
},
{
label: 'Ascii table',
keyCode: 7682,
keyLabel: 'Ctrl+3',
onClick: function() {
if (app.doesWindowExistsById('ascciDemo')) {
app.showWindow('ascciDemo')
} else {
app.addWindow(new AsciiTableDemo());
}
}
},
{
label: 'Dialog demo',
keyCode: 7938,
keyLabel: 'Ctrl+4',
onClick: function() {
if (app.doesWindowExistsById('dialogDemo')) {
app.showWindow('dialogDemo')
} else {
app.addWindow(new DialogDemo());
}
}
},
{
label: 'Scrollbar demo',
keyCode: 8194,
keyLabel: 'Ctrl+5',
onClick: function() {
if (app.doesWindowExistsById('scrollbarDemo')) {
app.showWindow('scrollbarDemo')
} else {
app.addWindow(new ScrollbarDemo());
}
}
},
{
label: 'About dialog',
onClick: function() {
app.showAbout()
}
}
]
/**
* Build demo window
*/
window1 = new UIWindow('window1', 'Example widgets')
window1.isClosable = false
window1.menu = [
{
label: 'Examples',
children: demoExamples,
},
]
window1.addChildren(new UIText(10, 30, 'Here are list of of demos'))
var buttonOffsetY = 50;
demoExamples.forEach(function (item) {
button = new UIButton(10, buttonOffsetY, item.label);
button.setSize(230, 24);
button.onClick = item.onClick
buttonOffsetY = buttonOffsetY + 34
window1.addChildren(button)
})
window1.setSize(250, buttonOffsetY);
window1.setPosition(-1, -1)
app.addWindow(window1);
/**
* Create input example
*/
window2 = new UIWindow('window2', 'Text input example')
window2.setSize(300, 100);
window2.setPosition(-1, -1);
window2.setVisible(false);
window2.menu = [];
// window2.addChildren(new UITextInput('Input value', 10, 30, 280, 20))
window2.addChildren(new UITextInput('Here are list of supported widgets/controls', 10, 30, 280, 20))
// window2.addChildren(new UITextInput('', 10, 30, 280, 20))
window2.addChildren(new UIButton(10, 60, 'Focus switch test'))
app.addWindow(window2);
// just do some garbage collecting if needed
Gc();
}
function Loop() {
app.loop();
// Some debug code.
// TextXY(0, SizeY() - 10, "fps:" + GetFramerate(), EGA.WHITE);
// TextXY(0, SizeY() - 20, "memory:" + JSON.stringify(MemoryInfo()), EGA.WHITE);
// TextXY(0, SizeY() - 30, "inputStr:" + inputStr, EGA.WHITE);
}
function Input(event) {
var newEvent = JSON.parse(JSON.stringify(event));
newEvent.keyCode = event.key >> 8;
inputStr = JSON.stringify(newEvent);
// forcegarbage collecting if needed
if (event.key === 1792) { // ctrl + alt + g
Gc()
}
app.input(event);
}