From 660c308527980183a582303218141acaa7dd1bdd Mon Sep 17 00:00:00 2001 From: sidorares Date: Wed, 27 Jul 2011 17:32:47 +1000 Subject: [PATCH] example with subwindows grid --- test/subwindows.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++ test/wndwrap.js | 10 +++++-- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 test/subwindows.js diff --git a/test/subwindows.js b/test/subwindows.js new file mode 100644 index 0000000..356092f --- /dev/null +++ b/test/subwindows.js @@ -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!'; +}); diff --git a/test/wndwrap.js b/test/wndwrap.js index 136348a..824f65b 100644 --- a/test/wndwrap.js +++ b/test/wndwrap.js @@ -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 } );