samterm: retina scaling for scroll bars, borders

R=rsc
http://codereview.appspot.com/6844083
This commit is contained in:
Russ Cox 2012-11-26 00:23:06 -05:00
parent a8a0a6422c
commit c28224992a
3 changed files with 24 additions and 14 deletions

View file

@ -65,9 +65,9 @@ flrect(Flayer *l, Rectangle r)
{ {
rectclip(&r, lDrect); rectclip(&r, lDrect);
l->entire = r; l->entire = r;
l->scroll = insetrect(r, FLMARGIN); l->scroll = insetrect(r, FLMARGIN(l));
r.min.x = r.min.x =
l->scroll.max.x = r.min.x+FLMARGIN+FLSCROLLWID+(FLGAP-FLMARGIN); l->scroll.max.x = r.min.x+FLMARGIN(l)+FLSCROLLWID(l)+(FLGAP(l)-FLMARGIN(l));
return r; return r;
} }
@ -78,7 +78,8 @@ flinit(Flayer *l, Rectangle r, Font *ft, Image **cols)
llinsert(l); llinsert(l);
l->visible = All; l->visible = All;
l->origin = l->p0 = l->p1 = 0; l->origin = l->p0 = l->p1 = 0;
frinit(&l->f, insetrect(flrect(l, r), FLMARGIN), ft, screen, cols); l->f.display = display; // for FLMARGIN
frinit(&l->f, insetrect(flrect(l, r), FLMARGIN(l)), ft, screen, cols);
l->f.maxtab = maxtab*stringwidth(ft, "0"); l->f.maxtab = maxtab*stringwidth(ft, "0");
newvisibilities(1); newvisibilities(1);
draw(screen, l->entire, l->f.cols[BACK], nil, ZP); draw(screen, l->entire, l->f.cols[BACK], nil, ZP);
@ -111,8 +112,8 @@ void
flborder(Flayer *l, int wide) flborder(Flayer *l, int wide)
{ {
if(flprepare(l)){ if(flprepare(l)){
border(l->f.b, l->entire, FLMARGIN, l->f.cols[BACK], ZP); border(l->f.b, l->entire, FLMARGIN(l), l->f.cols[BACK], ZP);
border(l->f.b, l->entire, wide? FLMARGIN : 1, l->f.cols[BORD], ZP); border(l->f.b, l->entire, wide? FLMARGIN(l) : 1, l->f.cols[BORD], ZP);
if(l->visible==Some) if(l->visible==Some)
flrefresh(l, l->entire, 0); flrefresh(l, l->entire, 0);
} }
@ -392,13 +393,13 @@ flresize(Rectangle dr)
r.min.x = dr.min.x; r.min.x = dr.min.x;
if(r.max.x-r.min.x<100) if(r.max.x-r.min.x<100)
r.max.x = dr.max.x; r.max.x = dr.max.x;
if(r.max.y-r.min.y<2*FLMARGIN+f->font->height) if(r.max.y-r.min.y<2*FLMARGIN(l)+f->font->height)
r.min.y = dr.min.y; r.min.y = dr.min.y;
if(r.max.y-r.min.y<2*FLMARGIN+f->font->height) if(r.max.y-r.min.y<2*FLMARGIN(l)+f->font->height)
r.max.y = dr.max.y; r.max.y = dr.max.y;
if(!move) if(!move)
l->visible = None; l->visible = None;
frsetrects(f, insetrect(flrect(l, r), FLMARGIN), f->b); frsetrects(f, insetrect(flrect(l, r), FLMARGIN(l)), f->b);
if(!move && f->b) if(!move && f->b)
scrdraw(l, scrtotal(l)); scrdraw(l, scrtotal(l));
} }
@ -422,7 +423,7 @@ flprepare(Flayer *l)
else if((f->b = allocimage(display, l->entire, screen->chan, 0, 0))==0) else if((f->b = allocimage(display, l->entire, screen->chan, 0, 0))==0)
return 0; return 0;
draw(f->b, l->entire, f->cols[BACK], nil, ZP); draw(f->b, l->entire, f->cols[BACK], nil, ZP);
border(f->b, l->entire, l==llist[0]? FLMARGIN : 1, f->cols[BORD], ZP); border(f->b, l->entire, l==llist[0]? FLMARGIN(l) : 1, f->cols[BORD], ZP);
n = f->nchars; n = f->nchars;
frinit(f, f->entire, f->font, f->b, 0); frinit(f, f->entire, f->font, f->b, 0);
f->maxtab = maxtab*stringwidth(f->font, "0"); f->maxtab = maxtab*stringwidth(f->font, "0");
@ -496,3 +497,11 @@ flrefresh(Flayer *l, Rectangle r, int i)
someinvis = 1; someinvis = 1;
} }
} }
int
flscale(Flayer *l, int n)
{
if(l == nil)
return n;
return scalesize(l->f.display, n);
}

View file

@ -41,10 +41,11 @@ void flsetselect(Flayer*, long, long);
void flstart(Rectangle); void flstart(Rectangle);
void flupfront(Flayer*); void flupfront(Flayer*);
Flayer *flwhich(Point); Flayer *flwhich(Point);
int flscale(Flayer*, int);
#define FLMARGIN 4 #define FLMARGIN(l) flscale(l, 4)
#define FLSCROLLWID 12 #define FLSCROLLWID(l) flscale(l, 12)
#define FLGAP 4 #define FLGAP(l) flscale(l, 4)
extern Image *maincols[NCOL]; extern Image *maincols[NCOL];
extern Image *cmdcols[NCOL]; extern Image *cmdcols[NCOL];

View file

@ -107,7 +107,7 @@ scroll(Flayer *l, int but)
long p0; long p0;
s = l->scroll; s = l->scroll;
x = s.min.x+FLSCROLLWID/2; x = s.min.x+FLSCROLLWID(l)/2;
scr = scrpos(l->scroll, l->origin, l->origin+l->f.nchars, tot); scr = scrpos(l->scroll, l->origin, l->origin+l->f.nchars, tot);
r = scr; r = scr;
y = scr.min.y; y = scr.min.y;
@ -115,7 +115,7 @@ scroll(Flayer *l, int but)
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min); draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
do{ do{
oin = in; oin = in;
in = abs(x-mousep->xy.x)<=FLSCROLLWID/2; in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
if(oin && !in) if(oin && !in)
scrunmark(l, r); scrunmark(l, r);
if(in){ if(in){