aboutsummaryrefslogtreecommitdiff
path: root/src/libframe
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2012-11-25 23:48:19 -0500
committerRuss Cox <rsc@swtch.com>2012-11-25 23:48:19 -0500
commitcc9547960e7cf12129e84c9489eb5dcd6235144b (patch)
treefafffafefcb6f8594dec50f499be5493d8d20717 /src/libframe
parentffaaaf9dae8de3c58c0d13f94926ddc363fdaf97 (diff)
downloadplan9port-cc9547960e7cf12129e84c9489eb5dcd6235144b.tar.gz
plan9port-cc9547960e7cf12129e84c9489eb5dcd6235144b.tar.bz2
plan9port-cc9547960e7cf12129e84c9489eb5dcd6235144b.zip
libframe: auto scale tick for retina
R=rsc http://codereview.appspot.com/6850102
Diffstat (limited to 'src/libframe')
-rw-r--r--src/libframe/frdraw.c19
-rw-r--r--src/libframe/frinit.c11
2 files changed, 22 insertions, 8 deletions
diff --git a/src/libframe/frdraw.c b/src/libframe/frdraw.c
index c1cace42..2a3a95e0 100644
--- a/src/libframe/frdraw.c
+++ b/src/libframe/frdraw.c
@@ -137,15 +137,15 @@ frredraw(Frame *f)
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;
@@ -157,6 +157,17 @@ frtick(Frame *f, Point pt, int ticked)
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)
{
diff --git a/src/libframe/frinit.c b/src/libframe/frinit.c
index c178ede1..90931f25 100644
--- a/src/libframe/frinit.c
+++ b/src/libframe/frinit.c
@@ -31,11 +31,14 @@ frinittick(Frame *f)
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)
@@ -49,10 +52,10 @@ frinittick(Frame *f)
/* 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