npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bunchtogether/node-sdl2

v2.1.3

Published

Bindings for SDL2 in Node

Downloads

1

Readme

node-sdl2

Bindings for SDL2 in Node

Installation

Install with npm:

npm install node-sdl2

Usage

1. Use with wrapped class ( Api Reference )

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 = () => {
  ...
}

2. Use as primitive SDL2 API ( SDL 2.0 API by Category )

const NS = require('node-sdl2')
const SDL2_video = NS.require('SDL2_video')
const SDL2_render = NS.require('SDl2_render')
...

Tutorials

Screenshot

Screenshot

API References

app

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 String

window

Create 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] Object
    • win.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] Integer
    • win.focus
      • [Getter/Setter] Boolean
    • win.grab
      • [Getter/Setter] Boolean
    • win.show
      • [Getter/Setter] Boolean
    • win.maximize
      • [Getter/Setter] Boolean
    • win.minimize
      • [Getter/Setter] Boolean
    • win.fullScreen
      • [Getter/Setter] Boolean
    • win.resizable
      • [Getter] Boolean
    • win.closable
      • [Getter/Setter] Boolean
    • win.position
      • [Getter/Setter] Boolean
    • win.title
      • [Getter/Setter] String
    • win.background
      • [Getter/Setter] Integer
    • win.bordered
      • [Setter] Boolean
    • win.screenKeyboard
      • [Getter] Boolean
    • static window.all
      • [Getter] win
    • static window.focused
      • [Getter] win
    • static window.mouseFocused
      • [Getter] win
    • static window.keyboardFocused
      • [Getter] win
    • static window.grabbed
      • [Getter] win
    • static window.mouseFocused
      • [Getter] win
    • static window.screenSaver
      • [Getter] win
    • static window.fromID
      • [Getter] win
    • static window.showMessageBox(opts, cb)
  • Events

    • win.on('change', (w, h) => {})
      • w Integer
      • h Integer
    • win.on('close', (event) => {}
      • event Object
        • preventDefault()
    • win.on('show', () => {})
    • win.on('hide', () => {})
    • win.on('move', (x, y) => {})
      • x Integer
      • y Integer
    • win.on('resize', (w, h) => {})
      • w Integer
      • h Integer
    • win.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 Integer
        • scanname String
        • keycode Integer
        • keyname String
        • repeat Boolean
    • win.on('keyup', (key) => {})
      • key Object
        • scancode Integer
        • scanname String
        • keycode Integer
        • keyname String
        • repeat Boolean
    • win.on('editing', ({str, start, length}) => {})
      • str String
      • start Integer
      • length Integer
    • win.on('textinput', (str) => {})
      • str String
    • win.on('mousemove', (pos) => {})
      • pos Object
        • x Integer
        • y Integer
        • xrel Integer
        • yrel Integer
    • win.on('mousedown', (mou) => {})
      • mou Object
        • x Integer
        • y Integer
        • clicks Integer
        • button String
    • win.on('mouseup', (mou) => {})
      • mou Object
        • x Integer
        • y Integer
        • clicks Integer
        • button String
    • win.on('mousewheel', (mou) => {})
      • mou Object
        • x Integer
        • y Integer
        • clicks Integer
        • button String

clipboard

Get and set the clipboard text.

  • Methods

    • clipboard.text
      • [Getter/Setter] String
    • clipboard.hasText
      • [Getter] Boolean
  • Events

    • Event 'update'

keyboard

Control the keyboard.

  • Methods
    • keyboard.startTextInput()
    • keyboard.stopTextInput()
    • keyboard.setTextInput(rect)
      • rect Object|Array - { x, y, w, h }
    • keyboard.hasTextInput
      • [Getter] Boolean
    • keyboard.hasScreenKeyboard
      • [Getter] Boolean
    • keyboard.state
      • [Getter] Object
    • keyboard.mod
      • [Getter] Object

mouse

Control the mouse and cursor.

  • Methods
    • mouse.setCursor(id)
    • mouse.setCursor(image, hot_x, hot_y)
    • mouse.setCursor(data, mask, w, h, hot_x, hot_y)
    • mouse.capture
      • [Setter] Boolean
    • mouse.relative
      • [Getter/Setter] Boolean
    • mouse.show
      • [Getter/Setter] Boolean
    • mouse.state
      • [Getter] Object
        • win Object
          • x Integer
          • y Integer
        • global Object
          • x Integer
          • y Integer
        • relative Object
          • x Integer
          • y Integer

power

Moniter the power infomation of hardware

  • Methods
    • power.info
      • [Getter] Object
        • life Integer
        • percentage Integer
        • state String

font

Allow you drawing text into window's face. please npm install sdl2-ttf before use.

  • Methods
    • let ft = new font(file, pixelsize, index)
      • file String
      • pixelsize Integer
      • index Integer
    • ft.style
      • [Geter/Setter] String
    • ft.outline
      • [Geter/Setter] Integer
    • ft.hinting
      • [Geter/Setter] Integer
    • ft.kerning
      • [Geter/Setter] Integer
    • ft.height
      • [Geter] Integer
    • ft.ascent
      • [Geter] Integer
    • ft.descent
      • [Geter] Integer
    • ft.lineSkip
      • [Geter] Integer
    • ft.solid(text, rgba)
      • text String
      • rgba Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]
    • ft.shade(text, rgba, rgbaBG)
      • text String
      • rgba 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 String
      • rgba Integer|Object|Array - rgb | { rgb, a } | { r, g, b, a } | [rgb, a]
    • ft.close()
    • ft.test(char)
      • char String
    • ft.metrics(char)
      • char String
    • ft.getSize(char)
      • char String
    • static font.init()
    • static font.wasInit()
    • static font.quit()

image

Load image from file. please npm install sdl2-image before use.

  • Methods

    • let img = new image(file)
      • file String
    • img.free()
    • img.texture(render)
    • static Image.init()
    • static Image.quit()