14 static Flayer **llist; /* front to back */
17 static Rectangle lDrect;
19 Vis visibility(Flayer *);
20 void newvisibilities(int);
21 void llinsert(Flayer*);
22 void lldelete(Flayer*);
24 Image *maincols[NCOL];
32 /* Main text is yellowish */
33 maincols[BACK] = allocimagemix(display, DPaleyellow, DWhite);
34 maincols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
35 maincols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, DYellowgreen);
36 maincols[TEXT] = display->black;
37 maincols[HTEXT] = display->black;
39 /* Command text is blueish */
40 cmdcols[BACK] = allocimagemix(display, DPalebluegreen, DWhite);
41 cmdcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen);
42 cmdcols[BORD] = allocimage(display, Rect(0,0,2,2), screen->chan, 1, DPurpleblue);
43 cmdcols[TEXT] = display->black;
44 cmdcols[HTEXT] = display->black;
48 flnew(Flayer *l, Rune *(*fn)(Flayer*, long, ulong*), int u0, void *u1)
50 if(nllist == nlalloc){
52 llist = realloc(llist, nlalloc*sizeof(Flayer**));
64 flrect(Flayer *l, Rectangle r)
68 l->scroll = insetrect(r, FLMARGIN);
70 l->scroll.max.x = r.min.x+FLMARGIN+FLSCROLLWID+(FLGAP-FLMARGIN);
75 flinit(Flayer *l, Rectangle r, Font *ft, Image **cols)
80 l->origin = l->p0 = l->p1 = 0;
81 frinit(&l->f, insetrect(flrect(l, r), FLMARGIN), ft, screen, cols);
82 l->f.maxtab = maxtab*stringwidth(ft, "0");
84 draw(screen, l->entire, l->f.cols[BACK], nil, ZP);
93 draw(screen, l->entire, display->white, nil, ZP);
94 else if(l->visible == Some){
96 l->f.b = allocimage(display, l->entire, screen->chan, 0, DNofill);
98 draw(l->f.b, l->entire, display->white, nil, ZP);
99 flrefresh(l, l->entire, 0);
104 if(l->f.b && l->visible!=All)
111 flborder(Flayer *l, int wide)
114 border(l->f.b, l->entire, FLMARGIN, l->f.cols[BACK], ZP);
115 border(l->f.b, l->entire, wide? FLMARGIN : 1, l->f.cols[BORD], ZP);
117 flrefresh(l, l->entire, 0);
127 return nllist? llist[0] : 0;
128 for(i=0; i<nllist; i++)
129 if(ptinrect(p, llist[i]->entire))
146 newvisibilities(int redraw)
147 /* if redraw false, we know it's a flupfront, and needn't
148 * redraw anyone becoming partially covered */
154 for(i = 0; i<nllist; i++){
156 l->lastsr = ZR; /* make sure scroll bar gets redrawn */
158 l->visible = visibility(l);
159 #define V(a, b) (((a)<<2)|((b)))
160 switch(V(ov, l->visible)){
171 if(l->f.b==0 && redraw)
174 if(l->f.b && redraw){
175 flrefresh(l, l->entire, 0);
186 draw(screen, l->entire, l->f.b, nil, l->entire.min);
195 if(ov==None && l->visible!=None)
204 for(i=nllist; i>0; --i)
215 for(i=0; i<nllist; i++)
219 llist[i] = llist[i+1];
226 flinsert(Flayer *l, Rune *sp, Rune *ep, long p0)
229 frinsert(&l->f, sp, ep, p0-l->origin);
230 scrdraw(l, scrtotal(l));
232 flrefresh(l, l->entire, 0);
237 fldelete(Flayer *l, long p0, long p1)
246 frdelete(&l->f, p0, p1);
247 scrdraw(l, scrtotal(l));
249 flrefresh(l, l->entire, 0);
259 frselect(&l->f, mousectl);
261 if(l->f.p0==l->f.p1){
262 if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0){
266 l->click = mousep->msec;
269 l->p0 = l->f.p0+l->origin, l->p1 = l->f.p1+l->origin;
274 flsetselect(Flayer *l, long p0, long p1)
280 if(l->visible==None || !flprepare(l)){
281 l->p0 = p0, l->p1 = p1;
284 l->p0 = p0, l->p1 = p1;
285 flfp0p1(l, &fp0, &fp1, &ticked);
286 if(fp0==l->f.p0 && fp1==l->f.p1){
287 if(l->f.ticked != ticked)
288 frtick(&l->f, frptofchar(&l->f, fp0), ticked);
292 if(fp1<=l->f.p0 || fp0>=l->f.p1 || l->f.p0==l->f.p1 || fp0==fp1){
293 /* no overlap or trivial repainting */
294 frdrawsel(&l->f, frptofchar(&l->f, l->f.p0), l->f.p0, l->f.p1, 0);
295 if(fp0 != fp1 || ticked)
296 frdrawsel(&l->f, frptofchar(&l->f, fp0), fp0, fp1, 1);
299 /* the current selection and the desired selection overlap and are both non-empty */
301 /* extend selection backwards */
302 frdrawsel(&l->f, frptofchar(&l->f, fp0), fp0, l->f.p0, 1);
303 }else if(fp0 > l->f.p0){
304 /* trim first part of selection */
305 frdrawsel(&l->f, frptofchar(&l->f, l->f.p0), l->f.p0, fp0, 0);
308 /* extend selection forwards */
309 frdrawsel(&l->f, frptofchar(&l->f, l->f.p1), l->f.p1, fp1, 1);
310 }else if(fp1 < l->f.p1){
311 /* trim last part of selection */
312 frdrawsel(&l->f, frptofchar(&l->f, fp1), fp1, l->f.p1, 0);
319 flrefresh(l, l->entire, 0);
323 flfp0p1(Flayer *l, ulong *pp0, ulong *pp1, int *ticked)
325 long p0 = l->p0-l->origin, p1 = l->p1-l->origin;
336 if(p1 > l->f.nchars){
345 rscale(Rectangle r, Point old, Point new)
347 r.min.x = r.min.x*new.x/old.x;
348 r.min.y = r.min.y*new.y/old.y;
349 r.max.x = r.max.x*new.x/old.x;
350 r.max.y = r.max.y*new.y/old.y;
355 flresize(Rectangle dr)
360 Rectangle r, olDrect;
366 /* no moving on rio; must repaint */
367 if(0 && Dx(dr)==Dx(olDrect) && Dy(dr)==Dy(olDrect))
370 draw(screen, lDrect, display->white, nil, ZP);
371 for(i=0; i<nllist; i++){
376 r = rectaddpt(rectsubpt(l->entire, olDrect.min), dr.min);
378 r = rectaddpt(rscale(rectsubpt(l->entire, olDrect.min),
379 subpt(olDrect.max, olDrect.min),
380 subpt(dr.max, dr.min)), dr.min);
381 if(l->visible==Some && f->b){
389 if(!rectclip(&r, dr))
391 if(r.max.x-r.min.x<100)
393 if(r.max.x-r.min.x<100)
395 if(r.max.y-r.min.y<2*FLMARGIN+f->font->height)
397 if(r.max.y-r.min.y<2*FLMARGIN+f->font->height)
401 frsetrects(f, insetrect(flrect(l, r), FLMARGIN), f->b);
403 scrdraw(l, scrtotal(l));
416 if(l->visible == None)
420 if(l->visible == All)
422 else if((f->b = allocimage(display, l->entire, screen->chan, 0, 0))==0)
424 draw(f->b, l->entire, f->cols[BACK], nil, ZP);
425 border(f->b, l->entire, l==llist[0]? FLMARGIN : 1, f->cols[BORD], ZP);
427 frinit(f, f->entire, f->font, f->b, 0);
428 f->maxtab = maxtab*stringwidth(f->font, "0");
429 r = (*l->textfn)(l, n, &n);
430 frinsert(f, r, r+n, (ulong)0);
431 frdrawsel(f, frptofchar(f, f->p0), f->p0, f->p1, 0);
432 flfp0p1(l, &f->p0, &f->p1, &ticked);
433 if(f->p0 != f->p1 || ticked)
434 frdrawsel(f, frptofchar(f, f->p0), f->p0, f->p1, 1);
436 scrdraw(l, scrtotal(l));
441 static int somevis, someinvis, justvis;
444 visibility(Flayer *l)
446 somevis = someinvis = 0;
448 flrefresh(l, l->entire, 0);
458 flrefresh(Flayer *l, Rectangle r, int i)
464 if((t=llist[i++]) == l){
466 draw(screen, r, l->f.b, nil, r.min);
469 if(!rectXrect(t->entire, r))
470 goto Top; /* avoid stacking unnecessarily */
471 if(t->entire.min.x>r.min.x){
473 s.max.x = t->entire.min.x;
475 r.min.x = t->entire.min.x;
477 if(t->entire.min.y>r.min.y){
479 s.max.y = t->entire.min.y;
481 r.min.y = t->entire.min.y;
483 if(t->entire.max.x<r.max.x){
485 s.min.x = t->entire.max.x;
487 r.max.x = t->entire.max.x;
489 if(t->entire.max.y<r.max.y){
491 s.min.y = t->entire.max.y;
493 r.max.y = t->entire.max.y;
495 /* remaining piece of r is blocked by t; forget about it */