mirror of
https://github.com/danbulant/node-x11
synced 2026-06-12 19:20:42 +00:00
AllocColor request
This commit is contained in:
parent
8cf496a220
commit
30f2f74d59
2 changed files with 62 additions and 0 deletions
|
|
@ -339,6 +339,20 @@ module.exports = {
|
|||
return [format, args];
|
||||
}
|
||||
],
|
||||
|
||||
AllocColor: [
|
||||
[ 'CxSLSSSxx', [84, 4] ], // params: colormap, red, green, blue
|
||||
|
||||
function(buf) {
|
||||
var res = buf.unpack('SSSxL');
|
||||
var color = {};
|
||||
color.red = res[0];
|
||||
color.blue = res[1];
|
||||
color.green = res[2];
|
||||
color.pixel = res[3];
|
||||
return color;
|
||||
}
|
||||
],
|
||||
|
||||
QueryExtension: [
|
||||
function(name) {
|
||||
|
|
|
|||
48
test/alloccolor.js
Normal file
48
test/alloccolor.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
var x11 = require('../lib/x11');
|
||||
|
||||
var xclient = x11.createClient();
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var pts = [];
|
||||
|
||||
xclient.on('connect', function(display) {
|
||||
var X = this;
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(
|
||||
wid, root,
|
||||
10, 10, 400, 300,
|
||||
1, 1, 0,
|
||||
{
|
||||
backgroundPixel: white, eventMask: Exposure|PointerMotion
|
||||
}
|
||||
);
|
||||
X.MapWindow(wid);
|
||||
|
||||
var gc = X.AllocID();
|
||||
X.AllocColor(display.screen[0].default_colormap, 0xffff, 0, 0, function(redcolor) {
|
||||
// todo: it is possible for PolyLine to be called before CreateGC!
|
||||
console.log(redcolor);
|
||||
X.CreateGC(gc, wid, { foreground: redcolor.pixel, background: white } );
|
||||
});
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 12)
|
||||
{
|
||||
if (pts.length > 4)
|
||||
X.PolyLine(0, wid, gc, pts);
|
||||
} else if (ev.type == 6) {
|
||||
pts.push(ev.x);
|
||||
pts.push(ev.y);
|
||||
if (pts.length > 4)
|
||||
X.PolyLine(0, wid, gc, pts.slice(-4));
|
||||
}
|
||||
});
|
||||
|
||||
X.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue