From 200c9c75414c788b929b941b09b670bfa685b013 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Mon, 25 Jul 2011 21:24:19 -0700 Subject: [PATCH] Edited README.md via GitHub --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 77442b9..ef97edb 100644 --- a/README.md +++ b/README.md @@ -47,20 +47,52 @@ Core requsests usage: }); -Simple core requests Window wrapper: +'click&draw' demo using simple Window wrapper: - var x11 = require('x11'); + var x11 = require('../lib/x11'); var Window = require('./wndwrap'); - var xclient = x11.createClient(); - xclient.on('connect', function(display) { - var mainwnd = new Window(xclient, 0, 0, 100, 100); - mainwnd.on('expose', function(ev) { - ev.gc.drawText(50, 50, 'Hello, NodeJS!'); - }); - mainwnd.map(); + + x11.createClient(function(display) { + + var pts = []; + new Window(display.client, 0, 0, 700, 500) + .handle({ + + 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([]); // start next polyline + } + }, + + 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!'; }); + # Protocol documentation - http://www.x.org/releases/X11R7.6/doc/