forked from zetsin/node-sdl2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·178 lines (145 loc) · 3.87 KB
/
test.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
'use strict'
const NS = require('../index')
// Test app begin
const App = NS.app
App.on('before-quit', function (event) {
// event.preventDefault()
})
// Test image preload
const Image = NS.image
let lena = new Image(__dirname + '/lena.jpg')
// Test font preload
const Font = NS.font
let font = new Font(__dirname + '/华文黑体.ttf')
// Test window begin
const Window = NS.window
let win = new Window
win.on('close', function() {
App.quit()
})
win.on('change', function() {
draw()
})
// Test window Setter
// win.focus = true
// win.grab = true
// win.show = false // BUG on Mac
win.bounds = [100, 100, 200, 200]
// win.minimumSize = [500, 500]
// win.maximumSize = [600, 600]
win.minimize = true
win.minimize = false
win.maximize = true
// win.fullScreen = true
// win.closable = false
win.title = 'TEST'
win.bordered = false
win.background = 0xFFFFFF
// Test window Getter
console.log('Test window Getter')
console.log(win.focus)
console.log(win.grab)
console.log(win.show)
console.log(win.bounds)
console.log(win.minimumSize)
console.log(win.maximumSize)
console.log(win.minimize)
console.log(win.maximize)
console.log(win.fullScreen)
console.log(win.closable)
// test window static methods
// console.log(Window.all.length)
// console.log(Window.focused)
// console.log(Window.mouseFocused)
// console.log(Window.keyboardFocused)
// console.log(Window.grabbed)
// console.log(Window.screenSaver)
// Window.screenSaver = true
// console.log(Window.fromID(1))
Window.showMessageBox({
type: 'error',
title: 'Test Message Box Title',
message: 'Test MEssage Box Message',
buttons: [
{
type: 'yes',
text: 'Test Message Box Button'
}
]
})
// setInterval(draw, 1000 / 24)
function draw() {
let render = win.render
let size = render.outputSize
// Test render fill rects
render.color = 0x00FFFF
render.fillRect((new Array(5)).join(' ').split('').map(() => {
return [
parseInt(Math.random() * size.w),
parseInt(Math.random() * size.h),
parseInt(Math.random() * size.w / 20),
parseInt(Math.random() * size.h / 20),
]
}))
// Test render draw rects
render.color = 0x00FF00
render.drawRect((new Array(100)).join(' ').split('').map(() => {
return [
parseInt(Math.random() * size.w),
parseInt(Math.random() * size.h),
parseInt(Math.random() * size.w),
parseInt(Math.random() * size.h),
]
}))
// Test render draw lines
render.color = 0xFF0000
render.drawLine((new Array(100)).join(' ').split('').map(() => {
return [parseInt(Math.random() * size.w), parseInt(Math.random() * size.h)]
}))
// Test render draw Points, its slow
render.color = 0x0000FF
render.drawPoint((new Array(1000)).join(' ').split('').map(() => {
let size = render.outputSize
return [parseInt(Math.random() * size.w), parseInt(Math.random() * size.h)]
}))
// Test render copy image
render.copy(lena.texture(render), null, [size.w / 3, size.h / 3, size.w / 3, size.h / 3])
// Test render copy font
let text = font.blend('你好, Hello', [0xaaaaaa, 0xaa], 0xffffff)
render.cut(text.texture(render))
// Test render.gfx
let gfx = render.gfx
gfx.rectFilled(100, 100, 400, 400, [0xabcdef, 100])
gfx.ellipseFilled(200, 600, 200, 300, 0xfedcba)
gfx.pieFilled(200, 1000, 100, 0, 100, 0xefcdab)
gfx.trigonFilled(300, 1200, 400, 1200, 500, 1000, 0x0000FF)
gfx.bezier([
[300, 400],
[200, 500],
[700, 300]
], 999, 0x667788)
// BUG
// gfx.polygonImage([
// [400, 400],
// [400, 500],
// [500, 400]
// ], lena)
// update window buffer
render.present()
}
// Test mouse begin
let Mouse = NS.mouse
Mouse.setCursor('hand')
Mouse.capture = false
// Mouse.relative = true
// Mouse.show = false
console.log(Mouse.state)
// Test keyboard begin
let Keyboard = NS.keyboard
Keyboard.setTextInput([400, 400, 500, 500])
Keyboard.startTextInput()
Keyboard.stopTextInput()
console.log(Keyboard.hasTextInput)
console.log(Keyboard.hasScreenKeyboard)
console.log(Keyboard.state)
console.log(Keyboard.mod)