File: colour.cc

package info (click to toggle)
pacman 10-13
  • links: PTS
  • area: main
  • in suites: woody
  • size: 664 kB
  • ctags: 1,108
  • sloc: cpp: 3,333; makefile: 502; sh: 96
file content (316 lines) | stat: -rw-r--r-- 9,398 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include<stdio.h>
#include"colour.h"
#include<stdlib.h>
#include<string.h>
#include"arg.h"
#include"pac.h"
               
COLOURTYPE Colour::MYFOREGROUND=0; //initializers 
COLOURTYPE Colour::MYBACKGROUND=0; 
COLOURTYPE Colour::WALLCOLOUR=0; 
COLOURTYPE Colour::PACMANCOLOUR=0;
COLOURTYPE Colour::GHOSTCOLOUR1=0;
COLOURTYPE Colour::GHOSTCOLOUR2=0;
COLOURTYPE Colour::GHOSTCOLOUR3=0;
COLOURTYPE Colour::GHOSTCOLOUR4=0;
COLOURTYPE Colour::RUNGHOSTCOLOUR=0; 
COLOURTYPE Colour::FOODCOLOUR=0;
COLOURTYPE Colour::SUPERFOODCOLOUR=0; 
COLOURTYPE Colour::BONUSPOINTCOLOUR=0; 
COLOURTYPE Colour::BONUSLIFECOLOUR=0;
                 
//plain colour names
static COLOURNAME black,white,cyan,lightblue,yellow,red,violetred,violet,orangered,deepskyblue,gold,lightyellow,grey,lightgrey,dimgrey,slategrey,darkslategrey,lightslategrey;

Colour::Colour(UserInterface* u) {	//constructor
static int starts=0;			//to make sure only one construction

#ifdef XWIN				//X-Win only
Window window;				//our window
int screen; 				//our screen
#endif
           
if (starts) { 				//make sure it is initialized just once
 pacwarning("Colour is just initialized once\n");
 return;
}
starts=1;				//to make sure only one construction

#ifdef XWIN
display=u->getdisplay();		//get pointer to display connection
screen=u->getscreen();			//get the screen

Visual *vis=DefaultVisual(display,screen);	//get the visual type class

int colour=0;				//colour?

//if it is not grayish then it is colour (only maybe)
if (Argument::argc==1 && vis->c_class!=GrayScale && vis->c_class!=StaticGray) colour=1;

//the following picks the first argument matching grey or colour
//in none given, no colour is assumed
if (Argument::argc>1) {			//if there are arguments
 char** temp=Argument::args;		//initial pointer to strings
 char* s;				//argument string
 while(s=*temp) {			//while there is still an argument left
  if (!strcmp(s,"grey")) 		//if argument is grey then no colours
   {colour=0; break; }
  if (!strcmp(s,"colour")) 		//if argument is colour then colours
   {colour=1; break; }
  temp++;				//increment to next string
 }
}    

if (colour) {				//if colour chosen

cmap=DefaultColormap(display,DefaultScreen(display));	//get colourmap

//the colour initializing is almost straightforward, you set the RGB
//mark flags according to what attribute members were set
//then you allocate the colour, which you get with ?????.pixel
cyan.red=0; 
cyan.green=65535; 
cyan.blue=65535;
cyan.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&cyan)==0) pacexit("Colour initialization error");

black.red=0;
black.green=0;
black.blue=0;
black.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&black)==0) pacexit("Colour initialization error");

white.red=65535;
white.green=65535;
white.blue=65535;
white.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&white)==0) pacexit("Colour initialization error");

lightblue.red=173*256; 
lightblue.green=216*256; 
lightblue.blue=230*256;
lightblue.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&lightblue)==0) pacexit("Colour initialization error");

yellow.red=65535; 
yellow.green=65535; 
yellow.blue=0;
yellow.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&yellow)==0) pacexit("Colour initialization error");

red.red=65535;
red.green=0;
red.blue=0;
red.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&red)==0) pacexit("Colour initialization error");

orangered.red=65535;
orangered.green=69*256;
orangered.blue=0;
orangered.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&orangered)==0) pacexit("Colour initialization error");

violetred.red=208*256;
violetred.green=32*256;
violetred.blue=144*256;
violetred.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&violetred)==0) pacexit("Colour initialization error");

violet.red=238*256;
violet.green=130*256;
violet.blue=238*256;
violet.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&violet)==0) pacexit("Colour initialization error");

deepskyblue.red=0;
deepskyblue.green=192*256-1;
deepskyblue.blue=65535;
deepskyblue.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&deepskyblue)==0) pacexit("Colour initialization error");

gold.red=65535;
gold.green=216*256-1;
gold.blue=0;
gold.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&gold)==0) pacexit("Colour initialization error");

lightyellow.red=65535; 
lightyellow.green=65535; 
lightyellow.blue=0;
lightyellow.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&lightyellow)==0) pacexit("Colour initialization error");
  
 MYFOREGROUND =cyan.pixel;
 MYBACKGROUND =black.pixel;
 WALLCOLOUR =deepskyblue.pixel;
 PACMANCOLOUR =yellow.pixel;
 GHOSTCOLOUR1 =red.pixel;
 GHOSTCOLOUR2 =violetred.pixel;
 GHOSTCOLOUR3 =violet.pixel;
 GHOSTCOLOUR4 =orangered.pixel;
 RUNGHOSTCOLOUR =lightblue.pixel;
 FOODCOLOUR =lightyellow.pixel;
 SUPERFOODCOLOUR =gold.pixel;
 BONUSPOINTCOLOUR =gold.pixel;
 BONUSLIFECOLOUR =gold.pixel;
/*
#define MYFOREGROUND cyan.pixel
#define MYBACKGROUND black.pixel
#define WALLCOLOUR deepskyblue.pixel
#define PACMANCOLOUR yellow.pixel
#define GHOSTCOLOUR1 red.pixel
#define GHOSTCOLOUR2 violetred.pixel
#define GHOSTCOLOUR3 violet.pixel
#define GHOSTCOLOUR4 orangered.pixel
#define RUNGHOSTCOLOUR lightblue.pixel
#define FOODCOLOUR lightyellow.pixel
#define SUPERFOODCOLOUR gold.pixel
#define BONUSPOINTCOLOUR gold.pixel
#define BONUSLIFECOLOUR gold.pixel
*/
} else {					//if no colours chosen
cmap=DefaultColormap(display,DefaultScreen(display));

grey.red=192*256;
grey.green=192*256;
grey.blue=192*256;
grey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&grey)==0) pacexit("Colour initialization error");

dimgrey.red=105*256;
dimgrey.green=105*256;
dimgrey.blue=105*256;
dimgrey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&dimgrey)==0) pacexit("Colour initialization error");

lightgrey.red=211*256;
lightgrey.green=211*256;
lightgrey.blue=211*256;
lightgrey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&lightgrey)==0) pacexit("Colour initialization error");

lightslategrey.red=119*256;
lightslategrey.green=136*256;
lightslategrey.blue=153*256;
lightslategrey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&lightslategrey)==0) pacexit("Colour initialization error");

slategrey.red=112*256;
slategrey.green=128*256;
slategrey.blue=144*256;
slategrey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&slategrey)==0) pacexit("Colour initialization error");

darkslategrey.red=47*256;
darkslategrey.green=79*256;
darkslategrey.blue=79*256;
darkslategrey.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&darkslategrey)==0) pacexit("Colour initialization error");
  
 MYFOREGROUND =WhitePixel(display,screen);
 MYBACKGROUND =BlackPixel(display,screen);
 WALLCOLOUR =darkslategrey.pixel;
 PACMANCOLOUR =WhitePixel(display,screen);
 GHOSTCOLOUR1 =slategrey.pixel;
 GHOSTCOLOUR2 =slategrey.pixel;
 GHOSTCOLOUR3 =slategrey.pixel;
 GHOSTCOLOUR4 =slategrey.pixel;
 RUNGHOSTCOLOUR =lightgrey.pixel;
 FOODCOLOUR =lightgrey.pixel;
 SUPERFOODCOLOUR =grey.pixel;
 BONUSPOINTCOLOUR =dimgrey.pixel;
 BONUSLIFECOLOUR =WhitePixel(display,screen);
/*  
#define MYFOREGROUND WhitePixel(display,screen)
#define MYBACKGROUND BlackPixel(display,screen)
#define WALLCOLOUR darkslategrey.pixel
#define PACMANCOLOUR WhitePixel(display,screen)
#define GHOSTCOLOUR1 slategrey.pixel
#define GHOSTCOLOUR2 slategrey.pixel
#define GHOSTCOLOUR3 slategrey.pixel
#define GHOSTCOLOUR4 slategrey.pixel
#define RUNGHOSTCOLOUR =lightgrey.pixel
#define FOODCOLOUR lightgrey.pixel
#define SUPERFOODCOLOUR grey.pixel
#define BONUSPOINTCOLOUR dimgrey.pixel
#define BONUSLIFECOLOUR WhitePixel(display,screen)
  */
}
/*
.red=;
.green=;
.blue=;
.flags=DoRed|DoGreen|DoBlue;
if(XAllocColor(display,cmap,&)==0) pacexit("Colour initialization error");
*/
    
#elif defined MSWIN				//MS-Win only        

cyan=(RGB(0,255,255));
black=(RGB(0,0,0));
white=(RGB(255,255,255));
lightblue=(RGB(173,216,230));
yellow=(RGB(255,255,0));
red=(RGB(255,0,0));
orangered=(RGB(255,69,0));
violetred=(RGB(208,32,144));
violet=(RGB(238,130,238));
deepskyblue=(RGB(0,191,255));
gold=(RGB(255,215,0));
lightyellow=(RGB(255,255,0));

 MYFOREGROUND =cyan;
 MYBACKGROUND =black;
 WALLCOLOUR =deepskyblue;
 PACMANCOLOUR =yellow;
 GHOSTCOLOUR1 =red;
 GHOSTCOLOUR2 =violetred;
 GHOSTCOLOUR3 =violet;
 GHOSTCOLOUR4 =orangered;
 RUNGHOSTCOLOUR =lightblue;
 FOODCOLOUR =lightyellow;
 SUPERFOODCOLOUR =gold;
 BONUSPOINTCOLOUR =gold;
 BONUSLIFECOLOUR =gold;

  /*
#define MYFOREGROUND RGB(0,255,255)
#define MYBACKGROUND RGB(0,0,0)
#define WALLCOLOUR RGB(0,191,255)
#define PACMANCOLOUR RGB(255,255,0)
#define GHOSTCOLOUR1 RGB(255,0,0)
#define GHOSTCOLOUR2 RGB(208,32,144)
#define GHOSTCOLOUR3 RGB(238,130,238)
#define GHOSTCOLOUR4 RGB(255,69,0)
#define RUNGHOSTCOLOUR RGB(173,216,230)
#define FOODCOLOUR RGB(255,255,0)
#define SUPERFOODCOLOUR RGB(255,215,0)
#define BONUSPOINTCOLOUR RGB(255,215,0)
#define BONUSLIFECOLOUR RGB(255,215,0)
*/
#endif
}

Colour::~Colour() {
#ifdef XWIN			//X-Win only
XFreeColormap(display,cmap);	//free the colourmap

#elif defined MSWIN		//MS-Win only

/*
DeleteObject(cyan);
DeleteObject(black);
DeleteObject(white);
DeleteObject(lightblue);
DeleteObject(yellow);
DeleteObject(lightyellow);
DeleteObject(red);
DeleteObject(orangered);
DeleteObject(violetred);
DeleteObject(violet);
DeleteObject(deepskyblue);
DeleteObject(gold);     
*/     
#endif
}