Annotation of researchv9/jtools/src/sunlib/button.c, revision 1.1

1.1     ! root        1: #include "jerq.h"
        !             2: 
        !             3: #define        UP      0
        !             4: #define        DOWN    1
        !             5: 
        !             6: static short boxcurs_bits[] = {
        !             7:        0x43FF, 0xE001, 0x7001, 0x3801, 0x1D01, 0x0F01, 0x8701, 0x8F01,
        !             8:        0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0x8001, 0xFFFF,
        !             9: };
        !            10: static Cursor boxcurs;
        !            11: static int firstime = 1;
        !            12: 
        !            13: Rectangle
        !            14: getrect (n)
        !            15: int n;
        !            16: {
        !            17:        return getrectb(8>>n, 1);
        !            18: }
        !            19: 
        !            20: /*
        !            21:        ngetrect:       ultimate getrect routine
        !            22:                        optional clipping rectangle
        !            23:                        optional blocking for mouse routines
        !            24:                        optional minimum width and height
        !            25:                        returns 1 if minimum rectangle is swept
        !            26: */
        !            27: int
        !            28: ngetrect (r, clip, but, block, minw, minh)
        !            29: register Rectangle *r;         /* rectangle                            */
        !            30: register Rectangle *clip;      /* clipping rectangle, can be 0         */
        !            31: register int but;              /* button 1, 2, or 3, defaults to 1     */
        !            32: register int block;            /* blocking flag 0 or 1                 */
        !            33: register int minw;             /* minimum width, can be 0              */
        !            34: register int minh;             /* minimum height, can be 0             */
        !            35: {
        !            36:        if(but == 0)
        !            37:                but = 1;
        !            38:        *r = getrectb(8>>but, block);
        !            39:        if(r->origin.x == 0 &&
        !            40:           r->origin.y == 0 &&
        !            41:           r->corner.x == 0 &&
        !            42:           r->corner.y == 0)
        !            43:                return 0;
        !            44:        if(r->corner.x - r->origin.x < minw ||
        !            45:           r->corner.y - r->origin.y < minh)
        !            46:                return 0;
        !            47:        if(clip && !rectclip(r, *clip))
        !            48:                return 0;
        !            49:        return 1;
        !            50: }
        !            51: 
        !            52: Rectangle
        !            53: getrectb (n, block)
        !            54: int n, block;
        !            55: {
        !            56:        Rectangle r, canon();
        !            57:        Point p1, p2;
        !            58:        Cursor *prev;
        !            59:        
        !            60:        if (firstime) {
        !            61:                boxcurs = ToCursor(boxcurs_bits, boxcurs_bits, 8, 8);
        !            62:                firstime = 0;
        !            63:        }
        !            64:        prev = cursswitch(&boxcurs);
        !            65:        Jscreengrab();
        !            66:        if(block){
        !            67:                buttons(UP);
        !            68:                buttons(DOWN);
        !            69:        }
        !            70:        if(!(mouse.buttons&n)){
        !            71:                r.origin.x=r.origin.y=r.corner.x=r.corner.y=0;
        !            72:                buttons(UP);
        !            73:                goto Return;
        !            74:        }
        !            75:        p1 = add(mouse.xy, Joffset);
        !            76:        p2 = p1;
        !            77:        r = canon(p1, p2);
        !            78:        outline(r);
        !            79:        for(; mouse.buttons&n; nap(2)){
        !            80:                outline(r);
        !            81:                p2 = add(mouse.xy, Joffset);
        !            82:                r = canon(p1, p2);
        !            83:                outline(r);
        !            84:        }
        !            85:        outline(r);     /* undraw for the last time */
        !            86:     Return:
        !            87:        Jscreenrelease();
        !            88:        cursswitch(prev);
        !            89:        r = rsubp(r, Joffset);
        !            90:        if(!rectclip(&r, Rpt(Drect.org,Drect.cor)))
        !            91:                r.origin.x = r.origin.y = r.corner.x = r.corner.y = 0;
        !            92:        return r;
        !            93: }
        !            94: 
        !            95: buttons (updown)
        !            96: {
        !            97:        while((button123()!=0) != updown)
        !            98:                nap(2);
        !            99: }
        !           100: 
        !           101: Rectangle
        !           102: canon (p1, p2)
        !           103: Point p1, p2;
        !           104: {
        !           105:        Rectangle r;
        !           106:        r.origin.x = min(p1.x, p2.x);
        !           107:        r.origin.y = min(p1.y, p2.y);
        !           108:        r.corner.x = max(p1.x, p2.x);
        !           109:        r.corner.y = max(p1.y, p2.y);
        !           110:        return(r);
        !           111: }
        !           112: 
        !           113: static outline(r)
        !           114: Rectangle  r;
        !           115: {
        !           116:        segment(&Jfscreen, r.org, Pt(r.cor.x, r.org.y), F_XOR);
        !           117:        segment(&Jfscreen, Pt(r.cor.x, r.org.y), r.cor, F_XOR);
        !           118:        segment(&Jfscreen, r.cor, Pt(r.org.x, r.cor.y), F_XOR);
        !           119:        segment(&Jfscreen, Pt(r.org.x, r.cor.y), r.org, F_XOR);
        !           120: }
        !           121: 
        !           122: Cursor *
        !           123: cursswitch (cp)
        !           124: Cursor *cp;
        !           125: {
        !           126:        Cursor *rc;
        !           127: #ifdef SUNTOOLS
        !           128:        extern struct pixrectops mem_ops;
        !           129:        static struct mpr_data d = 
        !           130:                {mpr_linebytes(16,1), (short *)0, {0, 0}, 0, 0};
        !           131:        static struct pixrect curs = {&mem_ops, 16, 16, 1, (caddr_t)&d};
        !           132:        static struct cursor cursor = {7, 7, F_XOR, &curs};
        !           133: #endif SUNTOOLS
        !           134: 
        !           135:        if (cp == (Cursor *)0)
        !           136:                cp = &normalcursor;
        !           137: #ifdef X11
        !           138:        XDefineCursor(dpy, display.dr, *cp);
        !           139: #endif X11
        !           140: #ifdef SUNTOOLS
        !           141:        cursor.cur_xhot = cp->hotx;
        !           142:        cursor.cur_yhot = cp->hoty;
        !           143:        d.md_image = cp->bits;
        !           144:        win_setcursor(displayfd, &cursor);
        !           145: #endif SUNTOOLS
        !           146:        rc = P->cursor;
        !           147:        P->cursor = cp;
        !           148:        return rc;
        !           149: }
        !           150: 
        !           151: cursset (p)
        !           152: Point p;
        !           153: {
        !           154: #ifdef X11
        !           155:        XWarpPointer(dpy, display.dr, display.dr, mouse.xy.x, mouse.xy.y,
        !           156:                display.rect.corner.x, display.rect.corner.y, p.x, p.y);
        !           157: #endif X11
        !           158: #ifdef SUNTOOLS
        !           159:        win_setmouseposition(displayfd, p.x, p.y);
        !           160: #endif SUNTOOLS
        !           161:        mouse.xy.x = p.x;
        !           162:        mouse.xy.y = p.y;
        !           163: }

unix.superglobalmegacorp.com

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