8 _frdrawtext(Frame *f, Point pt, Image *text, Image *back)
13 for(nb=0,b=f->box; nb<f->nbox; nb++, b++){
14 _frcklinewrap(f, &pt, b);
15 if(!f->noredraw && b->nrune >= 0)
16 stringbg(f->b, pt, text, ZP, f->font, (char*)b->ptr, back, ZP);
22 nbytes(char *s0, int nr)
29 s += chartorune(&r, s);
34 frdrawsel(Frame *f, Point pt, ulong p0, ulong p1, int issel)
39 frtick(f, frptofchar(f, f->p0), 0);
48 text = f->cols[HTEXT];
54 frdrawsel0(f, pt, p0, p1, back, text);
58 frdrawsel0(Frame *f, Point pt, ulong p0, ulong p1, Image *back, Image *text)
61 int nb, nr, w, x, trim;
67 sysfatal("libframe: frdrawsel0 p0=%lud > p1=%lud", p0, p1);
72 for(nb=0; nb<f->nbox && p<p1; nb++){
80 _frcklinewrap(f, &pt, b);
81 /* fill in the end of a wrapped line */
83 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
86 if(p < p0){ /* beginning of region: advance into box */
87 ptr += nbytes(ptr, p0-p);
92 if(p+nr > p1){ /* end of region: trim box */
96 if(b->nrune<0 || nr==b->nrune)
99 w = stringnwidth(f->font, ptr, nr);
103 draw(f->b, Rect(pt.x, pt.y, x, pt.y+f->font->height), back, nil, pt);
105 stringnbg(f->b, pt, text, ZP, f->font, ptr, nr, back, ZP);
111 /* if this is end of last plain text box on wrapped line, fill to end of line */
112 if(p1>p0 && b>f->box && b<f->box+f->nbox && b[-1].nrune>0 && !trim){
114 _frcklinewrap(f, &pt, b);
116 draw(f->b, Rect(qt.x, qt.y, f->r.max.x, pt.y), back, nil, qt);
130 frtick(f, frptofchar(f, f->p0), 0);
131 frdrawsel0(f, frptofchar(f, 0), 0, f->nchars, f->cols[BACK], f->cols[TEXT]);
133 frtick(f, frptofchar(f, f->p0), 1);
137 pt = frptofchar(f, 0);
138 pt = frdrawsel0(f, pt, 0, f->p0, f->cols[BACK], f->cols[TEXT]);
139 pt = frdrawsel0(f, pt, f->p0, f->p1, f->cols[HIGH], f->cols[HTEXT]);
140 pt = frdrawsel0(f, pt, f->p1, f->nchars, f->cols[BACK], f->cols[TEXT]);
144 _frtick(Frame *f, Point pt, int ticked)
148 if(f->ticked==ticked || f->tick==0 || !ptinrect(pt, f->r))
150 pt.x -= f->tickscale; /* looks best just left of where requested */
151 r = Rect(pt.x, pt.y, pt.x+FRTICKW*f->tickscale, pt.y+f->font->height);
152 /* can go into left border but not right */
153 if(r.max.x > f->r.max.x)
154 r.max.x = f->r.max.x;
156 draw(f->tickback, f->tickback->r, f->b, nil, pt);
157 draw(f->b, r, f->tick, nil, ZP);
159 draw(f->b, r, f->tickback, nil, ZP);
164 frtick(Frame *f, Point pt, int ticked)
166 if(f->tickscale != scalesize(f->display, 1)) {
171 _frtick(f, pt, ticked);
175 _frdraw(Frame *f, Point pt)
180 for(b=f->box,nb=0; nb<f->nbox; nb++, b++){
181 _frcklinewrap0(f, &pt, b);
182 if(pt.y == f->r.max.y){
183 f->nchars -= _frstrlen(f, nb);
184 _frdelbox(f, nb, f->nbox-1);
188 n = _frcanfit(f, pt, b);
192 _frsplitbox(f, nb, n);
199 pt.y+=f->font->height;
201 pt.x += _frnewwid(f, pt, b);
208 _frstrlen(Frame *f, int nb)
212 for(n=0; nb<f->nbox; nb++)
213 n += NRUNE(&f->box[nb]);