This is a highly experimental, rapidly-changing project. The APIs might change overnight.
Node-Five brings a subset of HTML5 APIs to Node.js. Presently the main focus is on low-level graphics and audio (for example, Canvas
and AudioContext
), but other higher-level APIs are welcome. (HTML/CSS layout engine, anyone?)
Node-Five is written in JavaScript on top of Node-Qt.
This example illustrates a minimal use of the HTML5 Canvas API:
var five = require('path-to-node-five-dir'),
window = new five.Window(300, 150),
canvas = new five.Canvas(window),
ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillText('hello node, hello qt', 20, 20);
For other examples see the demos/ directory.
Since the project is under heavy development, no npm packages are available at the moment. To start, clone the latest development version and install the necessary dependencies:
$ git clone git://github.com/arturadib/node-five.git
$ cd node-five
$ npm install
If everything went well you should be able to run the demos, for example:
$ node demos/03-game-goblins/game.js
To run the unit tests:
$ node make test
(Since different platforms generate different images based on several factors, it's likely the image-based regression tests will fail on your setup. Ignore those errors).
Main object. Typical usage is:
var five = require('path-to-node-five-dir');
Add event handler to Node's event loop via setTimeout(). This is the default event loop integration.
Add event handler to Node's event loop via process.nextTick()
.
This should used in applications that require more instant responsiveness (CPU-intensive!).
Stop Node-Five's event loop. Applications never exit without a call to this method.
Native window constructor with the given height
and width
.
Gets/sets window width in pixels
Gets/sets window height in pixels
Closes window. It can't be reopened.
Binds event
to callback
. Supported events are listed below.
Removes callback from event
handler.
-
mousedown
: Callback will be passed{ clientX, clientY, button }
.button
values correspond to the convenience constantsfive.LeftButton
,five.RightButton
, etc. See http://developer.qt.nokia.com/doc/qt-4.8/qt.html#MouseButton-enum for a list of supported button codes -
mouseup
: Callback will be passed{ clientX, clientY, button }
as inmousedown
. -
mousemove
: Callback will be passed{ clientX, clientY }
. -
keydown
: Callback will be passed{ key, char }
. Key values correspond to the convenience constantsfive.Key_Esc
,five.Key_Left
, etc. See http://developer.qt.nokia.com/doc/qt-4.8/qt.html#Key-enum for the list of supported keys.char
is the corresponding Unicode character, if available. -
keyup
: Callback will be passed{ key, char }
. Details as inkeydown
.
Class/constructor for Canvas objects, either off-screen (no window
argument) or inside an existing window
.
(Non-standard) Width of the canvas view. Will crop canvas and create
scroll bars if smaller than the canvas width
.
(Non-standard) Height of the canvas view. Will crop canvas and create scroll bars if smaller
than the canvas height
.
Vertical scroll position. To be used when height > viewHeight
.
Maximum value is height - viewHeight
.
Horizontal scroll position. To be used when width > viewWidth
.
Maximum value is width - viewWidth
.
(Non-standard) Top position of the canvas with respect to parent window (if any), in pixels. Only absolute positioning is available.
(Non-standard) Left position of the canvas with respect to parent window (if any), in pixels. Only absolute positioning is available.
Presently only supports type == '2d'
.
The documentation below is for exposed methods after a ctx = canvas.getContext('2d')
call, which returns a CanvasRenderingContext2D
object.
Currently only supports color types (e.g. 'rgb()'
, 'rgba()'
, 'blue'
, '#aabbcc'
, etc)
Currently only supports color types (e.g. 'rgb()'
, 'rgba()'
, 'blue'
, '#aabbcc'
, etc)
Currently only supports the format above
Presently only supports images created via five.Image()
Constructor for image objects. Intended to mirror Image()
constructor from browsers.
Presently only supports local paths, e.g. ./images/file.png
Class/constructor for AudioContext objects.
Currently returns null
Returns a new AudioBufferSourceNode object
The documentation below is for exposed methods after a source = context.createBufferSource()
call, which returns an AudioBufferSourceNode
object.
Non-compliant. Presently must specify local filename.
dest
is currently a dummy variable. The destination will always
be the default audio device
Currently when = 0
, i.e. immediately