1 /**
2  ** curstest.c ---- test cursors
3  **
4  ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
5  ** [e-mail: csaba@vuse.vanderbilt.edu]
6  **
7  ** This is a test/demo file of the GRX graphics library.
8  ** You can use GRX test/demo files as you want.
9  **
10  ** The GRX graphics library is free software; you can redistribute it
11  ** and/or modify it under some conditions; see the "copying.grx" file
12  ** for details.
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17  **
18  **/
19 
20 #include "test.h"
21 
22 char p16d[] = {
23     0,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,
24     1,2,1,0,0,0,0,0,0,0,0,1,2,2,1,0,
25     1,2,2,1,0,0,0,0,0,0,1,2,0,0,2,1,
26     1,2,2,2,1,0,0,0,0,0,1,2,0,0,2,1,
27     1,2,2,2,2,1,0,0,0,0,0,1,2,2,1,0,
28     1,2,2,2,2,2,1,0,0,0,0,0,1,1,0,0,
29     1,2,2,2,2,2,2,1,0,0,0,0,0,0,0,0,
30     1,2,2,2,2,2,2,2,1,0,0,0,0,0,0,0,
31     1,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0,
32     1,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,
33     1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,
34     1,2,2,2,2,1,1,1,1,1,1,0,0,0,0,0,
35     1,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,
36     1,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,
37     1,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,
38     0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39 };
40 
TESTFUNC(cursortest)41 TESTFUNC(cursortest)
42 {
43 	GrColor bgc = GrAllocColor(0,0,128);
44 	GrColor fgc = GrAllocColor(255,255,0);
45 	GrColor msc[3];
46 	GrCursor *cur;
47 	int x,y;
48 
49 	msc[0] = 2;
50 	msc[1] = GrWhite();
51 	msc[2] = GrAllocColor(255,0,0);
52 	cur = GrBuildCursor(p16d,16,16,16,1,1,msc);
53 	x = GrScreenX() / 2;
54 	y = GrScreenY() / 2;
55 	GrMoveCursor(cur,x,y);
56 	GrClearScreen(bgc);
57 	GrSetColor((GrNumColors() - 1),255,255,255);
58 	drawing(0,0,GrSizeX(),GrSizeY(),fgc,GrNOCOLOR);
59 	GrFilledBox(0,0,320,120,GrAllocColor(0,255,255));
60 	GrTextXY( 10,90,"ANDmask",GrBlack(),GrNOCOLOR);
61 	GrTextXY( 90,90,"ORmask", GrBlack(),GrNOCOLOR);
62 	GrTextXY(170,90,"Save",   GrBlack(),GrNOCOLOR);
63 	GrTextXY(250,90,"Work",   GrBlack(),GrNOCOLOR);
64 	GrDisplayCursor(cur);
65 	for( ; ; ) {
66 	    GrBitBlt(
67 		NULL,10,10,
68 		&cur->work,cur->xwork/2,0,cur->xwork/2+cur->xsize-1,cur->ysize-1,
69 		GrWRITE
70 	    );
71 	    GrBitBlt(
72 		NULL,90,10,
73 		&cur->work,0,0,cur->xsize-1,cur->ysize-1,
74 		GrWRITE
75 	    );
76 	    GrBitBlt(
77 		NULL,170,10,
78 		&cur->work,0,cur->ysize,cur->xwork-1,cur->ysize+cur->ywork-1,
79 		GrWRITE
80 	    );
81 	    GrBitBlt(
82 		NULL,250,10,
83 		&cur->work,0,cur->ysize+cur->ywork,cur->xwork-1,cur->ysize+2*cur->ywork-1,
84 		GrWRITE
85 	    );
86 	    GrTextXY(0,GrMaxY()-20,"Type u d l r U D L R or q to quit",GrWhite(),GrNOCOLOR);
87 	    switch(GrKeyRead()) {
88 		case 'u': y--; break;
89 		case 'd': y++; break;
90 		case 'l': x--; break;
91 		case 'r': x++; break;
92 		case 'U': y -= 10; break;
93 		case 'D': y += 10; break;
94 		case 'L': x -= 10; break;
95 		case 'R': x += 10; break;
96 		case 'q': return;
97 		default:  continue;
98 	    }
99 	    if(x < 0) x = 0;
100 	    if(x > GrScreenX()) x = GrScreenX();
101 	    if(y < 100) y = 100;
102 	    if(y > GrScreenY()) y = GrScreenY();
103 	    GrMoveCursor(cur,x,y);
104 	}
105 }
106 
107