Russ Cox avatar Russ Cox committed efbcf6a

samterm: retina scaling for scroll bars, borders

R=rsc
http://codereview.appspot.com/6844083

Comments (0)

Files changed (3)

src/cmd/samterm/flayer.c

 {
 	rectclip(&r, lDrect);
 	l->entire = r;
-	l->scroll = insetrect(r, FLMARGIN);
+	l->scroll = insetrect(r, FLMARGIN(l));
 	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;
 }
 
 	llinsert(l);
 	l->visible = All;
 	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");
 	newvisibilities(1);
 	draw(screen, l->entire, l->f.cols[BACK], nil, ZP);
 flborder(Flayer *l, int wide)
 {
 	if(flprepare(l)){
-		border(l->f.b, l->entire, FLMARGIN, 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, FLMARGIN(l), l->f.cols[BACK], ZP);
+		border(l->f.b, l->entire, wide? FLMARGIN(l) : 1, l->f.cols[BORD], ZP);
 		if(l->visible==Some)
 			flrefresh(l, l->entire, 0);
 	}
 			r.min.x = dr.min.x;
 		if(r.max.x-r.min.x<100)
 			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;
-		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;
 		if(!move)
 			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)
 			scrdraw(l, scrtotal(l));
 	}
 		else if((f->b = allocimage(display, l->entire, screen->chan, 0, 0))==0)
 			return 0;
 		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;
 		frinit(f, f->entire, f->font, f->b, 0);
 		f->maxtab = maxtab*stringwidth(f->font, "0");
 		someinvis = 1;
 	}
 }
+
+int
+flscale(Flayer *l, int n)
+{
+	if(l == nil)
+		return n;
+	return scalesize(l->f.display, n);
+}

src/cmd/samterm/flayer.h

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

src/cmd/samterm/scroll.c

 	long p0;
 
 	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);
 	r = scr;
 	y = scr.min.y;
 	draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
 	do{
 		oin = in;
-		in = abs(x-mousep->xy.x)<=FLSCROLLWID/2;
+		in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
 		if(oin && !in)
 			scrunmark(l, r);
 		if(in){
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.