gdi
v0.3.8
Published
Node.js bindings to Windows GDI/GDI+ (graphics device interface)
Downloads
5
Maintainers
Readme
node-gdi
Node.js bindings to Windows GDI/GDI+ (graphics device interface)
Uses GDI for text rendering and GDI+ for graphics elements.
Beta version, development in progress...
Install
npm i gdi
Usage
Some examples can be found in the examples directory.
Example
const GDILib = require('gdi');
// create window
const window = GDILib.init({ title: 'GDILib - Example 1.' });
let angle = 0;
window.onPaint(g => {
// clear screen to gray
// g.clear(r, g, b)
g.clear(39, 40, 34);
// draw text
// g.penColor(r, g, b, a = 255)
g.penColor(255, 255, 255);
// g.font(name, size, weight)
g.font('Consolas', 16, 400);
// g.text(x, y, str)
g.text(30, 30, 'Hello world from GDILib!');
// draw colored triangle
g.penColor(255, 0, 0) ;
// g.line(startX, startY, endX, endY)
g.line(400, 30, 500, 200);
g.penColor(0, 255, 0);
g.line(400, 30, 300, 200);
g.penColor(0, 0, 255) ;
g.line(300, 200, 500, 200);
// draw rotating rectangle
// g.rotate(angle, originX, originY)
g.rotate(angle, 50 + 80, 50 + 80);
g.penColor(255, 255, 255);
// g.rectangle (x, y, width, height)
g.rectangle(80, 80, 100, 100);
});
setInterval(() => {
angle += 1;
window.repaint();
}, 25);
GDILib methods
GDILib.init(options)
options = {
title: 'GDI Window',
width: 600,
height: 400,
backgroundColor: [39, 40, 34],
frameless: false,
titleBarHeight: 0,
transparency: false,
transparentColor: [255, 0, 0],
alwaysOnTop: false,
persistPosition: true,
minWidth: 150,
minHeight: 150
};