Win * newwin(int t, Rectangle r, File *f) { Win *w; w = emalloc(sizeof(*w)); w->next = &wlist; w->prev = wlist.prev; w->next->prev = w; w->prev->next = w; w->type = t; w->tab = tabs[t]; w->entire = r; w->inner = insetrect(r, BORDSIZ); w->im = allocwindow(scr, r, Refbackup, 0); draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP); if(f != nil){ incref(f); w->wprev = f->wins.wprev; w->wnext = &f->wins; f->wins.wprev->wnext = w; f->wins.wprev = w; w->f = f; } w->tab->init(w); setfocus(w); w->tab->draw(w); return w; }
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); } }
void winresize(Win *w, Mousectl *mc) { Rectangle r; if(w == nil) return; r = getrect(3, mc); if(Dx(r) < MINSIZ || Dy(r) < MINSIZ) return; rectclip(&r, screen->r); freeimage(w->im); w->entire = r; w->inner = insetrect(r, BORDSIZ); w->im = allocwindow(scr, r, Refbackup, 0); draw(w->im, w->inner, w->tab->cols[BACK], nil, ZP); setfocus(w); w->tab->draw(w); }
int menuhit(int but, Mousectl *mc, Menu *menu, Screen *scr) { int i, nitem, nitemdrawn, maxwid, lasti, off, noff, wid, screenitem; int scrolling; Rectangle r, menur, sc, textr, scrollr; Image *b, *save, *backup; Point pt; char *item; if(back == nil) menucolors(); sc = screen->clipr; replclipr(screen, 0, screen->r); maxwid = 0; for(nitem = 0; item = menu->item? menu->item[nitem] : (*menu->gen)(nitem); nitem++){ i = stringwidth(font, item); if(i > maxwid) maxwid = i; } if(menu->lasthit<0 || menu->lasthit>=nitem) menu->lasthit = 0; screenitem = (Dy(screen->r)-10)/(font->height+Vspacing); if(nitem>Maxunscroll || nitem>screenitem){ scrolling = 1; nitemdrawn = Nscroll; if(nitemdrawn > screenitem) nitemdrawn = screenitem; wid = maxwid + Gap + Scrollwid; off = menu->lasthit - nitemdrawn/2; if(off < 0) off = 0; if(off > nitem-nitemdrawn) off = nitem-nitemdrawn; lasti = menu->lasthit-off; }else{ scrolling = 0; nitemdrawn = nitem; wid = maxwid; off = 0; lasti = menu->lasthit; } r = insetrect(Rect(0, 0, wid, nitemdrawn*(font->height+Vspacing)), -Margin); r = rectsubpt(r, Pt(wid/2, lasti*(font->height+Vspacing)+font->height/2)); r = rectaddpt(r, mc->m.xy); pt = ZP; if(r.max.x>screen->r.max.x) pt.x = screen->r.max.x-r.max.x; if(r.max.y>screen->r.max.y) pt.y = screen->r.max.y-r.max.y; if(r.min.x<screen->r.min.x) pt.x = screen->r.min.x-r.min.x; if(r.min.y<screen->r.min.y) pt.y = screen->r.min.y-r.min.y; menur = rectaddpt(r, pt); textr.max.x = menur.max.x-Margin; textr.min.x = textr.max.x-maxwid; textr.min.y = menur.min.y+Margin; textr.max.y = textr.min.y + nitemdrawn*(font->height+Vspacing); if(scrolling){ scrollr = insetrect(menur, Border); scrollr.max.x = scrollr.min.x+Scrollwid; }else scrollr = Rect(0, 0, 0, 0); if(scr){ b = allocwindow(scr, menur, Refbackup, DWhite); if(b == nil) b = screen; backup = nil; }else{ b = screen; backup = allocimage(display, menur, screen->chan, 0, -1); if(backup) draw(backup, menur, screen, nil, menur.min); } draw(b, menur, back, nil, ZP); border(b, menur, Blackborder, bord, ZP); save = allocimage(display, menurect(textr, 0), screen->chan, 0, -1); r = menurect(textr, lasti); moveto(mc, divpt(addpt(r.min, r.max), 2)); menupaint(b, menu, textr, off, nitemdrawn); if(scrolling) menuscrollpaint(b, scrollr, off, nitem, nitemdrawn); while(mc->m.buttons & (1<<(but-1))){ lasti = menuscan(b, menu, but, mc, textr, off, lasti, save); if(lasti >= 0) break; while(!ptinrect(mc->m.xy, textr) && (mc->m.buttons & (1<<(but-1)))){ if(scrolling && ptinrect(mc->m.xy, scrollr)){ noff = ((mc->m.xy.y-scrollr.min.y)*nitem)/Dy(scrollr); noff -= nitemdrawn/2; if(noff < 0) noff = 0; if(noff > nitem-nitemdrawn) noff = nitem-nitemdrawn; if(noff != off){ off = noff; menupaint(b, menu, textr, off, nitemdrawn); menuscrollpaint(b, scrollr, off, nitem, nitemdrawn); } } readmouse(mc); } } if(b != screen) freeimage(b); if(backup){ draw(screen, menur, backup, nil, menur.min); freeimage(backup); } freeimage(save); replclipr(screen, 0, sc); flushimage(display, 1); if(lasti >= 0){ menu->lasthit = lasti+off; return menu->lasthit; } return -1; }
PCompound* iconbox(Prefab_Environ *e, Draw_Point p, String *titletext, Draw_Image *icon, Draw_Image *mask) { Draw_Rect er, r, ir; PCompound *pc; Prefab_Compound *c; PElement *elem, *title; Image *disp; Draw_Image *ddisp; Screen *screen; Heap *h; Rectangle t; Point pt; screen = lookupscreen(e->screen); if(screen == nil) return H; h = heapz(TCompound); if(h == H) return H; pc = H2D(PCompound*, h); c = &pc->c; gchalt++; title = H; if(titletext != H){ er.min.x = 0; er.min.y = 0; er.max.x = Dx(icon->r)-5; er.max.y = 0; title = textelement(e, titletext, er, ETitle); if(title == H){ Err: destroy(c); gchalt--; return H; } c->title = (Prefab_Element*)title; } r = icon->r; if(title != H) r.max.y += 2+1+title->nkids*e->style->titlefont->height+1; er = edgerect(e, p, &r); R2R(t, er); disp = allocwindow(screen, t, Refbackup /*refreshcompound*/, DWhite); if(disp == nil) goto Err; if((ddisp=mkdrawimage(disp, e->screen, e->screen->display, nil)) == H){ freeimage(disp); goto Err; } ir = r; if(title != H){ ir = r; pt.x = r.min.x+3; pt.y = r.min.y+3; translateelement(&title->e, pt); ir.min.y = title->e.r.max.y+1; } elem = iconelement(e, ir, icon, mask); c->r = r; c->image = ddisp; c->environ = e; D2H(e)->ref++; c->contents = (Prefab_Element*)elem; pc->display = screen->display; gchalt--; return pc; }
static void groupmouse(Control *c, Mouse *m) { Group *g; int i, lastkid; g = (Group*)c; if (g->type == Ctlstack){ i = g->selected; if (i >= 0 && g->kids[i]->mouse && ( ( ((m->buttons == 0) || (g->lastbut == 0)) && ptinrect(m->xy, g->kids[i]->rect) ) || ( ((m->buttons != 0) || (g->lastbut != 0)) && (g->lastkid == i) ) ) ) { if (debugm) fprint(2, "groupmouse %s mouse kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n", g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut, ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0); (g->kids[i]->mouse)(g->kids[i], m); g->lastkid = i; g->lastbut = m->buttons; } else { if (debugm) fprint(2, "groupmouse %s skip kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n", g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut, ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0); } return; } lastkid = -1; for(i=0; i<g->nkids; i++) { if(g->kids[i]->mouse && ( ( ((m->buttons == 0) || (g->lastbut == 0)) && ptinrect(m->xy, g->kids[i]->rect) ) || ( ((m->buttons != 0) || (g->lastbut != 0)) && (g->lastkid == i) ) ) ) { if (debugm) fprint(2, "groupmouse %s mouse kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n", g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut, ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0); (g->kids[i]->mouse)(g->kids[i], m); lastkid = i; } else { if (debugm) fprint(2, "groupmouse %s skip kid %s i=%d lastkid=%d buttons=%d lastbut=%d inrect=%d\n", g->name, g->kids[i]->name, i, g->lastkid, m->buttons, g->lastbut, ptinrect(m->xy, g->kids[i]->rect) ? 1 : 0); } } g->lastkid = lastkid; g->lastbut = m->buttons; #ifdef notdef if(m->buttons == 0){ /* buttons now up */ g->lastbut = 0; return; } if(g->lastbut == 0 && m->buttons != 0){ /* button went down, start tracking border */ switch(g->stacking){ default: return; case Vertical: p = Pt(m->xy.x, middle_of_border.y); p0 = Pt(g->r.min.x, m->xy.y); p1 = Pt(g->r.max.x, m->xy.y); break; case Horizontal: p = Pt(middle_of_border.x, m->xy.y); p0 = Pt(m->xy.x, g->r.min.y); p1 = Pt(m->xy.x, g->r.max.y); break; } // setcursor(); oi = nil; } else if (g->lastbut != 0 && s->m.buttons != 0){ /* button is down, keep tracking border */ if(!eqpt(s->m.xy, p)){ p = onscreen(s->m.xy); r = canonrect(Rpt(p0, p)); if(Dx(r)>5 && Dy(r)>5){ i = allocwindow(wscreen, r, Refnone, 0xEEEEEEFF); /* grey */ freeimage(oi); if(i == nil) goto Rescue; oi = i; border(i, r, Selborder, red, ZP); flushimage(display, 1); } } } else if (g->lastbut != 0 && s->m.buttons == 0){ /* button went up, resize kiddies */ } g->lastbut = s->m.buttons; #endif }