/* * make rectangle r in widget tk visible if possible; * if not possible, at least make point p visible. */ void tksee(Tk *tk, Rectangle r, Point p) { Point g; //print("tksee %R, %P in %s\n", r, p, tk->name->name); g = Pt(tk->borderwidth, tk->borderwidth); if(tk->parent != nil) { g = addpt(g, tkmethod[tk->parent->type]->relpos(tk)); tk = tk->parent; } else { g.x += tk->act.x; g.y += tk->act.y; tk = tk->master; } r = rectaddpt(r, g); p = addpt(p, g); while (tk != nil) { if (tkmethod[tk->type]->see != nil){ //print("see r %R, p %P in %s\n", r, p, tk->name->name); tkmethod[tk->type]->see(tk, &r, &p); //print("now r %R, p %P\n", r, p); } g = Pt(tk->borderwidth, tk->borderwidth); if (tk->parent != nil) { g = addpt(g, tkmethod[tk->parent->type]->relpos(tk)); tk = tk->parent; } else { g.x += tk->act.x; g.y += tk->act.y; tk = tk->master; } r = rectaddpt(r, g); p = addpt(p, g); } }
static void tkentrytext(Image *i, Rectangle s, Tk *tk, TkEnv *env) { TkEntry *tke = TKobj(TkEntry, tk); Point dp; int s0, s1, xs0, xs1, j; Rectangle r; Rune showr, *text; dp = Pt(s.min.x - (tke->x0 - tke->xv0), s.min.y); if (tke->show) { chartorune(&showr, tke->show); text = mallocz(sizeof(Rune) * (tke->textlen+1), 0); if (text == nil) return; for (j = 0; j < tke->textlen; j++) text[j] = showr; } else text = tke->text; runestringn(i, dp, tkgc(env, TkCforegnd), dp, env->font, text+tke->v0, tke->v1-tke->v0); if (tke->sel0 < tke->v1 && tke->sel1 > tke->v0) { if (tke->sel0 < tke->v0) { s0 = tke->v0; xs0 = tke->xv0 - tke->x0; } else { s0 = tke->sel0; xs0 = tke->xsel0 - tke->x0; } if (tke->sel1 > tke->v1) { s1 = tke->v1; xs1 = s.max.x; } else { s1 = tke->sel1; xs1 = tke->xsel1 - tke->x0; } r = rectaddpt(Rect(xs0, 0, xs1, env->font->height), s.min); tktextsdraw(i, r, env, 1); runestringn(i, r.min, tkgc(env, TkCselectfgnd), r.min, env->font, text+s0, s1-s0); } if((tke->flag&Ecursoron) && tke->icursor >= tke->v0 && tke->icursor <= tke->v1) { r = Rect( tke->xicursor - tke->x0, 0, tke->xicursor - tke->x0 + Inswidth, env->font->height ); draw(i, rectaddpt(r, s.min), tkgc(env, TkCforegnd), nil, ZP); } if (tke->show) free(text); }
void drawnowin(int i) { Rectangle r; r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows), MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min); draw(screen, insetrect(r, -1), lightblue, nil, ZP); }
void drawbar(int digit, int selected) { Rectangle r = Rect((digit - 1)*Square, 0, digit*Square, Square); if(digit < 1 || digit > 9) return; r = insetrect(r, Border); r.max = addpt(r.max, Pt(2, 2)); draw(screen, rectaddpt(r, screen->r.min), selected ? backselect : background, nil, ZP); draw(screen, rectaddpt(r, screen->r.min), display->black, dig[digit-1], ZP); }
void drawcell(int x, int y, int num, Image *col) { Rectangle r = Rect(x*Square, y*Square, (x+1)*Square, (y+1)*Square); if(num < 0 || num > 9) return; r = insetrect(r, Border); r = rectaddpt(r, Pt(0, Square)); r.max = addpt(r.max, Pt(2, 2)); draw(screen, rectaddpt(r, screen->r.min), col, dig[num], ZP); }
void geometry(void) { int i, rows; Rectangle r; rows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD); r = Rect(0,0,(Dx(screen->r)-2*MARGIN), font->height); for(i=0; i<nmap; i++) map[i].r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows), MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min); }
void drawarrows(void) { Point p; p = enddate; p.x += Facesep; if(p.x & 1) p.x++; /* align background texture */ leftr = rectaddpt(leftright, p); p.x += Dx(leftright) + Facesep; rightr = rectaddpt(leftright, p); draw(screen, leftr, first>0? blue : bgrnd, left, leftright.min); draw(screen, rightr, last<nfaces? blue : bgrnd, right, leftright.min); }
void redraw(Image *screen) { Rectangle r; if(im == nil) return; ulrange.max = screen->r.max; ulrange.min = subpt(screen->r.min, Pt(Dx(im->r), Dy(im->r))); ul = pclip(ul, ulrange); drawop(screen, screen->r, im, nil, subpt(im->r.min, subpt(ul, screen->r.min)), S); if(im->repl) return; /* fill in any outer edges */ /* black border */ r = rectaddpt(im->r, subpt(ul, im->r.min)); border(screen, r, -2, display->black, ZP); r.min = subpt(r.min, Pt(2,2)); r.max = addpt(r.max, Pt(2,2)); /* gray for the rest */ if(gray == nil) { gray = xallocimage(display, Rect(0,0,1,1), RGB24, 1, 0x888888FF); if(gray == nil) { fprint(2, "g out of memory: %r\n"); wexits("mem"); } } border(screen, r, -4000, gray, ZP); // flushimage(display, 0); }
char* tkcvstextcoord(TkCitem *i, char *arg, int x, int y) { char *e; TkCpoints p; if(arg == nil) { tkxlatepts(i->p.parampt, i->p.npoint, x, y); tkxlatepts(i->p.drawpt, i->p.npoint, TKF2I(x), TKF2I(y)); i->p.bb = rectaddpt(i->p.bb, Pt(TKF2I(x), TKF2I(y))); } else { e = tkparsepts(i->env->top, &p, &arg, 0); if(e != nil) return e; if(p.npoint != 1) { tkfreepoint(&p); return TkFewpt; } tkfreepoint(&i->p); i->p = p; tkcvstextsize(i); } return nil; }
char *pan(void) { Point dd, xy, lastxy, min, max; esetcursor(&blot); waitdown(); xy = mouse.xy; do{ lastxy = mouse.xy; mouse = emouse(); dd = subpt(mouse.xy, lastxy); min = addpt(screen->clipr.min, dd); max = addpt(screen->clipr.max, dd); draw(screen, rectaddpt(screen->r, subpt(mouse.xy, lastxy)), screen, nil, screen->r.min); if(mouse.xy.x < lastxy.x) /* moved left, clear right */ draw(screen, Rect(max.x, screen->r.min.y, screen->r.max.x, screen->r.max.y), display->white, nil, ZP); else /* moved right, clear left*/ draw(screen, Rect(screen->r.min.x, screen->r.min.y, min.x, screen->r.max.y), display->white, nil, ZP); if(mouse.xy.y < lastxy.y) /* moved up, clear down */ draw(screen, Rect(screen->r.min.x, max.y, screen->r.max.x, screen->r.max.y), display->white, nil, ZP); else /* moved down, clear up */ draw(screen, Rect(screen->r.min.x, screen->r.min.y, screen->r.max.x, min.y), display->white, nil, ZP); flushimage(display, 1); }while(mouse.buttons); xyoffset = addpt(xyoffset, subpt(mouse.xy, xy)); esetcursor(0); return "p"; }
static void tkentrysee(Tk *tk, int index, int jump) { TkEntry *tke = TKobj(TkEntry, tk); int dx, margin; Rectangle r; r = tkentrybbox(tk, index); dx = tk->act.width - 2*xinset(tk); if (jump) margin = dx / 4; else margin = 0; if (r.min.x <= tke->x0 || r.max.x > tke->x0 + dx) { if (r.min.x <= tke->x0) { tke->x0 = r.min.x - margin; if (tke->x0 < 0) tke->x0 = 0; } else if (r.max.x >= tke->x0 + dx) { tke->x0 = r.max.x - dx + margin; if (tke->x0 > tke->xlen - dx) tke->x0 = tke->xlen - dx; } tk->dirty = tkrect(tk, 0); } r = rectaddpt(r, Pt(xinset(tk) - tke->x0, yinset(tk))); tksee(tk, r, r.min); }
void resize(void) { Rectangle old, r; int dxo, dyo, dxn, dyn; Win *w; old = screen->r; dxo = Dx(old); dyo = Dy(old); if(getwindow(display, Refnone) < 0) sysfatal("resize failed: %r"); dxn = Dx(screen->r); dyn = Dy(screen->r); freescreen(scr); scr = allocscreen(screen, display->white, 0); if(scr == nil) sysfatal("allocscreen: %r"); for(w = wlist.next; w != &wlist; w = w->next){ r = rectsubpt(w->entire, old.min); r.min.x = muldiv(r.min.x, dxn, dxo); r.max.x = muldiv(r.max.x, dxn, dxo); r.min.y = muldiv(r.min.y, dyn, dyo); r.max.y = muldiv(r.max.y, dyn, dyo); w->entire = rectaddpt(r, screen->r.min); w->inner = insetrect(w->entire, BORDSIZ); freeimage(w->im); w->im = allocwindow(scr, w->entire, Refbackup, 0); if(w->im == nil) sysfatal("allocwindow: %r"); draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP); border(w->im, w->entire, BORDSIZ, w->tab->cols[w == actw ? BORD : DISB], ZP); w->tab->draw(w); } }
static bool config_event(Window *frame, void *aux, XConfigureEvent *ev) { frame->r = rectaddpt(Rect(ev->x, ev->y, ev->width, ev->height), Pt(ev->border_width, ev->border_width)); restrut(frame); return false; }
void undrawpiece(void) { Image *mask = nil; if(collider(pos, br.max)) mask = bbmask; draw(screen, rectaddpt(br, pos), display->white, mask, bb->r.min); }
Rectangle imager(Image *i) { Point p1, p2; p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min); p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min); return rectaddpt(i->r, subpt(p2, p1)); }
static void config(Window *w, XConfigureEvent *ev) { USED(w); frame.r = rectaddpt(Rect(0, 0, ev->width, ev->height), Pt(ev->x+ev->border_width, ev->y+ev->border_width)); restrut(); }
static void scrollbar(Win *w) { int h, t0, t1; h = Dy(w->inner); draw(w->im, rectaddpt(Rect(0, 0, SCRBSIZ+1, h), w->inner.min), w->tab->cols[BORD], nil, ZP); t0 = w->toprune * h; t1 = (w->toprune + w->fr.nchars) * h; if(w->nrunes == 0){ t0 = 0; t1 = h; }else{ t0 /= w->nrunes; t1 /= w->nrunes; } draw(w->im, rectaddpt(Rect(0, t0, SCRBSIZ, t1), w->inner.min), w->tab->cols[BACK], nil, ZP); }
void setpiece(Piece *p) { int i; Rectangle r, r2; Point op, delta; draw(bb, bb->r, display->white, nil, ZP); draw(bbmask, bbmask->r, display->transparent, nil, ZP); br = Rect(0, 0, 0, 0); br2 = br; piece = p; if(p == 0) return; r.min = bb->r.min; for(i=0; i<N; i++) { r.min.x += p->d[i].x*pcsz; r.min.y += p->d[i].y*pcsz; r.max.x = r.min.x + pcsz; r.max.y = r.min.y + pcsz; if(i == 0) { draw(bb, r, display->black, nil, ZP); draw(bb, insetrect(r, 1), tx[piece->tx], nil, ZP); draw(bbmask, r, display->opaque, nil, ZP); op = r.min; } else { draw(bb, r, bb, nil, op); draw(bbmask, r, bbmask, nil, op); } if(br.max.x < r.max.x) br.max.x = r.max.x; if(br.max.y < r.max.y) br.max.y = r.max.y; } br.max = subpt(br.max, bb->r.min); delta = Pt(0,DY); br2.max = addpt(br.max, delta); r = rectaddpt(br, bb2->r.min); r2 = rectaddpt(br2, bb2->r.min); draw(bb2, r2, display->white, nil, ZP); draw(bb2, rectaddpt(r,delta), bb, nil, bb->r.min); draw(bb2mask, r2, display->transparent, nil, ZP); draw(bb2mask, r, display->opaque, bbmask, bb->r.min); draw(bb2mask, rectaddpt(r,delta), display->opaque, bbmask, bb->r.min); }
static void groupsize(Control *c) { Rectangle r; int i; Control *q; Group *g; g = (Group*)c; assert(g->type == Ctlcolumn || g->type == Ctlrow || g->type == Ctlstack); if (g->mansize) return; r = Rect(1, 1, 1, 1); if (debug) fprint(2, "groupsize %q\n", g->name); for (i = 0; i < g->nkids; i++){ q = g->kids[i]; if (q->setsize) q->setsize(q); if (q->size.min.x == 0 || q->size.min.y == 0 || q->size.max.x == 0 || q->size.max.y == 0) ctlerror("%q: bad size %R", q->name, q->size); if (debug) fprint(2, "groupsize %q: [%d %q]: %R\n", g->name, i, q->name, q->size); switch(g->type){ case Ctlrow: if (i) r.min.x += q->size.min.x + g->border; else r.min.x = q->size.min.x; if (i) r.max.x += q->size.max.x + g->border; else r.max.x = q->size.max.x; if (r.min.y < q->size.min.y) r.min.y = q->size.min.y; if (r.max.y < q->size.max.y) r.max.y = q->size.max.y; break; case Ctlcolumn: if (r.min.x < q->size.min.x) r.min.x = q->size.min.x; if (r.max.x < q->size.max.x) r.max.x = q->size.max.x; if (i) r.min.y += q->size.min.y + g->border; else r.min.y = q->size.min.y; if (i) r.max.y += q->size.max.y + g->border; else r.max.y = q->size.max.y; break; case Ctlstack: if (r.min.x < q->size.min.x) r.min.x = q->size.min.x; if (r.max.x < q->size.max.x) r.max.x = q->size.max.x; if (r.min.y < q->size.min.y) r.min.y = q->size.min.y; if (r.max.y < q->size.max.y) r.max.y = q->size.max.y; break; } } g->size = rectaddpt(r, Pt(g->border, g->border)); if (debug) fprint(2, "groupsize %q: %R\n", g->name, g->size); }
Rectangle tilerect(Click c) { Point p; Rectangle r; p = Pt(c.x*(Facex/2)-(c.d*TileDxy), c.y*(Facey/2)-(c.d*TileDxy)); r = Rpt(p, addpt(p, Pt(Facex, Facey))); return rectaddpt(r, Pt(Depth*TileDxy, Depth*TileDxy)); }
int horiz(void) { int lev[MAXN]; int i, j, h; Rectangle r; h = 0; for(i=0; i<NY; i++) { for(j=0; board[i][j]; j++) if(j == NX-1) { lev[h++] = i; break; } } if(h == 0) return 0; r = rboard; newscreen = 0; for(j=0; j<h; j++) { r.min.y = rboard.min.y + lev[j]*pcsz; r.max.y = r.min.y + pcsz; draw(screen, r, display->white, whitemask, ZP); flushimage(display, 1); } for(i=0; i<3; i++) { pause(250); if(newscreen) { drawboard(); break; } for(j=0; j<h; j++) { r.min.y = rboard.min.y + lev[j]*pcsz; r.max.y = r.min.y + pcsz; draw(screen, r, display->white, whitemask, ZP); } flushimage(display, 1); } r = rboard; for(j=0; j<h; j++) { i = NY - lev[j] - 1; score(250+10*i*i); r.min.y = rboard.min.y; r.max.y = rboard.min.y+lev[j]*pcsz; draw(screen, rectaddpt(r, Pt(0,pcsz)), screen, nil, r.min); r.max.y = rboard.min.y+pcsz; draw(screen, r, display->white, nil, ZP); memcpy(&board[1][0], &board[0][0], NX*lev[j]); memset(&board[0][0], 0, NX); } flushimage(display, 1); return 1; }
void drawnub(Image *m, Image *clipr, Point o, Tnode *t) { clipr = nil; if(t->nkid == 0) return; if(t->nkid == -1 && t->expand == nil) return; o.y += (display->defaultfont->height-Nubheight)/2; draw(m, rectaddpt(Rect(0,0,1,Nubheight), o), display->black, clipr, ZP); draw(m, rectaddpt(Rect(0,0,Nubwidth,1), o), display->black, clipr, o); draw(m, rectaddpt(Rect(Nubwidth-1,0,Nubwidth,Nubheight), o), display->black, clipr, addpt(o, Pt(Nubwidth-1, 0))); draw(m, rectaddpt(Rect(0, Nubheight-1, Nubwidth, Nubheight), o), display->black, clipr, addpt(o, Pt(0, Nubheight-1))); draw(m, rectaddpt(Rect(0, Nubheight/2, Nubwidth, Nubheight/2+1), o), display->black, clipr, addpt(o, Pt(0, Nubheight/2))); if(!t->expanded) draw(m, rectaddpt(Rect(Nubwidth/2, 0, Nubwidth/2+1, Nubheight), o), display->black, clipr, addpt(o, Pt(Nubwidth/2, 0))); }
static void getwinsize(Window *win) { int x, y; uint w, h; XWindow root; uint border, depth; XGetGeometry(display, win->xid, &root, &x, &y, &w, &h, &border, &depth); win->r = rectaddpt(Rect(0, 0, w, h), Pt(x+border, y+border)); }
int geometry(void) { int i, ncols, z; Rectangle r; z = 0; rows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD); if(rows*cols < nwin || rows*cols >= nwin*2){ ncols = nwin <= 0 ? 1 : (nwin+rows-1)/rows; if(ncols != cols){ cols = ncols; z = 1; } } r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height); for(i=0; i<nwin; i++) win[i].r = rectaddpt(rectaddpt(r, Pt(MARGIN+(PAD+Dx(r))*(i/rows), MARGIN+(PAD+Dy(r))*(i%rows))), screen->r.min); return z; }
int movepiece(void) { Image *mask = nil; if(collide(Pt(pos.x, pos.y+pcsz), piece)) return 0; if(collider(pos, br2.max)) mask = bb2mask; draw(screen, rectaddpt(br2, pos), bb2, mask, bb2->r.min); pos.y += DY; flushimage(display, 1); return 1; }
static char* tkdrawslaves1(Tk *tk, Point orig, Image *dst, int *dirty) { Tk *f; char *e = nil; Point worig; Rectangle r, oclip; worig.x = orig.x + tk->act.x + tk->borderwidth; worig.y = orig.y + tk->act.y + tk->borderwidth; r = rectaddpt(tk->dirty, worig); if (Dx(r) > 0 && rectXrect(r, dst->clipr)) { e = tkmethod[tk->type]->draw(tk, orig); tk->dirty = bbnil; *dirty = 1; } if(e != nil) return e; /* * grids need clipping * XXX BUG: they can't, 'cos text widgets don't clip appropriately. */ if (tk->grid != nil) { r = rectaddpt(tkrect(tk, 0), worig); if (rectclip(&r, dst->clipr) == 0) return nil; oclip = dst->clipr; replclipr(dst, 0, r); } for(f = tk->slave; e == nil && f; f = f->next) e = tkdrawslaves1(f, worig, dst, dirty); if (tk->grid != nil) replclipr(dst, 0, oclip); return e; }
/* * Translate the image in the window by delta. */ static void translate(Point delta) { Point u; Rectangle r, or; if(im == nil) return; u = pclip(addpt(ul, delta), ulrange); delta = subpt(u, ul); if(delta.x == 0 && delta.y == 0) return; /* * The upper left corner of the image is currently at ul. * We want to move it to u. */ or = rectaddpt(Rpt(ZP, Pt(Dx(im->r), Dy(im->r))), ul); r = rectaddpt(or, delta); drawop(screen, r, screen, nil, ul, S); ul = u; /* fill in gray where image used to be but isn't. */ drawdiff(screen, insetrect(or, -2), insetrect(r, -2), gray, nil, ZP, S); /* fill in black border */ drawdiff(screen, insetrect(r, -2), r, display->black, nil, ZP, S); /* fill in image where it used to be off the screen. */ if(rectclip(&or, screen->r)) drawdiff(screen, r, rectaddpt(or, delta), im, nil, im->r.min, S); else drawop(screen, r, im, nil, im->r.min, S); flushimage(display, 1); }
Tnode* findnode(Tnode *t, Point p) { int i; Tnode *tt; if(ptinrect(p, rectaddpt(Rect(0,0,Nubwidth, Nubheight), t->offset))) return t; if(!t->expanded) return nil; for(i=0; i<t->nkid; i++) if(tt = findnode(t->kid[i], p)) return tt; return nil; }
static void tkcvsseesub(Tk *tk, Rectangle *rr, Point *pp) { Rectangle r; Point p; TkCanvas *c; c = TKobj(TkCanvas, tk); r = rectaddpt(*rr, c->view); p = addpt(*pp, c->view); tkcvsseerect(tk, r, p); *rr = rectsubpt(r, c->view); *pp = subpt(p, c->view); }
void swcursordraw(void) { if(swvisible) return; if(swenabled == 0) return; if(swback == nil || swimg1 == nil || swmask1 == nil) return; assert(!canqlock(&drawlock)); swvispt = swpt; swvisvers = swvers; swrect = rectaddpt(Rect(0,0,16,16), swvispt); memimagedraw(swback, swback->r, gscreen, swpt, memopaque, ZP, S); memimagedraw(gscreen, swrect, swimg1, ZP, swmask1, ZP, SoverD); flushmemscreen(swrect); swvisible = 1; }