#include "paint.h" Point sdim; /* the dimensions of a sector in pixels */ Point gdim; /* the dimensions of the grid in sectors */ int nbits, nbytes; static int init(Widget *w) { Canvas *c; Point wdim; c = w->aux; sdim = Pt(32, 32); wdim = subpt(w->r.max, w->r.min); gdim.x = (wdim.x + sdim.x - 1) / sdim.x; gdim.y = (wdim.y + sdim.y - 1) / sdim.y; nbits = gdim.x * gdim.y; nbytes = (nbits + 7) / 8; fprint(2, "%P %P %P bits %d bytes %d\n", c->img->r.max, wdim, gdim, nbits, nbytes); return 0; } static int mouse(Widget *w, Mousectl *mctl) { Point mempt, sec; int bit, byte; uchar mask; if(!mctl->buttons) return 0; while(mctl->buttons) readmouse(mctl); mempt = stompt(mctl->xy, w); sec.x = (mempt.x < 0 ? mempt.x - sdim.x : mempt.x) / sdim.x; sec.y = (mempt.y < 0 ? mempt.y - sdim.y : mempt.y) / sdim.y; bit = sec.y * gdim.x + sec.x; byte = bit / 8; mask = 0x80 >> bit - byte*8; fprint(2, " s %P m %P se %P b %d map[%d] & %.2uhhx %s\n", mctl->xy, mempt, sec, bit, byte, mask, ptinrect(sec, Rpt(ZP, gdim)) ? "inside" : "outside" ); return 0; } CanvasTool probe = { mouse, init, };