|
|
1.1 ! root 1: #include <CC/jerq.h> ! 2: #include "pot.pri" ! 3: ! 4: extern void bord(Bitmap *, Rectangle, int, int); ! 5: ! 6: #define P_H_STRING 0x8000 ! 7: #define P_H_VALUE 0x4000 ! 8: ! 9: Rulepot.Rulepot(Rectangle rect, short fl, short m, short v) : (rect, fl, v) ! 10: { ! 11: maxval = m; ! 12: } ! 13: ! 14: Rulepot.Rulepot(Rectangle rect, short fl, short m, Point sp, char *s, short v) : (rect, fl, v) ! 15: { ! 16: maxval = m; ! 17: flags |= P_H_STRING; ! 18: stroffset = sp; ! 19: str = s; ! 20: } ! 21: ! 22: Rulepot.Rulepot(Rectangle rect, short fl, short m, Point vp, short v) : (rect, fl, v) ! 23: { ! 24: maxval = m; ! 25: flags |= P_H_VALUE; ! 26: valoffset = vp; ! 27: } ! 28: ! 29: Rulepot.Rulepot(Rectangle rect, short fl, short m, Point vp, Point sp, char *s, short v) : (rect, fl, v) ! 30: { ! 31: maxval = m; ! 32: flags |= P_H_STRING|P_H_VALUE; ! 33: valoffset = vp; ! 34: stroffset = sp; ! 35: str = s; ! 36: } ! 37: ! 38: void ! 39: Rulepot.resize(Rectangle rect) ! 40: { ! 41: r = rect; ! 42: draw(); ! 43: } ! 44: ! 45: void ! 46: Rulepot.draw() ! 47: { ! 48: int len, i, s, e, horiz = (flags&P_STYLE)==P_HORIZ; ! 49: Point p; ! 50: Rectangle bar; ! 51: ! 52: bar = inset(r, -1); ! 53: if(horiz) ! 54: bar.o.x++; ! 55: else ! 56: bar.o.y++; ! 57: bord(&display, bar, 1, F_OR); ! 58: bar = r; ! 59: p = r.o; ! 60: if(horiz) ! 61: { ! 62: len = r.c.x - r.o.x; ! 63: s = r.o.x; ! 64: e = r.c.x; ! 65: for(i = 0; i <= 10; i++) ! 66: { ! 67: p.x = (s*(10-i) + e*i)/10; ! 68: segment(&display, p, Pt(p.x, p.y+(i%5? 5:10)), F_OR); ! 69: } ! 70: rx = bar.c.x = bar.o.x + muldiv(val, len, maxval); ! 71: } ! 72: else ! 73: { ! 74: p.x = r.c.x; ! 75: len = r.c.y - r.o.y; ! 76: s = r.c.y; ! 77: e = r.o.y; ! 78: for(i = 0; i <= 10; i++) ! 79: { ! 80: p.y = (s*(10-i) + e*i)/10; ! 81: segment(&display, p, Pt(p.x-(i%5? 5:10), p.y), F_OR); ! 82: } ! 83: rx = bar.o.y = bar.c.y - muldiv(val, len, maxval); ! 84: } ! 85: rectf(&display, bar, F_XOR); ! 86: if(flags&P_H_STRING) string(&defont, str, &display, r.o+stroffset, F_OR); ! 87: if(flags&P_H_VALUE) prval(r.o+valoffset, val); ! 88: } ! 89: ! 90: confine(int x, int lo, int hi) ! 91: { ! 92: return(min(max(lo, x), hi)); ! 93: } ! 94: ! 95: void ! 96: Rulepot.mod(int but) ! 97: { ! 98: int x, len, horiz = (flags&P_STYLE)==P_HORIZ; ! 99: Rectangle bar = r; ! 100: ! 101: len = horiz? (r.c.x - r.o.x):(r.c.y - r.o.y); ! 102: bar = r; ! 103: while(button(but)) ! 104: { ! 105: x = horiz? confine(mouse.xy.x, r.o.x, r.c.x):confine(mouse.xy.y, r.o.y, r.c.y); ! 106: if(rx != x) ! 107: { ! 108: if(flags&P_H_VALUE) prval(r.o+valoffset, val); ! 109: if(horiz) ! 110: { ! 111: bar.o.x = min(x, rx); ! 112: bar.c.x = max(x, rx); ! 113: val = muldiv(x-r.o.x, maxval, len); ! 114: } ! 115: else ! 116: { ! 117: bar.o.y = min(x, rx); ! 118: bar.c.y = max(x, rx); ! 119: val = muldiv(r.c.y-x, maxval, len); ! 120: } ! 121: rx = x; ! 122: rectf(&display, bar, F_XOR); ! 123: if(flags&P_H_VALUE) prval(r.o+valoffset, val); ! 124: nap(2); ! 125: } ! 126: } ! 127: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.