From f434e589e8c553bdeda3495a75106885a45bffd8 Mon Sep 17 00:00:00 2001 From: sidorares Date: Tue, 26 Jul 2011 15:41:58 +1000 Subject: [PATCH] CreateNotify, MapNotify; CopyArea example --- test/copyarea.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/copyarea.js diff --git a/test/copyarea.js b/test/copyarea.js new file mode 100644 index 0000000..2b636d6 --- /dev/null +++ b/test/copyarea.js @@ -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); +});