Commits

Russ Cox committed f99a2ec

libframe: auto scale tick for retina

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

  • Participants
  • Parent commits c386d69

Comments (0)

Files changed (3)

 #ifndef _FRAME_H_
 #define _FRAME_H_ 1
 #if defined(__cplusplus)
-extern "C" { 
+extern "C" {
 #endif
 
 AUTOLIB(frame)
 };
 
 #define	FRTICKW	3
-
 struct Frbox
 {
 	long		wid;		/* in pixels */
 	Image		*tickback;	/* saved image under tick */
 	int			ticked;	/* flag: is tick onscreen? */
 	int			noredraw;	/* don't draw on the screen */
+	int			tickscale;	/* tick scaling factor */
 };
 
 ulong	frcharofpt(Frame*, Point);

src/libframe/frdraw.c

 	pt = frdrawsel0(f, pt, f->p1, f->nchars, f->cols[BACK], f->cols[TEXT]);
 }
 
-void
-frtick(Frame *f, Point pt, int ticked)
+static void
+_frtick(Frame *f, Point pt, int ticked)
 {
 	Rectangle r;
 
 	if(f->ticked==ticked || f->tick==0 || !ptinrect(pt, f->r))
 		return;
-	pt.x--;	/* looks best just left of where requested */
-	r = Rect(pt.x, pt.y, pt.x+FRTICKW, pt.y+f->font->height);
+	pt.x -= f->tickscale;	/* looks best just left of where requested */
+	r = Rect(pt.x, pt.y, pt.x+FRTICKW*f->tickscale, pt.y+f->font->height);
 	/* can go into left border but not right */
 	if(r.max.x > f->r.max.x)
 		r.max.x = f->r.max.x;
 	f->ticked = ticked;
 }
 
+void
+frtick(Frame *f, Point pt, int ticked)
+{
+	if(f->tickscale != scalesize(f->display, 1)) {
+		if(f->ticked)
+			_frtick(f, pt, 0);
+		frinittick(f);
+	}
+	_frtick(f, pt, ticked);
+}
+
 Point
 _frdraw(Frame *f, Point pt)
 {

src/libframe/frinit.c

 	Image *b;
 	Font *ft;
 
+	if(f->cols[BACK] == nil || f->display == nil)
+		return;
+	f->tickscale = scalesize(f->display, 1);
 	b = f->display->screenimage;
 	ft = f->font;
 	if(f->tick)
 		freeimage(f->tick);
-	f->tick = allocimage(f->display, Rect(0, 0, FRTICKW, ft->height), b->chan, 0, DWhite);
+	f->tick = allocimage(f->display, Rect(0, 0, f->tickscale*FRTICKW, ft->height), b->chan, 0, DWhite);
 	if(f->tick == nil)
 		return;
 	if(f->tickback)
 	/* background color */
 	draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP);
 	/* vertical line */
-	draw(f->tick, Rect(FRTICKW/2, 0, FRTICKW/2+1, ft->height), f->display->black, nil, ZP);
+	draw(f->tick, Rect(f->tickscale*(FRTICKW/2), 0, f->tickscale*(FRTICKW/2+1), ft->height), f->display->black, nil, ZP);
 	/* box on each end */
-	draw(f->tick, Rect(0, 0, FRTICKW, FRTICKW), f->cols[TEXT], nil, ZP);
-	draw(f->tick, Rect(0, ft->height-FRTICKW, FRTICKW, ft->height), f->cols[TEXT], nil, ZP);
+	draw(f->tick, Rect(0, 0, f->tickscale*FRTICKW, f->tickscale*FRTICKW), f->cols[TEXT], nil, ZP);
+	draw(f->tick, Rect(0, ft->height-f->tickscale*FRTICKW, f->tickscale*FRTICKW, ft->height), f->cols[TEXT], nil, ZP);
 }
 
 void