2 #include "../port/lib.h"
6 #include "../port/error.h"
14 extern Memimage* gscreen;
19 static Memimage* swback; /* screen under cursor */
20 static Memimage* swimg; /* cursor image */
21 static Memimage* swmask; /* cursor mask */
22 static Memimage* swimg1;
23 static Memimage* swmask1;
25 static Point swoffset;
26 static Rectangle swrect; /* screen rectangle in swback */
27 static Point swvispt; /* actual cursor location */
28 static int swvisible; /* is the cursor visible? */
31 * called with drawlock locked for us, most of the time.
32 * kernel prints at inopportune times might mean we don't
33 * hold the lock, but memimagedraw is now reentrant so
34 * that should be okay: worst case we get cursor droppings.
41 if(swback == nil || gscreen == nil)
44 memimagedraw(gscreen, swrect, swback, ZP, memopaque, ZP, S);
45 flushmemscreen(swrect);
49 swcursoravoid(Rectangle r)
51 if(swvisible && rectXrect(r, swrect)){
53 mouseredraw(); /* schedule cursor redraw after we release drawlock */
62 if(swback == nil || swimg1 == nil || swmask1 == nil || gscreen == nil)
64 assert(!canqlock(&drawlock));
65 swvispt = addpt(swoffset, p);
66 swrect = rectaddpt(Rect(0,0,16,16), swvispt);
67 memimagedraw(swback, swback->r, gscreen, swvispt, memopaque, ZP, S);
68 memimagedraw(gscreen, swrect, swimg1, ZP, swmask1, ZP, SoverD);
69 flushmemscreen(swrect);
74 swcursorload(Cursor *curs)
79 if(swimg == nil || swmask == nil || swimg1 == nil || swmask1 == nil)
82 * Build cursor image and mask.
83 * Image is just the usual cursor image
84 * but mask is a transparent alpha mask.
86 * The 16x16x8 memimages do not have
87 * padding at the end of their scan lines.
89 ip = byteaddr(swimg, ZP);
90 mp = byteaddr(swmask, ZP);
94 for(j=0x80; j; j>>=1){
95 *ip++ = set&j ? 0x00 : 0xFF;
96 *mp++ = (clr|set)&j ? 0xFF : 0x00;
99 swoffset = curs->offset;
100 memimagedraw(swimg1, swimg1->r, swimg, ZP, memopaque, ZP, S);
101 memimagedraw(swmask1, swmask1->r, swmask, ZP, memopaque, ZP, S);
113 freememimage(swback);
114 freememimage(swmask);
115 freememimage(swmask1);
117 freememimage(swimg1);
119 swback = allocmemimage(Rect(0,0,32,32), gscreen->chan);
120 swmask = allocmemimage(Rect(0,0,16,16), GREY8);
121 swmask1 = allocmemimage(Rect(0,0,16,16), GREY1);
122 swimg = allocmemimage(Rect(0,0,16,16), GREY8);
123 swimg1 = allocmemimage(Rect(0,0,16,16), GREY1);
124 if(swback == nil || swmask == nil || swmask1 == nil || swimg == nil || swimg1 == nil){
125 print("software cursor: allocmemimage fails\n");
128 memfillcolor(swback, DTransparent);
129 memfillcolor(swmask, DOpaque);
130 memfillcolor(swmask1, DOpaque);
131 memfillcolor(swimg, DBlack);
132 memfillcolor(swimg1, DBlack);