|
|
1.1 ! root 1: #include <jerq.h> ! 2: #include <font.h> ! 3: #define SPACING 14 ! 4: Rectangle ! 5: drawmenu(menu, pt) ! 6: register Menu *menu; ! 7: Point pt; ! 8: { ! 9: register i,xmax; ! 10: register char **s; ! 11: Point p; ! 12: register Bitmap *b; ! 13: Rectangle r; ! 14: extern Font defont; ! 15: ! 16: s = menu->item; ! 17: xmax = jstrwidth(*s++); ! 18: for (i = 0; *s; i++) ! 19: xmax = max(xmax,jstrwidth(*s++)); ! 20: xmax += 10; ! 21: menu->n = i+1; ! 22: if(menu->lasty <= 0) ! 23: menu->lasty = SPACING/2; ! 24: /* move p to origin of rectangle */ ! 25: p.x = max(0, pt.x-(xmax>>1)); ! 26: p.y = max(0, pt.y-menu->lasty); ! 27: p.x = min(p.x, XMAX-xmax); ! 28: p.y = min(p.y, YMAX-menu->n*SPACING-2); ! 29: r.origin = r.corner = p; ! 30: r.corner.x += xmax; ! 31: r.corner.y += menu->n*SPACING+2; ! 32: menu->b = b = balloc(r); ! 33: cursinhibit(); ! 34: if(b) ! 35: bitblt(&display, r, b, p, F_STORE); ! 36: rectf(&display, r, F_OR); ! 37: rectf(&display, inset(r, 1), F_CLR); ! 38: p.y += 2; /* careful with font ascent */ ! 39: for (s = menu->item; *s; s++) { ! 40: string(&defont, *s, &display, ! 41: Pt(p.x+((xmax-jstrwidth(*s))>>1), p.y), F_XOR); ! 42: p.y += SPACING; ! 43: } ! 44: cursallow(); ! 45: return r; ! 46: } ! 47: menuhit(menu,but) ! 48: register Menu *menu; ! 49: { ! 50: register hit= -1,y=menu->lasty,oldhit; ! 51: register Bitmap *b; ! 52: Point p; ! 53: Rectangle r; ! 54: ! 55: r = drawmenu(menu, mouse.xy); ! 56: for (oldhit = -1; bttn(but); nap(2)) { ! 57: if (ptinrect((p = mouse.xy),r)) { ! 58: y = p.y - r.origin.y; ! 59: hit = y/SPACING; ! 60: if (hit<0) hit = 0; ! 61: if (hit>=menu->n) hit = menu->n-1; ! 62: if (hit!=oldhit) { ! 63: /* A little hysteresis */ ! 64: if (oldhit>0 && ! 65: abs(y-(SPACING/2+hit*SPACING)) > SPACING/3) ! 66: hit = oldhit; ! 67: } ! 68: } ! 69: else ! 70: hit = -1; ! 71: if (hit != oldhit) { ! 72: flip(r,oldhit); ! 73: flip(r,hit); ! 74: oldhit = hit; ! 75: } ! 76: } ! 77: if(b=menu->b){ /* assignment = */ ! 78: cursinhibit(); ! 79: screenswap(b, b->rect, b->rect); ! 80: cursallow(); ! 81: bfree(b); ! 82: menu->b=0; ! 83: } ! 84: menu->lasty = y; ! 85: return(hit); ! 86: } ! 87: ! 88: static flip(r,n) ! 89: Rectangle r; ! 90: register int n; ! 91: { ! 92: if (n >= 0) { ! 93: r.origin.y += SPACING*n+1; /* +1 for the top line... */ ! 94: r.corner.y = r.origin.y+SPACING; ! 95: r.origin.x++; ! 96: r.corner.x--; ! 97: rectf(&display, r, F_XOR); ! 98: } ! 99: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.