Annotation of researchv9/jerq/src/lib/pot/bmap.c, revision 1.1

1.1     ! root        1: #include       <CC/jerq.h>
        !             2: #include       "pot.pri"
        !             3: 
        !             4: static Rectangle r32 = Rectangle( 0,0, 32,32 );
        !             5: 
        !             6: class Bmapitem
        !             7: {
        !             8: public:
        !             9:        Point stroffset;
        !            10:        char *str;
        !            11:        Bitmap *map;
        !            12:        Bmapitem *next;
        !            13:        Bmapitem(Point, char *, Bitmap *);
        !            14: };
        !            15: 
        !            16: #define                P_B_STRING      0x8000
        !            17: 
        !            18: Bmappot.Bmappot(Rectangle rect, short fl, short v) : (rect, fl, v)
        !            19: {
        !            20:        items = 0;
        !            21:        nitems = 0;
        !            22:        corner.x = corner.y = 0;
        !            23: }
        !            24: 
        !            25: Bmappot.Bmappot(Rectangle rect, short fl, Point p, char *s, short v) : (rect, fl, v)
        !            26: {
        !            27:        flags |= P_B_STRING;
        !            28:        str = s;
        !            29:        stroffset = p;
        !            30:        items = 0;
        !            31:        nitems = 0;
        !            32:        corner.x = corner.y = 0;
        !            33: }
        !            34: 
        !            35: void
        !            36: Bmappot.draw()
        !            37: {
        !            38:        register Bmapitem *b;
        !            39:        int n, style = flags&P_STYLE;
        !            40:        Point p, step;
        !            41: 
        !            42:        if(flags&P_B_STRING) string(&defont, str, &display, r.o+stroffset, F_OR);
        !            43:        if(nitems == 0) return;
        !            44:        step.x = step.y = 0;
        !            45:        if(style <= P_HORIZ)
        !            46:        {
        !            47:                if(flags&P_HORIZ)
        !            48:                        step.x = (corner.x)/(nitems-1);
        !            49:                else
        !            50:                        step.y = (corner.y-14)/(nitems-1);
        !            51:                for(n = 0, b = items, p = r.o; b; b = b->next, n++)
        !            52:                {
        !            53:                        if(n == val)
        !            54:                                bitblt(b->map, b->map->rect, &display, r.o, F_STORE);
        !            55:                        string(&defont, b->str, &display, add(b->stroffset, p), F_OR);
        !            56:                        p = p+step;
        !            57:                }
        !            58:        }
        !            59:        else if(style == P_CIRC)
        !            60:        {
        !            61:                Point center = div(add(r.o, r.c), 2);
        !            62: 
        !            63:                for(n = 0, b = items; b; b = b->next, n++)
        !            64:                {
        !            65:                        if(n == val)
        !            66:                                bitblt(b->map, b->map->rect, &display, r.o, F_STORE);
        !            67:                        string(&defont, b->str, &display, b->stroffset+center, F_OR);
        !            68:                }
        !            69:        }
        !            70: }
        !            71: 
        !            72: void
        !            73: Bmappot.mod(int but)
        !            74: {
        !            75:        register Bmapitem *b;
        !            76:        int style = flags&P_STYLE, sel, n = max(nitems, 1);
        !            77: 
        !            78:        if(style <= P_HORIZ)
        !            79:        {
        !            80:                int gap, horiz = style==P_HORIZ;
        !            81: 
        !            82:                gap = (horiz? (r.c.x-r.o.x):(r.c.y-r.o.y))/n;
        !            83:                while(button(but))
        !            84:                {
        !            85:                        sel = (horiz? (mouse.xy.x-r.o.x):(mouse.xy.y-r.o.y))/gap;
        !            86:                        sel = max(0, min(sel, nitems-1));
        !            87:                        if(sel != val)
        !            88:                        {
        !            89:                                val = sel;
        !            90:                                for(b = items; sel--; b = b->next);
        !            91:                                bitblt(b->map, b->map->rect, &display, r.o, F_STORE);
        !            92:                                nap(2);
        !            93:                        } 
        !            94:                }
        !            95:        }
        !            96:        else if(style == P_CIRC)
        !            97:        {
        !            98:                Point p, center = div(add(r.o, r.c), 2);
        !            99:                int ndeg = 360/n;
        !           100: 
        !           101:                while(button(but))
        !           102:                {
        !           103:                        p = mouse.xy - center;
        !           104:                        sel = (atan2(p.x, p.y)/ndeg + 1)%n;
        !           105:                        if(sel != val)
        !           106:                        {
        !           107:                                val = sel;
        !           108:                                for(b = items; sel--; b = b->next);
        !           109:                                bitblt(b->map, b->map->rect, &display, r.o, F_STORE);
        !           110:                                nap(2);
        !           111:                        } 
        !           112:                }
        !           113:        }
        !           114:        b = 0;
        !           115: }
        !           116: 
        !           117: void
        !           118: Bmappot.resize(Rectangle rect)
        !           119: {
        !           120:        r = rcenter(Rpt(Pt(0, 0), corner), rect);
        !           121:        draw();
        !           122: }
        !           123: 
        !           124: static Bitmap *
        !           125: bt(Texture32 *t)
        !           126: {
        !           127:        Bitmap *b = balloc(Rect(0, 0, 32, 32));
        !           128: 
        !           129:        texture32(b, b->rect, t, F_OR);
        !           130:        return(b);
        !           131: }
        !           132: 
        !           133: void
        !           134: Bmappot.item(Point p, char *s, Texture32 *t)
        !           135: {
        !           136:        item(p, s, bt(t));
        !           137: }
        !           138: 
        !           139: void
        !           140: Bmappot.item(Point p, char *s, Bitmap *bp)
        !           141: {
        !           142:        register Bmapitem *b, *bb;
        !           143: 
        !           144:        bb = new Bmapitem(p, s, bp);
        !           145:        corner.x = max(corner.x, bp->rect.c.x);
        !           146:        corner.y = max(corner.y, bp->rect.c.y);
        !           147:        r = rcenter(Rpt(Pt(0, 0), corner), r);
        !           148:        if(items == 0)
        !           149:                items = bb;
        !           150:        else
        !           151:        {
        !           152:                for(b = items; b->next; b = b->next)
        !           153:                        ;
        !           154:                b->next = bb;
        !           155:        }
        !           156:        nitems++;
        !           157: }
        !           158: 
        !           159: Bmapitem.Bmapitem(Point p, char *s, Bitmap *bp)
        !           160: {
        !           161:        str = s;
        !           162:        stroffset = p;
        !           163:        map = bp;
        !           164:        next = 0;
        !           165: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.