static void addflush(Rectangle r) { if(flushr.min.x >= flushr.max.x) flushr = r; else combinerect(&flushr, r); }
static void addrect(Rectangle *rp, Rectangle r) { if(rp->min.x >= rp->max.x) *rp = r; else combinerect(rp, r); }
void drawrampbar(Image *color, State *s) { Rectangle liner, r; static Rectangle br; if(Dx(br)) draw(screen, br, ramp, nil, subpt(br.min, rramp.min)); r = rramp; r.max.x = r.min.x + (int)(s->white*255.0); r.min.x += (int)(s->black*255.0); r.min.y += gamma2y(s->gamma); r.max.y = r.min.y+1; rectclip(&r, rramp); draw(screen, r, color, nil, ZP); br = r; r.min.y -= 2; r.max.y += 2; liner = r; r.min.x += Dx(liner)/3; r.max.x -= Dx(liner)/3; rectclip(&r, rramp); draw(screen, r, color, nil, ZP); combinerect(&br, r); r = liner; r.max.x = r.min.x+3; rectclip(&r, rramp); draw(screen, r, color, nil, ZP); combinerect(&br, r); r = liner; r.min.x = r.max.x-3; rectclip(&r, rramp); draw(screen, r, color, nil, ZP); combinerect(&br, r); }
void addtorlist(Rlist *rlist, Rectangle r) { int i, j; Rectangle ir, cr, rr; Rlist tmp; if(r.min.x >= r.max.x || r.min.y >= r.max.y) return; memset(&tmp, 0, sizeof tmp); rappend(&tmp, r); if(verbose > 5) fprint(2, "region union add %R:\n", r); combinerect(&rlist->bbox, r); // must do this first for(j = 0; j < tmp.nrect; j++){ r = tmp.rect[j]; for(i=0; i < rlist->nrect; i++){ ir = rlist->rect[i]; if(verbose > 5) fprint(2, "checking %R against %R\n", r, ir); if(!rectadjacent(ir, r)) continue; /* r is covered by ir? */ if(rectinrect(r, ir)) break; /* r covers ir? */ if(rectinrect(ir, r)){ rtrim(rlist, i); i--; continue; } /* aligned and overlapping? */ if((ir.min.y == r.min.y && ir.max.y == r.max.y) || (ir.min.x == r.min.x && ir.max.x == r.max.x)){ combinerect(&r, ir); rtrim(rlist, i); i--; continue; } /* not aligned */ if(verbose > 5) fprint(2, "break up rect %R and %R\n", ir, r); /* 2->2 breakup */ cr = ir; if (!rectclip(&cr, r)) /* share only one point */ continue; if(rectubr(&r, cr)) continue; if(rectubr(&rlist->rect[i], cr)) continue; /* 2 -> 3 breakup */ /* stride across */ if(recttridesubr(&r, cr, &rr)){ rappend(&tmp, rr); continue; } /* corner overlap */ if(rectcornersubr(&r, cr, &rr)){ rappend(&tmp, rr); continue; } abort(); } if(i == rlist->nrect) rappend(rlist, r); } freerlist(&tmp); if(verbose > 5) rprint(rlist); }
static void vgascreenputc(VGAscr* scr, char* buf, Rectangle *flushr) { Point p; int h, w, pos; Rectangle r; // drawdebug = 1; if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)]) xp = xbuf; h = scr->memdefont->height; switch(buf[0]){ case '\n': if(curpos.y+h >= window.max.y){ vgascroll(scr); *flushr = window; } curpos.y += h; vgascreenputc(scr, "\r", flushr); break; case '\r': xp = xbuf; curpos.x = window.min.x; break; case '\t': p = memsubfontwidth(scr->memdefont, " "); w = p.x; if(curpos.x >= window.max.x-4*w) vgascreenputc(scr, "\n", flushr); pos = (curpos.x-window.min.x)/w; pos = 4-(pos%4); *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); curpos.x += pos*w; break; case '\b': if(xp <= xbuf) break; xp--; r = Rect(*xp, curpos.y, curpos.x, curpos.y+h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, ZP, S); combinerect(flushr, r); curpos.x = *xp; break; case '\0': break; default: p = memsubfontwidth(scr->memdefont, buf); w = p.x; if(curpos.x >= window.max.x-w) vgascreenputc(scr, "\n", flushr); *xp++ = curpos.x; r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y+h); memimagedraw(scr->gscreen, r, back, back->r.min, nil, back->r.min, S); memimagestring(scr->gscreen, curpos, conscol, ZP, scr->memdefont, buf); combinerect(flushr, r); curpos.x += w; } // drawdebug = 0; }