Industrial Training




Building Mouse Cursors



Building Mouse Cursors

In text mode the mouse cursor appears as a block, whereas in graphics mode it appears as an arrow. If we wish, we can change the graphics cursor to any other shape the way Windows or Ventura does. The mouse cursor in graphics mode occupies a 16 by 16 pixel box. By highlighting or de-highlighting some of the pixels in this box we can get the desired shape. For example, the following bit-pattern can be used to generate the cursor which looks like an hour-glass.



1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0



The 1's in the mouse pointer bitmap indicate that the pixel would be drawn, whereas the zeros indicate that the pixel would stand erased. It is important to note that the mouse pointer bit pattern is 32 bytes long. However, while actually writing a program to change the pointer shape we need a 64 byte bit-map. This provision is made to ensure that when the cursor reaches a position on the screen where something is already written or drawn, only that portion should get overwritten which is to be occupied by the mouse cursor. Of the 64 bytes, the first 32 bytes contain a bit mask which is first ANDed with the screen image, and then the second 32 bytes bit mask is XORed with the screen image. The following program changes the mouse cursor in graphics mode to resemble an hour glass.



#include "graphics.h"

#include "dos.h"

union REGS i, o ;

struct SREGS s ;

int cursor[32] = {


/* Hour-glass screen mask */

0x0000, 0x0000, 0x0000, 0x0000,

0x8001, 0xc003, 0xf00f, 0xfc3f,

0xfc3f, 0xf00f, 0xc003, 0x8001,

0x0000, 0x0000, 0x0000, 0x0000,


/* The mouse pointer bitmap */

0xffff, 0x8001, 0xffff, 0x8001,

0x4002, 0x2004, 0x1008, 0x0240,

0x0240, 0x0810, 0x2004, 0x4002,

0x8001, 0xffff, 0x8001, 0xffff,

} ;

main( )

{

int gd = DETECT, gm ;

initgraph ( &gd, &gm, "c:\\tc\\bgi" ) ;

if ( initmouse( ) == 0 )

{

closegraph( ) ;

printf ( "\n Mouse not installed!" ) ;

exit ( 1 ) ;

}

gotoxy ( 10, 1 ) ;

printf ( "Press any key to exit..." ) ;

changecursor ( cursor ) ;

showmouseptr( ) ;

getch( ) ;

}

initmouse( )

{

i.x.ax = 0 ;

int86 ( 0x33, &i, &o ) ;

return ( o.x.ax ) ;

}

showmouseptr( )

{

i.x.ax = 1 ;

int86 ( 0x33, &i, &o ) ;

}

changecursor ( int *shape )

{

i.x.ax = 9 ; /* service number */

i.x.bx = 0 ; /* actual cursor position from left */

i.x.cx = 0 ; /* actual cursor position from top */

i.x.dx = ( unsigned ) shape ; /* offset address of pointer image */

segread ( &s ) ;

s.es = s.ds ; /* segment address of pointer */

int86x ( 0x33, &i, &i, &s ) ;

}


Building Mouse Cursors

More Mouse Cursors

In the last program we saw how to change the default mouse cursor. Once we know this we can think of building different shapes of mouse cursors, each to signify a different operation or mode. This is what is done by Ventura to show in which mode are we working currently. The following program shows how this can be managed.


# include "graphics.h"

# include "dos.h"

#include "alloc.h"

union REGS i, o ;

struct SREGS s ;

int c[ ][32] = {


/* Cursor 1. Hand-screen mask + pointer bit map*/

0xe1ff, 0xe1ff, 0xe1ff, 0xe1ff, 0xe1ff, 0x0000,

0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,

0x0000, 0x0000, 0x0000, 0x0000, 0x1e00, 0x1200,

0x1200, 0x1200, 0x13ff, 0x1249, 0x1249, 0xf249,

0x9001, 0x9001, 0x9001, 0x8001, 0x8001, 0x8001,

0xffff, 0x0000,


/* Cursor 2. Arrow-screen mask + pointer bit map*/

0xffff, 0xffff, 0xe003, 0xf003, 0xf803, 0xfc03,

0xfe03, 0xfc03, 0xf803, 0xf043, 0xe0e3, 0xc1f3,

0x83fb, 0x07ff, 0x8fff, 0xdfff, 0x0000, 0x0000,

0x1ffc, 0x0804, 0x0404, 0x0204, 0x0104, 0x0204,

0x0444, 0x08a4, 0x1114, 0x220c, 0x4404, 0x8800,

0x5000, 0x2000,


/* Cursor 3. Hour glass mask + bit map*/

0x0000, 0x0000, 0x0000, 0x0000, 0x8001, 0xc003,

0xf00f, 0xfc3f, 0xfc3f, 0xf00f, 0xc003, 0x8001,

0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0x8001,

0xffff, 0x8001, 0x4002, 0x2004, 0x1008, 0x0240,

0x0240, 0x0810, 0x2004, 0x4002, 0x8001, 0xffff,

0x8001, 0xffff,


/* Cursor 4. Para-screen mask + pointer bit map*/

0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,

0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,

0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,

0xffff, 0x0007, 0x0007, 0xeee7, 0x0007, 0x0007,

0xeee7, 0x0007, 0x0007, 0xeee7, 0x0007, 0x0007,

0xeee7, 0xeee7

} ;



Hi I am Pluto.