Bindings for SDL2 in Node
Install with npm:
npm install node-sdl2
const NS = require('node-sdl2')
const App = NS.app
const Window = NS.window
let win = new Window
win.on('close', () => {
App.quit()
})
win.on('change', () => {
draw()
})
let draw = () => {
...
}
const NS = require('node-sdl2')
const SDL2_video = NS.require('SDL2_video')
const SDL2_render = NS.require('SDl2_render')
...
Control your application's event lifecycle.
Methods
app.quit()
app.hide()
app.show()
app.exit()
Events
app.on('window-all-closed', () = {})
app.on('before-quit', (event) = {})
event
Object
preventDefalut()
app.on('will-quit', (event) = {})
event
Object
preventDefault()
app.on('drop', (file) = {})
file
StringCreate and control
window(s)
.
Methods
let win = new window(opts)
opts
Object
tittle
String - ''
w
Integer - 0x1FFF0000
h
Integer - 0x1FFF0000
x
Integer - 0x1FFF0000
y
Integer - 0x1FFF0000
background
Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a] - 0xFF0000
center
Boolean - false
show
Boolean - true
closable
Boolean - true
resizable
Boolean - true
minimized
Boolean - false
maximized
Boolean - false
borderless
Boolean - false
fullscreen
Boolean - false
kiosk
Boolean - false
hdpi
Boolean - true
mouseCapture
Boolean - false
grab
Boolean - false
win.close()
win.destroy()
win.restore()
win.center()
win.setModal(win)
win
[Circular]win.render
[Getter]
Objectwin.size
[Getter]
Array-like Object - { w: 100, h: 200, "1": 100, "2": 200 }
[Setter]
Object|Array - { w: 100, h: 200 }
| [ 100, 200 ]
win.bounds
[Getter/Setter]
[Array-like Object / Object|Array] - { x, y, w, h }win.minimumSize
[Getter/Setter]
[Array-like Object / Object|Array] - { w, h }win.maximumSize
[Getter/Setter]
[Array-like Object / Object|Array] - { w, h }win.bordersSize
[Getter]
[Array-like Object / Object|Array] - { top, right, bottom, left }win.id
[Getter]
Integerwin.focus
[Getter/Setter]
Booleanwin.grab
[Getter/Setter]
Booleanwin.show
[Getter/Setter]
Booleanwin.maximize
[Getter/Setter]
Booleanwin.minimize
[Getter/Setter]
Booleanwin.fullScreen
[Getter/Setter]
Booleanwin.resizable
[Getter]
Booleanwin.closable
[Getter/Setter]
Booleanwin.position
[Getter/Setter]
Booleanwin.title
[Getter/Setter]
Stringwin.background
[Getter/Setter]
Integerwin.bordered
[Setter]
Booleanwin.screenKeyboard
[Getter]
Booleanwindow.all
[Getter]
winwindow.focused
[Getter]
winwindow.mouseFocused
[Getter]
winwindow.keyboardFocused
[Getter]
winwindow.grabbed
[Getter]
winwindow.mouseFocused
[Getter]
winwindow.screenSaver
[Getter]
winwindow.fromID
[Getter]
winwindow.showMessageBox(opts, cb)
Events
win.on('change', (w, h) => {})
w
Integerh
Integerwin.on('close', (event) => {}
event
Object
preventDefault()
win.on('show', () => {})
win.on('hide', () => {})
win.on('move', (x, y) => {})
x
Integery
Integerwin.on('resize', (w, h) => {})
w
Integerh
Integerwin.on('minimize', () => {})
win.on('maximize', () => {})
win.on('restore', () => {})
win.on('enter', () => {})
win.on('leave', () => {})
win.on('focus', () => {})
win.on('blur', () => {})
win.on('keydown', (key) => {})
key
Object
scancode
Integerscanname
Stringkeycode
Integerkeyname
Stringrepeat
Booleanwin.on('keyup', (key) => {})
key
Object
scancode
Integerscanname
Stringkeycode
Integerkeyname
Stringrepeat
Booleanwin.on('editing', ({str, start, length}) => {})
str
Stringstart
Integerlength
Integerwin.on('textinput', (str) => {})
str
Stringwin.on('mousemove', (pos) => {})
pos
Object
x
Integery
Integerxrel
Integeryrel
Integerwin.on('mousedown', (mou) => {})
mou
Object
x
Integery
Integerclicks
Integerbutton
Stringwin.on('mouseup', (mou) => {})
mou
Object
x
Integery
Integerclicks
Integerbutton
Stringwin.on('mousewheel', (mou) => {})
mou
Object
x
Integery
Integerclicks
Integerbutton
StringGet and set the clipboard text.
Methods
clipboard.text
[Getter/Setter]
Stringclipboard.hasText
[Getter]
BooleanEvents
Control the keyboard.
keyboard.startTextInput()
keyboard.stopTextInput()
keyboard.setTextInput(rect)
rect
Object|Array - { x, y, w, h }keyboard.hasTextInput
[Getter]
Booleankeyboard.hasScreenKeyboard
[Getter]
Booleankeyboard.state
[Getter]
Objectkeyboard.mod
[Getter]
ObjectControl the mouse and cursor.
mouse.setCursor(id)
mouse.setCursor(image, hot_x, hot_y)
mouse.setCursor(data, mask, w, h, hot_x, hot_y)
mouse.capture
[Setter]
Booleanmouse.relative
[Getter/Setter]
Booleanmouse.show
[Getter/Setter]
Booleanmouse.state
[Getter]
Object
win
Objectx
Integery
Integerglobal
Objectx
Integery
Integerrelative
Objectx
Integery
IntegerMoniter the power infomation of hardware
power.info
[Getter]
Object
life
Integerpercentage
Integerstate
StringAllow you drawing text into window's face. please
npm install sdl2-ttf
before use.
let ft = new font(file, pixelsize, index)
file
Stringpixelsize
Integerindex
Integerft.style
[Geter/Setter]
Stringft.outline
[Geter/Setter]
Integerft.hinting
[Geter/Setter]
Integerft.kerning
[Geter/Setter]
Integerft.height
[Geter]
Integerft.ascent
[Geter]
Integerft.descent
[Geter]
Integerft.lineSkip
[Geter]
Integerft.solid(text, rgba)
text
Stringrgba
Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]ft.shade(text, rgba, rgbaBG)
text
Stringrgba
Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]rgbaBG
Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]ft.blend(text, rgba)
text
Stringrgba
Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]ft.close()
ft.test(char)
char
Stringft.metrics(char)
char
Stringft.getSize(char)
char
Stringfont.init()
font.wasInit()
font.quit()
Load image from file. please
npm install sdl2-image
before use.
Methods
let img = new image(file)
file
Stringimg.free()
img.texture(render)
Image.init()
Image.quit()