t9term: adjust to dpi changes - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a8a0a6422c5af47fad529917835ed1c30cd43936
 (DIR) parent 94dae4befca074c0415b1ba448b69a9fa16c1981
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Mon, 26 Nov 2012 00:13:18 -0500
       
       9term: adjust to dpi changes
       
       R=rsc
       http://codereview.appspot.com/6847105
       
       Diffstat:
         M src/cmd/9term/wind.c                |      38 +++++++++++++++++++------------
       
       1 file changed, 23 insertions(+), 15 deletions(-)
       ---
 (DIR) diff --git a/src/cmd/9term/wind.c b/src/cmd/9term/wind.c
       t@@ -35,6 +35,14 @@ static        Image        *holdcol;
        static        Image        *lightholdcol;
        static        Image        *paleholdcol;
        
       +static int
       +wscale(Window *w, int n)
       +{
       +        if(w == nil || w->i == nil)
       +                return n;
       +        return scalesize(w->i->display, n);
       +}
       +
        Window*
        wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
        {
       t@@ -58,7 +66,7 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
                }
                w = emalloc(sizeof(Window));
                w->screenr = i->r;
       -        r = insetrect(i->r, Selborder+1);
       +        r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1));
                w->i = i;
                w->mc = *mc;
                w->ck = ck;
       t@@ -69,9 +77,9 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
                w->mouseread =  chancreate(sizeof(Mousereadmesg), 0);
                w->wctlread =  chancreate(sizeof(Consreadmesg), 0);
                w->scrollr = r;
       -        w->scrollr.max.x = r.min.x+Scrollwid;
       +        w->scrollr.max.x = r.min.x+wscale(w, Scrollwid);
                w->lastsr = ZR;
       -        r.min.x += Scrollwid+Scrollgap;
       +        r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap);
                frinit(&w->f, r, font, i, cols);
                w->f.maxtab = maxtab*stringwidth(font, "0");
                w->topped = ++topped;
       t@@ -80,9 +88,9 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
                w->scrolling = scrolling;
                w->dir = estrdup(startdir);
                w->label = estrdup("<unnamed>");
       -        r = insetrect(w->i->r, Selborder);
       +        r = insetrect(w->i->r, wscale(w, Selborder));
                draw(w->i, r, cols[BACK], nil, w->f.entire.min);
       -        wborder(w, Selborder);
       +        wborder(w, wscale(w, Selborder));
                wscrdraw(w);
                incref(&w->ref);        /* ref will be removed after mounting; avoids delete before ready to be deleted */
                return w;
       t@@ -123,11 +131,11 @@ fprint(2, "res %p %p\n", w->i, i);
                }
        /*        wsetname(w); */
        /*XXX        w->mc.image = i; */
       -        r = insetrect(i->r, Selborder+1);
       +        r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1));
                w->scrollr = r;
       -        w->scrollr.max.x = r.min.x+Scrollwid;
       +        w->scrollr.max.x = r.min.x+wscale(w, Scrollwid);
                w->lastsr = ZR;
       -        r.min.x += Scrollwid+Scrollgap;
       +        r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap);
                if(move)
                        frsetrects(&w->f, r, w->i);
                else{
       t@@ -135,13 +143,13 @@ fprint(2, "res %p %p\n", w->i, i);
                        frinit(&w->f, r, w->f.font, w->i, cols);
                        wsetcols(w);
                        w->f.maxtab = maxtab*stringwidth(w->f.font, "0");
       -                r = insetrect(w->i->r, Selborder);
       +                r = insetrect(w->i->r, wscale(w, Selborder));
                        draw(w->i, r, cols[BACK], nil, w->f.entire.min);
                        wfill(w);
                        wsetselect(w, w->q0, w->q1);
                        wscrdraw(w);
                }
       -        wborder(w, Selborder);
       +        wborder(w, wscale(w, Selborder));
                w->topped = ++topped;
                w->resized = TRUE;
                w->mouse.counter++;
       t@@ -154,9 +162,9 @@ wrefresh(Window *w, Rectangle r)
        
                /* BUG: rectangle is ignored */
                if(w == input)
       -                wborder(w, Selborder);
       +                wborder(w, wscale(w, Selborder));
                else
       -                wborder(w, Unselborder);
       +                wborder(w, wscale(w, Unselborder));
                if(w->mouseopen)
                        return;
                draw(w->i, insetrect(w->i->r, Borderwidth), w->f.cols[BACK], nil, w->i->r.min);
       t@@ -764,10 +772,10 @@ wrepaint(Window *w)
                        frredraw(&w->f);
                }
                if(w == input){
       -                wborder(w, Selborder);
       +                wborder(w, wscale(w, Selborder));
                        wsetcursor(w, 0);
                }else
       -                wborder(w, Unselborder);
       +                wborder(w, wscale(w, Unselborder));
        }
        
        int
       t@@ -890,7 +898,7 @@ wplumb(Window *w)
        int
        winborder(Window *w, Point xy)
        {
       -        return ptinrect(xy, w->screenr) && !ptinrect(xy, insetrect(w->screenr, Selborder));
       +        return ptinrect(xy, w->screenr) && !ptinrect(xy, insetrect(w->screenr, wscale(w, Selborder)));
        }
        
        void