mirror of
https://github.com/danbulant/node-x11
synced 2026-06-18 14:11:29 +00:00
CreateNotify, MapNotify; CopyArea example
This commit is contained in:
parent
e23f1caa68
commit
f434e589e8
1 changed files with 51 additions and 0 deletions
51
test/copyarea.js
Normal file
51
test/copyarea.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
var x11 = require('../lib/x11');
|
||||
var Window = require('./wndwrap');
|
||||
|
||||
x11.createClient(function(display) {
|
||||
|
||||
var pts = [];
|
||||
new Window(display.client, 0, 0, 700, 500)
|
||||
.handle({
|
||||
|
||||
map: function(ev) {
|
||||
this.pixmap = this.createPixmap(700, 500);
|
||||
},
|
||||
|
||||
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.pixmap.gc.polyLine(pts[i]);
|
||||
}
|
||||
// todo: resize
|
||||
this.gc.copy(this.pixmap, 0, 0, 0, 0, 700, 500);
|
||||
}
|
||||
|
||||
})
|
||||
.map()
|
||||
.title = 'Hello, world!';
|
||||
}).on('error', function(err) {
|
||||
console.error(err);
|
||||
});
|
||||
Loading…
Reference in a new issue