--- researchv9/jerq/src/lib/j/menuhit.c 2018/04/24 17:21:59 1.1.1.1 +++ researchv9/jerq/src/lib/j/menuhit.c 2018/04/24 17:32:59 1.1.1.2 @@ -1,4 +1,6 @@ #include +#include +#include #include #define scale(x, inmin, inmax, outmin, outmax)\ @@ -6,9 +8,7 @@ #define bound(x, low, high) min(high, max( low, x )) -#define SPACING defont.height #define DISPLAY 16 -#define CHARWIDTH (defont.info[' '].width) #define DELTA 6 #define BARWIDTH 18 @@ -27,6 +27,14 @@ register Menu *m; Rectangle sr, tr, mr; /* scroll, text, menu */ register Bitmap *b; register char *s, *(*generator)(), *from, *to, fill[64]; +#ifdef MUX + Font *font = (!P||!P->defaultfont)? &defont: + P->defaultfont; +#else + Font *font = &defont; +#endif MUX + int spacing = font->height; + int charwidth = font->info['n'].width; #define sro sr.origin #define src sr.corner @@ -37,13 +45,16 @@ register Menu *m; generator = (table=m->item) ? tablegen : m->generator; p = mouse.xy; - for(length = items = 0; s=(*generator)(items); ++items) + length = width = items = 0; + for( ; s=(*generator)(items); ++items) { length = max(length, strlen(s)); + width = max(width, strwidth(font,s)); + } if(items == 0){ while(button(but)); return -1; } - width = length*CHARWIDTH+10; + width += 10; sro.x = sro.y = src.x = tro.x = mro.x = mro.y = 0; if(items <= DISPLAY) lines = items; @@ -53,10 +64,10 @@ register Menu *m; sro.x = sro.y = 1; } tro.y = 1; - mrc = trc = add(Pt(tro.x, mro.y), Pt(width, min(items, lines)*SPACING+2)); + mrc = trc = add(Pt(tro.x, mro.y), Pt(width, min(items, lines)*spacing+2)); trc.y = src.y = mrc.y-1; newtop = bound(m->prevtop, 0, items-lines); - p.y -= bound(m->prevhit, 0, lines-1)*SPACING+SPACING/2; + p.y -= bound(m->prevhit, 0, lines-1)*spacing+spacing/2; p.x = bound(p.x-(src.x+width/2), 0, XMAX-mrc.x); p.y = bound(p.y, 0, YMAX-mrc.y); sr = raddp(sr, p); @@ -90,9 +101,9 @@ PaintMenu: else *to++ = *from; *to = '\0'; - q.x += (width-jstrwidth(fill))/2; - string(&defont, fill, &display, q, F_XOR); - p.y += SPACING; + q.x += (width-strwidth(font,fill))/2; + string(font, fill, &display, q, F_XOR); + p.y += spacing; } savep = mouse.xy; for(newhit = hit = -1; button(but); nap(2)){ @@ -120,24 +131,24 @@ PaintMenu: savep = p; newhit = -1; if(ptinrect(p, tr)){ - newhit = bound((p.y-tro.y)/SPACING, 0, lines-1); + newhit = bound((p.y-tro.y)/spacing, 0, lines-1); if(newhit!=hit && hit>=0 - && abs(tro.y+SPACING*newhit+SPACING/2-p.y) > SPACING/3) + && abs(tro.y+spacing*newhit+spacing/2-p.y) > spacing/3) newhit = hit; } if(newhit != hit){ - flip(tr, hit); - flip(tr, hit = newhit); + flip(tr, hit, spacing); + flip(tr, hit = newhit, spacing); } if(newhit==0 && top>0){ newtop = top-1; - p.y += SPACING; + p.y += spacing; cursset(p); /* ->->-> */ goto PaintMenu; } if(newhit==DISPLAY-1 && top->-> */ goto PaintMenu; } @@ -157,13 +168,13 @@ PaintMenu: } static -flip(r,n) +flip(r,n,spacing) Rectangle r; { if(n<0) return; ++r.origin.x; - r.corner.y = (r.origin.y += SPACING*n) + SPACING; + r.corner.y = (r.origin.y += spacing*n) + spacing; --r.corner.x; rectf(&display, r, F_XOR); }