make text example work when default bg color is black

This commit is contained in:
Andrey Sidorov 2018-07-09 14:01:14 +10:00
parent ce51cefdad
commit 4c6617c994

View file

@ -10,14 +10,21 @@
npm install x11 npm install x11
Windows users: Windows users:
1) install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/)
2) get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master )) 1. install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/)
2. get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master))
## Example ## Example
Core requests usage: Core requests usage:
```js ```js
/*
var nomnoml = require('nomnoml');
var src = '[nomnoml] is -> [awesome]';
console.log(nomnoml.renderSvg(src));
*/
var x11 = require('x11'); var x11 = require('x11');
var Exposure = x11.eventMask.Exposure; var Exposure = x11.eventMask.Exposure;
@ -29,18 +36,31 @@ x11.createClient(function(err, display) {
var root = display.screen[0].root; var root = display.screen[0].root;
var wid = X.AllocID(); var wid = X.AllocID();
X.CreateWindow( X.CreateWindow(
wid, root, // new window id, parent wid,
0, 0, 100, 100, // x, y, w, h root, // new window id, parent
0, 0, 0, 0, // border, depth, class, visual 0,
0,
500,
500, // x, y, w, h
0,
0,
0,
0, // border, depth, class, visual
{ eventMask: Exposure | PointerMotion } // other parameters { eventMask: Exposure | PointerMotion } // other parameters
); );
X.MapWindow(wid); X.MapWindow(wid);
var gc = X.AllocID(); var gc = X.AllocID();
X.CreateGC(gc, wid); X.CreateGC(gc, wid);
var white = display.screen[0].white_pixel;
var black = display.screen[0].black_pixel;
cidBlack = X.AllocID();
cidWhite = X.AllocID();
X.CreateGC(cidBlack, wid, { foreground: black, background: white });
X.CreateGC(cidWhite, wid, { foreground: white, background: black });
X.on('event', function(ev) { X.on('event', function(ev) {
if (ev.type == 12) if (ev.type == 12) {
{ X.PolyFillRectangle(wid, cidWhite, [0, 0, 500, 500]);
X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!']); X.PolyText8(wid, cidBlack, 50, 50, ['Hello, Node.JS!']);
} }
}); });
X.on('error', function(e) { X.on('error', function(e) {
@ -60,6 +80,7 @@ x11.createClient(function(err, display) {
![OpenGL teapot](http://img-fotki.yandex.ru/get/4132/37511094.30/0_81713_82a5ac48_L) ![OpenGL teapot](http://img-fotki.yandex.ru/get/4132/37511094.30/0_81713_82a5ac48_L)
## In use ## In use
- [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11 - [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11
- [node-remote](https://github.com/AndrewSwerlick/node-remote) - media center controller - [node-remote](https://github.com/AndrewSwerlick/node-remote) - media center controller
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager - [tiles](https://github.com/dominictarr/tiles) - tiling window manager