Annotation of 43BSDTahoe/new/X/libapollo/cursor.c, revision 1.1

1.1     ! root        1:     /*
        !             2: 
        !             3:     Copyright 1986 by the University of Utah
        !             4: 
        !             5:     Permission to use, copy, modify, and distribute this
        !             6:     software and its documentation for any purpose and without
        !             7:     fee is hereby granted, provided that the above copyright
        !             8:     notice appear in all copies and that both that copyright
        !             9:     notice and this permission notice appear in supporting
        !            10:     documentation, and that the name of the University of Utah
        !            11:     not be used in advertising or publicity pertaining to 
        !            12:     distribution of the software without specific, written 
        !            13:     prior permission. The University of Utah makes no
        !            14:     representations about the suitability of this software for
        !            15:     any purpose.  It is provided "as is" without express or
        !            16:     implied warranty.
        !            17: 
        !            18:     */
        !            19: 
        !            20: /* cursor.c    various stuff with the mouse & cursor
        !            21:  *
        !            22:  *     StoreCursor             Creates a cursor
        !            23:  *     FreeCursor              Frees the storage taken by a cursor
        !            24:  *     LoadCursor              Loads a bitmap to use as cursor
        !            25:  *     InitMouse               Initialize the mouse
        !            26:  *     SetCursorPosition       Forces cursor to a particular position
        !            27:  *     SetMouseCharacteristics Controls speed of cursor relative to mouse
        !            28:  *
        !            29:  */
        !            30: 
        !            31: /*
        !            32:  *     ToDo:
        !            33:  *             Threshold/Acceleration
        !            34:  *             Use macros for CheckCursor()
        !            35:  */
        !            36: 
        !            37: #include "Xapollo.h"
        !            38: 
        !            39: extern char *Xalloc();
        !            40: extern DEVICE *CurrentDevice;
        !            41: 
        !            42: CURSOR *CurrentCursor;
        !            43: int CursorDisplayed;
        !            44: 
        !            45: CURSOR *StoreCursor (func, image, fore, back, mask, xoff, yoff)
        !            46:        BITMAP *image;
        !            47:        BITMAP *mask;
        !            48:        int func, fore, back, xoff, yoff;
        !            49: {
        !            50:     register CURSOR *cursor;
        !            51:     register CursPriv *data;
        !            52: 
        !            53:     if (!image)
        !            54:        return (NULL);
        !            55:     cursor = (CURSOR *) Xalloc(sizeof(CURSOR));
        !            56:     cursor->width = image->width;
        !            57:     cursor->height = image->height;
        !            58:     cursor->xmin = 0;
        !            59:     cursor->ymin = 0;
        !            60:     cursor->xoff = xoff;
        !            61:     cursor->yoff = yoff;
        !            62:     cursor->xmax = Screen.width - image->width;
        !            63:     cursor->ymax = Screen.height - image->height;
        !            64:     cursor->refcnt = 1;
        !            65: 
        !            66:     data = (CursPriv *) Xalloc(sizeof(CursPriv));
        !            67:     cursor->data = (caddr_t) data;
        !            68:     image->refcnt++;
        !            69:     data->bits = (caddr_t) image;
        !            70:     data->fore = fore;
        !            71:     data->back = back;
        !            72:     data->save = make_bitmap(NULL, image->width, image->height+2, false);
        !            73:     if (mask) {
        !            74:        data->mask = mask;
        !            75:        mask->refcnt++;
        !            76:     } else
        !            77:        data->mask = NULL;
        !            78:     return (cursor);
        !            79: }
        !            80: 
        !            81: FreeCursor (cursor)
        !            82:        register CURSOR *cursor;
        !            83: {
        !            84:     CursPriv   *cp = CDATA(cursor);
        !            85: 
        !            86:     if (--(cp->bits->refcnt) <= 0)
        !            87:        FreeBitmap(cp->bits);
        !            88:     if (cp->mask && --(cp->mask->refcnt) <= 0)
        !            89:        FreeBitmap(cp->mask);
        !            90:     FreeBitmap(cp->save);
        !            91:     free((caddr_t) CDATA(cursor));
        !            92:     free((caddr_t) cursor);
        !            93: }
        !            94: 
        !            95: 
        !            96: LoadCursor (cursor)
        !            97:        register CURSOR *cursor;
        !            98: {
        !            99:     if (CursorDisplayed)
        !           100:        DisplayCursor(NULL);
        !           101:     if ((CurrentCursor = cursor) != NULL) {
        !           102:        DisplayCursor(cursor);
        !           103:         }
        !           104: }
        !           105: 
        !           106: InitMouse ()
        !           107: {
        !           108: }
        !           109: 
        !           110: SetCursorPosition(pos)
        !           111:        register vsCursor *pos;
        !           112: {
        !           113:     if (pos->x != (CurrentDevice->mouse->x) ||
        !           114:         pos->y != (CurrentDevice->mouse->y)) {
        !           115:        if (CursorDisplayed)
        !           116:            DisplayCursor(NULL);
        !           117:        CurrentDevice->mouse->x = pos->x;
        !           118:            CurrentDevice->mouse->y = pos->y;
        !           119:        DisplayCursor(CurrentCursor);
        !           120:         }
        !           121: }
        !           122: 
        !           123: SetMouseCharacteristics (threshold, accelaration)
        !           124:        int threshold, accelaration;
        !           125: {
        !           126: }
        !           127: 
        !           128: DisplayCursor(cs)
        !           129: CURSOR *cs;
        !           130: {
        !           131:     vsCursor   *ms = CurrentDevice->mouse;
        !           132:     short op, i, msx, msy;
        !           133:     gpr_$window_t srcwin;
        !           134:     gpr_$position_t dstorg, destorg;
        !           135:     status_$t status;
        !           136:     static gpr_$attribute_desc_t ab = -1;
        !           137:     gpr_$window_t saved_clip_wind;
        !           138:     gpr_$window_t screen_clip_wind;
        !           139:     boolean saved_clip_active;
        !           140:     gpr_$mask_t saved_plane_mask;
        !           141:     gpr_$raster_op_array_t saved_rops;
        !           142:     
        !           143: 
        !           144: /* Use a private attribute block, since caller has probably already set
        !           145:    lots of attributes
        !           146:   --   We disable this, and just save/restore raster ops, clip window and plane mask,
        !           147:   --   because attribute block switching (1) is expensive, especially on color hardware, and
        !           148:   --   (2) screws up input enables something awful.
        !           149:  */
        !           150: /*
        !           151:     if (ab == -1)  {
        !           152:         gpr_$allocate_attribute_block( ab, status );
        !           153:         gpr_$set_attribute_block( ab, status );
        !           154:         gpr_$set_plane_mask(Screen.plane_mask, status);
        !           155:         }
        !           156:     gpr_$set_attribute_block( ab, status );
        !           157: */
        !           158:     gpr_$inq_raster_ops (saved_rops, status);
        !           159:     gpr_$inq_constraints (saved_clip_wind, saved_clip_active, saved_plane_mask, status);
        !           160:     screen_clip_wind.window_base.x_coord = 0;
        !           161:     screen_clip_wind.window_base.y_coord = 0;
        !           162:     screen_clip_wind.window_size.x_size = Screen.width;
        !           163:     screen_clip_wind.window_size.y_size = Screen.height;
        !           164:     gpr_$set_clip_window(screen_clip_wind, status);
        !           165:     gpr_$set_plane_mask( Screen.plane_mask, status);
        !           166: 
        !           167:     msx = ms->x < 0 ? 0 : ms->x;
        !           168:     msy = ms->y < 0 ? 0 : ms->y;
        !           169:     dstorg.x_coord = msx;
        !           170:     dstorg.y_coord = msy;
        !           171:     if (cs == NULL) {
        !           172:        if (CursorDisplayed && (cs = CurrentCursor) != NULL) {
        !           173:            /* take it out */  
        !           174:         srcwin.x_coord = srcwin.y_coord = 0;
        !           175:         srcwin.x_size = cs->width;
        !           176:         srcwin.y_size = cs->height;
        !           177:         for (i=0; i<Screen.depth; i++) 
        !           178:             gpr_$set_raster_op( (gpr_$plane_t)i, (gpr_$raster_op_t)3, status );
        !           179:         gpr_$pixel_blt(CDATA(cs)->save->data, srcwin, dstorg, status);
        !           180:            CursorDisplayed = 0;
        !           181:         }
        !           182:     }
        !           183:     else {
        !           184:            int botop = (CDATA(cs)->back == 1 ? 7 : 4);
        !           185:            int topop = (CDATA(cs)->fore == 1 ? 7 : 4);
        !           186: 
        !           187:         CursorDisplayed = -1;
        !           188: 
        !           189:         /* save image beneath cursor */
        !           190:         srcwin.x_size = cs->width;
        !           191:         srcwin.y_size = cs->height;
        !           192:         srcwin.x_coord = msx;
        !           193:         srcwin.y_coord = msy;
        !           194:         destorg.x_coord = destorg.y_coord = 0;
        !           195:         gpr_$set_bitmap(CDATA(cs)->save->data, status);
        !           196: /*  the following code is redundant
        !           197:         for (i=0; i<Screen.depth; i++) 
        !           198:             gpr_$set_raster_op( (gpr_$plane_t)i, (gpr_$raster_op_t)3, status );
        !           199: */
        !           200:         gpr_$pixel_blt(Screen.bm, srcwin, destorg, status);
        !           201:         gpr_$set_bitmap(Screen.bm, status);
        !           202: 
        !           203:         /* display mask */
        !           204:         srcwin.x_coord = srcwin.y_coord = 0;
        !           205:         if (CDATA(cs)->mask != NULL) {
        !           206:             for (i=0; i<Screen.depth; i++) 
        !           207:                 gpr_$set_raster_op( (gpr_$plane_t)i, (gpr_$raster_op_t)botop, status );
        !           208:             gpr_$pixel_blt(CDATA(cs)->mask->data, srcwin, dstorg, status);
        !           209:             }
        !           210:         /* display cursor itself */
        !           211:         for (i=0; i<Screen.depth; i++) 
        !           212:             gpr_$set_raster_op( (gpr_$plane_t)i, (gpr_$raster_op_t)topop, status );
        !           213:         gpr_$pixel_blt(CDATA(cs)->bits->data, srcwin, dstorg, status);
        !           214:         
        !           215:         }
        !           216: /*
        !           217:     gpr_$set_attribute_block( Screen.ab, status );
        !           218: */
        !           219:     for (i=0; i<Screen.depth; i++) 
        !           220:         gpr_$set_raster_op( (gpr_$plane_t)i, saved_rops[i], status );
        !           221:     gpr_$set_clip_window(saved_clip_wind, status);
        !           222:     gpr_$set_plane_mask(saved_plane_mask, status);
        !           223: }

unix.superglobalmegacorp.com

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