mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 09:12:13 +00:00
AllocColor request
This commit is contained in:
parent
8cf496a220
commit
30f2f74d59
2 changed files with 62 additions and 0 deletions
|
|
@ -340,6 +340,20 @@ module.exports = {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
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: [
|
QueryExtension: [
|
||||||
function(name) {
|
function(name) {
|
||||||
var padded = xutil.padded_string(name);
|
var padded = xutil.padded_string(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