#include #include #include #include "graphics.h" Point screenRes = {0, 0}; Image *background = nil; Image *ball = nil; int r = 20; /* ball radius */ static Point *ballPos = nil; void initGraphics(Point *pBallPos) { ballPos = pBallPos; screenRes = Pt(Dx(screen->r), Dy(screen->r)); Image *brush = allocimage(display, Rect(0, 0, 1, 1), CMAP8, 1, DRed); background = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DBlack); ball = allocimage(display, Rect(0, 0, r * 4, r * 4), screen->chan, 0, DBlack); fillellipse(ball, Pt(r*2,r*2), r, r, brush, ZP); freeimage(brush); } /* shamelessly lifted from page.c and modified to suit */ void resizewin(Point size) { int wctl; if((wctl = open("/dev/wctl", OWRITE)) < 0) return; /* add rio border */ size = addpt(size, Pt(Borderwidth*2, Borderwidth*2)); if(display->image != nil){ Point dsize = subpt(display->image->r.max, display->image->r.min); if(size.x > dsize.x) size.x = dsize.x; if(size.y > dsize.y) size.y = dsize.y; /* can't just conver whole display */ if(eqpt(size, dsize)) size.y--; } fprint(wctl, "resize -dx %d -dy %d\n", size.x, size.y); close(wctl); /* initdraw() must also be called after resizing. */ if(initdraw(nil, nil, "Another Plan") < 0) { sysfatal("initdraw failed: %r"); } /* * TODO: use something like libdraw's scalesize() * to upscale the native 320x200 res. */ } void render(void) { draw( screen, screen->r, display->black, nil, ZP ); draw( screen, rectaddpt(screen->r, *ballPos), ball, nil, ZP ); } void eresized(int new) { if (new && getwindow(display, Refnone) < 0) { sysfatal("can't reattach to window"); } screenRes = Pt(Dx(screen->r), Dy(screen->r)); render(); }