#!/usr/local/bin/rune -x # # Graphical test import "sys"; import ; import ; alias stdio.File *stdout = stdio.stdout; typedef gfx.Event Event; typedef gfx.Frame Frame; subclass Frame as MyFrame { int holding; gfx.Point savePos; refine public method bool refreshFrame(int x, int y, int w, int h) { int i; int j; for (i = 0; i < 512; i += 32) { for (j = 0; j < 512; j += 32) { this.drawLine(0, i, j, 0); } } } refine public method int mouseMoved(Event *ev) { if (this.holding == Event.XK_Pointer_Button1) this.drawLineTo(ev->pos.x, ev->pos.y); if (this.holding == Event.XK_Pointer_Button2) this.drawPoint(ev->pos.x, ev->pos.y); } refine public method int buttonPressed(Event *ev) { switch(ev->keySym) { case Event.XK_Pointer_Button1: this.savePos = ev->pos; /* fall through */ case Event.XK_Pointer_Button2: this.drawPoint(ev->pos.x, ev->pos.y); this.holding = ev->keySym; stdout->show("position", ev->pos.x, ev->pos.y); break; case -Event.XK_Pointer_Button1: case -Event.XK_Pointer_Button2: if (this.holding == Event.XK_Pointer_Button1) { this.drawLineTo(ev->pos.x, ev->pos.y); } this.holding = 0; break; case Event.XK_Pointer_Button3: this.pen->setFGColor(0xFFFF, 0, 0); this.savePos = ev->pos; break; case -Event.XK_Pointer_Button3: this.fillRect(this.savePos.x, this.savePos.y, ev->pos.x, ev->pos.y); break; default: if (ev->keySym > 0 && ev->keyChar > 0UB) { this.drawText(this.savePos.x, this.savePos.y, &ev->keyChar, 1); this.savePos.x += this.textWidth(&ev->keyChar, 1); } } } } int waiting; int main(int ac, char **av) { MyFrame *frame; int i; int j; frame.createFrame("BODY", &gfx.root, 512, 512, BODY); frame->recalc(); frame->flush(); # If we unlink and NULL out the frame, there will be no refs # and Rune should destroy it. # # If we do not unlink the frame the frame thread will prevent # us from dying. # #stdout->show("should exit after 2.5 seconds"); delayedwake(); Thread.tsleep(&waiting, 5000); stdout->show("main woke up"); frame->unlinkFrame(); # frame->destroyFrame(); - NULLing it out should be good enough frame = NULL; stdout->show("waiting"); Thread.waitThreads(); # wait until all threads have exited stdout->show("returning"); return(0); } thread void delayedwake() { result; Thread.mssleep(2500); Thread.wakeup(&waiting); }