mirror of
https://github.com/danbulant/node-x11
synced 2026-06-14 12:11:26 +00:00
example with subwindows grid
This commit is contained in:
parent
6cf8937e2a
commit
660c308527
2 changed files with 75 additions and 3 deletions
68
test/subwindows.js
Normal file
68
test/subwindows.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
var x11 = require('../lib/x11');
|
||||
var Window = require('./wndwrap');
|
||||
|
||||
x11.createClient(function(display) {
|
||||
|
||||
var pts = [];
|
||||
new Window(display.client, 0, 0, 600, 400, display.screen[0].white_pixel)
|
||||
.handle({
|
||||
|
||||
create: function(ev) {
|
||||
console.log(eve);
|
||||
},
|
||||
|
||||
map: function(ev) {
|
||||
console.log(ev);
|
||||
|
||||
for (var i=0; i < 29; ++i)
|
||||
for (var j=0; j < 19; ++j)
|
||||
{
|
||||
new Window( this, 10+i*20, 10+j*20, 17, 17, display.screen[0].black_pixel)
|
||||
.handle({
|
||||
mousemove: function() {
|
||||
var self = this;
|
||||
self.unmap();
|
||||
setTimeout(function() {
|
||||
self.map();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
})
|
||||
.map();
|
||||
}
|
||||
},
|
||||
|
||||
mousemove: function(ev) {
|
||||
if (this.pressed)
|
||||
{
|
||||
var lastpoly = pts[pts.length - 1];
|
||||
lastpoly.push(ev.x);
|
||||
lastpoly.push(ev.y);
|
||||
if (lastpoly.length > 3)
|
||||
this.gc.polyLine(lastpoly.slice(-4));
|
||||
}
|
||||
},
|
||||
|
||||
mousedown: function(ev) {
|
||||
if (ev.keycode == 1) // left button
|
||||
{
|
||||
this.pressed = true;
|
||||
pts.push([]);
|
||||
}
|
||||
},
|
||||
|
||||
mouseup: function(ev) {
|
||||
if (ev.keycode == 1) // left button
|
||||
this.pressed = false;
|
||||
},
|
||||
|
||||
expose: function(ev) {
|
||||
//for (var i=0; i < pts.length ; ++i) {
|
||||
// this.gc.polyLine(pts[i]);
|
||||
//}
|
||||
}
|
||||
|
||||
})
|
||||
.map()
|
||||
.title = 'Hello, world!';
|
||||
});
|
||||
|
|
@ -15,7 +15,8 @@ function GraphicContext(win)
|
|||
this.xclient = win.xclient;
|
||||
this.id = this.xclient.AllocID();
|
||||
var screen = this.xclient.display.screen[0];
|
||||
win.xclient.CreateGC(this.id, win.id, { foreground: screen.black_pixel, background: screen.white_pixel});
|
||||
//win.xclient.CreateGC(this.id, win.id, { foreground: screen.black_pixel, background: screen.white_pixel});
|
||||
this.xclient.CreateGC(this.id, win.id, { foreground: screen.white_pixel, background: screen.black_pixel});
|
||||
}
|
||||
|
||||
GraphicContext.prototype.polyLine = function(points)
|
||||
|
|
@ -60,7 +61,7 @@ GraphicContext.prototype.copy = function(srcDrawable, srcX, srcY, dstX, dstY, wi
|
|||
this.xclient.CopyArea(srcDrawable.id, this.win.id, this.id, srcX, srcY, dstX, dstY, width, height);
|
||||
}
|
||||
|
||||
function Window(parent, x, y, w, h)
|
||||
function Window(parent, x, y, w, h, bg)
|
||||
{
|
||||
if (parent.constructor && parent.constructor.name == 'XClient')
|
||||
{
|
||||
|
|
@ -90,6 +91,9 @@ function Window(parent, x, y, w, h)
|
|||
this.white = this.xclient.display.screen[0].white_pixel;
|
||||
this.id = this.xclient.AllocID();
|
||||
|
||||
if (!bg)
|
||||
bg = this.white;
|
||||
|
||||
var borderWidth = 1;
|
||||
var _class = 1; // InputOutput
|
||||
var visual = 0; // CopyFromParent
|
||||
|
|
@ -97,7 +101,7 @@ function Window(parent, x, y, w, h)
|
|||
this.id, this.parent.id, this.x, this.y, this.w, this.h,
|
||||
borderWidth, _class, visual,
|
||||
{
|
||||
backgroundPixel: this.white,
|
||||
backgroundPixel: bg,
|
||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|SubstructureNotify|StructureNotify
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue