home *** CD-ROM | disk | FTP | other *** search
-
- /************************************************************************/
- /* Display black and white sprite and move it using arrow keys */
- /************************************************************************/
-
- demo_cursor()
- {
- #define MAX_X (640 - 16)
- #define MAX_Y (350 - 16)
-
- #define KEY_ESC 0x011B
- #define KEY_UP 0x4800
- #define KEY_DOWN 0x5000
- #define KEY_LEFT 0x4B00
- #define KEY_RIGHT 0x4D00
- #define KEY_ENTER 0x1C0D
-
- static char and_mask[] = {
- 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x1F,0xF8,
- 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8,
- 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8, 0x1F,0xF8,
- 0x1F,0xF8, 0x00,0x00, 0x00,0x00, 0x00,0x00};
- static char xor_mask[] = {
- 0xFF,0xFF, 0x80,0x01, 0xBF,0xFD, 0xA0,0x05,
- 0xA0,0x05, 0xA0,0x05, 0xA0,0x05, 0xA0,0x05,
- 0xA0,0x05, 0xA0,0x05, 0xA0,0x05, 0xA0,0x05,
- 0xA0,0x05, 0xBF,0xFD, 0x80,0x01, 0xFF,0xFF};
- int key, x, y, i;
-
- /* Draw a background pattern and a solid white box */
-
- clear_screen();
- for (i = 0; i < 640; i += 20) line(320,100,i, 0,i/20);
- for (i = 0; i < 640; i += 20) line(320,100,i,199,i/20);
- for (i = 0; i < 200; i += 10) line(320,100,0, i,i/10);
- for (i = 0; i < 200; i += 10) line(320,100,639,i,i/10);
- solid_box(320,100,150,150,15);
-
- /* Set cursor shape and color, and display the first cursor */
-
- set_cursor(and_mask, xor_mask, 0, 15);
- x = 320; /* initial position of cursor */
- y = 100;
- move_cursor(x,y); /* show cursor at initial pos */
-
- /* Loop while keys are pressed */
-
- do
- {
- switch (key = get_key())/* Move cursor according to key */
- {
- case KEY_ESC:
- case KEY_ENTER:
- remove_cursor();
- break;
- case KEY_UP:
- y = (y -1) > 0 ? --y : 0;
- move_cursor(x, y);
- break;
- case KEY_DOWN:
- y = (y + 1) < MAX_Y ? ++y : MAX_Y;
- move_cursor(x, y);
- break;
- case KEY_RIGHT:
- x = (x + 1) < MAX_X ? ++x : MAX_X;
- move_cursor(x, y);
- break;
- case KEY_LEFT:
- x = (x - 1) > 0 ? --x : 0;
- move_cursor(x, y);
- break;
- default:
- break;
- }
- } while (key != KEY_ENTER);
- }
-