项目作者: Daninet

项目描述 :
Node.js bindings to Windows GDI (graphics device interface)
高级语言: JavaScript
项目地址: git://github.com/Daninet/node-gdi.git
创建时间: 2018-08-05T15:37:40Z
项目社区:https://github.com/Daninet/node-gdi

开源协议:MIT License

下载


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

  1. npm i gdi

Usage

Some examples can be found in the examples directory.

Example

  1. const GDILib = require('gdi');
  2. // create window
  3. const window = GDILib.init({ title: 'GDILib - Example 1.' });
  4. let angle = 0;
  5. window.onPaint(g => {
  6. // clear screen to gray
  7. // g.clear(r, g, b)
  8. g.clear(39, 40, 34);
  9. // draw text
  10. // g.penColor(r, g, b, a = 255)
  11. g.penColor(255, 255, 255);
  12. // g.font(name, size, weight)
  13. g.font('Consolas', 16, 400);
  14. // g.text(x, y, str)
  15. g.text(30, 30, 'Hello world from GDILib!');
  16. // draw colored triangle
  17. g.penColor(255, 0, 0) ;
  18. // g.line(startX, startY, endX, endY)
  19. g.line(400, 30, 500, 200);
  20. g.penColor(0, 255, 0);
  21. g.line(400, 30, 300, 200);
  22. g.penColor(0, 0, 255) ;
  23. g.line(300, 200, 500, 200);
  24. // draw rotating rectangle
  25. // g.rotate(angle, originX, originY)
  26. g.rotate(angle, 50 + 80, 50 + 80);
  27. g.penColor(255, 255, 255);
  28. // g.rectangle (x, y, width, height)
  29. g.rectangle(80, 80, 100, 100);
  30. });
  31. setInterval(() => {
  32. angle += 1;
  33. window.repaint();
  34. }, 25);

GDILib methods

GDILib.init(options)

  1. options = {
  2. title: 'GDI Window',
  3. width: 600,
  4. height: 400,
  5. backgroundColor: [39, 40, 34],
  6. frameless: false,
  7. titleBarHeight: 0,
  8. transparency: false,
  9. transparentColor: [255, 0, 0],
  10. alwaysOnTop: false,
  11. persistPosition: true,
  12. minWidth: 150,
  13. minHeight: 150
  14. };

Window methods

window.close()

window.getClipboard()

window.getPosition()

window.getSize()

window.hide()

window.maximize()

window.messageBox(text, title = ‘Message’)

window.minimize()

window.onClick(cb)

window.onClose(cb)

window.onCreate(cb)

window.onCustomMsg(cb)

window.onKeyDown(cb)

window.onKeyPress(cb)

window.onKeyUp(cb)

window.onMouseDown(cb)

window.onMouseMove(cb)

window.onMouseUp(cb)

window.onMouseWheel(cb)

window.onPaint(cb)

window.onResize(cb)

window.repaint()

window.restore()

window.setClipboard(str)

window.setCursor(type)

window.setPosition(x, y)

window.setSize(width, height)

window.setTitle(title)

window.show()

Graphics methods

p.arc(x, y, width, height, startAngle, sweepAngle)

p.bezier(points)

p.brushColor(r, g, b, a = 255)

p.brushLinearGradient(x1, y1, x2, y2, r1, g1, b1, r2, g2, b2, a1 = 255, a2 = 255)

p.brushRadialGradient(x, y, width, height, r1, g1, b1, r2, g2, b2, a1 = 255, a2 = 255)

p.clear(r, g, b, a = 255)

p.curve(points, close = false, fill = false)

p.ellipse(x, y, width, height, stroke = true, fill = false)

p.flush()

p.font(name, size = 14, weight = 400, italic = false, underline = false, strikeout = false)

p.image(x, y, buf, width = -1, height = -1, srcX = 0, srcY = 0, srcWidth = -1, srcHeight = -1)

p.line(x1, y1, x2, y2)

p.measure(text, width, height)

p.penColor(r, g, b, a = 255)

p.penWidth(width)

p.pie(x, y, width, height, startAngle, sweepAngle, stroke = true, fill = false)

p.polygon(points, stroke = true, fill = false)

p.rectangle(x, y, width, height, stroke = true, fill = false)

p.resetClip()

p.resetTransform()

p.rotate(angle, originX = 0, originY = 0)

p.setClip(x, y, width, height, combineMode = ‘REPLACE’)

p.setFormatFlags(flags)

p.setTrimming(trimming)

p.text(x, y, text, width, height)