update
[AROS.git] / test / obtainpentest.c
blobf68ae5a6a7d72bcc3136ac7af1111bd7739dc59f
1 #include <proto/graphics.h>
2 #include <proto/exec.h>
3 #include <intuition/intuitionbase.h>
4 #include <intuition/screens.h>
5 #include <graphics/view.h>
7 #include <stdio.h>
9 int main(void)
11 struct IntuitionBase * IntuitionBase;
12 struct Library * GfxBase;
13 struct ViewPort * vp;
14 struct ColorMap * cm;
15 #define NUMCOLORS 32
16 ULONG n[2*NUMCOLORS];
17 ULONG i;
19 IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
20 GfxBase = OpenLibrary("graphics.library",0);
22 cm = GetColorMap(NUMCOLORS);
24 vp = &IntuitionBase->ActiveScreen->ViewPort;
26 AttachPalExtra(cm,vp);
28 n[0] = ObtainPen(cm,
29 -1,
30 0xa0000000,
31 0xb0000000,
32 0xc0000000,
33 0);
35 printf("Got pen number %ld.\n",(long)n[0]);
37 printf("Trying to obtain the same pen as shared.\n");
38 n[1] = ObtainPen(cm,
39 -1,
40 0xa0000000,
41 0xb0000000,
42 0xc0000000,
43 0);
45 printf("Got pen number %ld (=%ld!).\n",(long)n[1],(long)n[0]);
47 printf("Trying to obtain a pen as exclusive.\n");
48 n[2] = ObtainPen(cm,
49 -1,
50 0xa0000000,
51 0xb0000000,
52 0xc0000000,
53 PENF_EXCLUSIVE);
55 printf("Got pen number %ld.\n",(long)n[2]);
57 printf("Trying to allocate pen %ld as exclusive again.\n",(long)n[2]);
58 n[3] = ObtainPen(cm,
59 n[2],
60 0xa0000000,
61 0xb0000000,
62 0xc0000000,
63 PENF_EXCLUSIVE);
65 printf("Got pen number %ld.\n",(long)n[3]);
67 printf("Trying to allocate pen %ld as shared.\n",(long)n[2]);
68 n[4] = ObtainPen(cm,
69 n[2],
70 0xa0000000,
71 0xb0000000,
72 0xc0000000,
73 0);
75 printf("Got pen number %ld.\n",(long)n[4]);
77 printf("Releasing all pens.\n");
78 ReleasePen(cm, n[4]);
79 ReleasePen(cm, n[3]);
80 ReleasePen(cm, n[2]);
81 ReleasePen(cm, n[1]);
82 ReleasePen(cm, n[0]);
84 printf("Obtaining a shared pen.\n");
85 n[0] = ObtainPen(cm,
86 -1,
87 0xa0000000,
88 0xb0000000,
89 0xc0000000,
90 0);
92 printf("Got pen number %ld.\n",(long)n[0]);
94 ReleasePen(cm, n[0]);
96 printf("---------------------------\n");
98 printf("Trying to allocate %d shared pens\n",NUMCOLORS);
99 i = 0;
100 while (i < NUMCOLORS)
102 n[i] = ObtainPen(cm, -1, i << 28, i << 24, i << 20,0);
104 printf("Got pen %ld\n",(long)n[i]);
105 i++;
108 printf("Trying to get %d exclusive pens (no pen was released)\n",NUMCOLORS);
109 i = 0;
110 while (i < NUMCOLORS)
112 n[i+NUMCOLORS] = ObtainPen(cm, -1, 0,0,0,PENF_EXCLUSIVE);
114 printf("Got pen %ld (=-1)\n",(long)n[i+NUMCOLORS]);
115 i++;
118 printf("Releasing all pens!\n");
119 i = 0;
120 while (i < 2 * NUMCOLORS)
122 ReleasePen(cm, n[i]);
123 i++;
126 printf("---------------------------\n");
129 printf("Trying to get %d exclusive pens\n",NUMCOLORS);
130 i = 0;
131 while (i < NUMCOLORS)
133 n[i] = ObtainPen(cm, -1, 0,0,0,PENF_EXCLUSIVE);
135 printf("Got pen %ld\n",(long)n[i]);
136 i++;
139 printf("Trying to allocate %d shared pens (no pen was released)\n",NUMCOLORS);
140 i = 0;
141 while (i < NUMCOLORS)
143 n[i+NUMCOLORS] = ObtainPen(cm, -1, 0,0,0,0);
145 printf("Got pen %ld (=-1)\n",(long)n[i+NUMCOLORS]);
146 i++;
149 printf("Releasing all pens!\n");
150 i = 0;
151 while (i < 2*NUMCOLORS)
153 ReleasePen(cm, n[i]);
154 i++;
157 printf("---------------------------\n");
159 printf("Trying to allocate %d shared pens at certain indices\n",NUMCOLORS);
160 i = 0;
161 while (i < NUMCOLORS)
163 n[i] = ObtainPen(cm, i, 0, 0, 0,0);
165 printf("Got pen %ld\n",(long)n[i]);
166 i++;
169 printf("Trying to get %d exclusive pens (no pen was released)\n",NUMCOLORS);
170 i = 0;
171 while (i < NUMCOLORS)
173 n[i+NUMCOLORS] = ObtainPen(cm, -1, 0,0,0,PENF_EXCLUSIVE);
175 printf("Got pen %ld (=-1)\n",(long)n[i+NUMCOLORS]);
176 i++;
179 printf("Releasing all pens!\n");
180 i = 0;
181 while (i < 2 * NUMCOLORS)
183 ReleasePen(cm, n[i]);
184 i++;
187 printf("---------------------------\n");
189 printf("Trying to get %d exclusive pens at certain indices\n",NUMCOLORS);
190 i = 0;
191 while (i < NUMCOLORS)
193 n[i] = ObtainPen(cm, i, 0,0,0,PENF_EXCLUSIVE);
195 printf("Got pen %ld\n",(long)n[i]);
196 i++;
199 printf("Trying to allocate %d shared pens (bo pen was released)\n",NUMCOLORS);
200 i = 0;
201 while (i < NUMCOLORS)
203 n[i+NUMCOLORS] = ObtainPen(cm, -1, 0,0,0,0);
205 printf("Got pen %ld (=-1)\n",(long)n[i+NUMCOLORS]);
206 i++;
209 printf("Releasing all pens!\n");
210 i = 0;
211 while (i < 2*NUMCOLORS)
213 ReleasePen(cm, n[i]);
214 i++;
217 printf("---------------------------\n");
219 FreeColorMap(cm);
221 return 0;