~ubuntu-branches/ubuntu/wily/pacman/wily

« back to all changes in this revision

Viewing changes to colour.cc

  • Committer: Bazaar Package Importer
  • Author(s): Peter Joseph
  • Date: 2001-07-16 00:40:44 UTC
  • Revision ID: james.westby@ubuntu.com-20010716004044-oezvmjnpidekt21n
Tags: upstream-10
ImportĀ upstreamĀ versionĀ 10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include<stdio.h>
 
2
#include"colour.h"
 
3
#include<stdlib.h>
 
4
#include<string.h>
 
5
#include"arg.h"
 
6
#include"pac.h"
 
7
               
 
8
COLOURTYPE Colour::MYFOREGROUND=0; //initializers 
 
9
COLOURTYPE Colour::MYBACKGROUND=0; 
 
10
COLOURTYPE Colour::WALLCOLOUR=0; 
 
11
COLOURTYPE Colour::PACMANCOLOUR=0;
 
12
COLOURTYPE Colour::GHOSTCOLOUR1=0;
 
13
COLOURTYPE Colour::GHOSTCOLOUR2=0;
 
14
COLOURTYPE Colour::GHOSTCOLOUR3=0;
 
15
COLOURTYPE Colour::GHOSTCOLOUR4=0;
 
16
COLOURTYPE Colour::RUNGHOSTCOLOUR=0; 
 
17
COLOURTYPE Colour::FOODCOLOUR=0;
 
18
COLOURTYPE Colour::SUPERFOODCOLOUR=0; 
 
19
COLOURTYPE Colour::BONUSPOINTCOLOUR=0; 
 
20
COLOURTYPE Colour::BONUSLIFECOLOUR=0;
 
21
                 
 
22
//plain colour names
 
23
static COLOURNAME black,white,cyan,lightblue,yellow,red,violetred,violet,orangered,deepskyblue,gold,lightyellow,grey,lightgrey,dimgrey,slategrey,darkslategrey,lightslategrey;
 
24
 
 
25
Colour::Colour(UserInterface* u) {      //constructor
 
26
static int starts=0;                    //to make sure only one construction
 
27
 
 
28
#ifdef XWIN                             //X-Win only
 
29
Window window;                          //our window
 
30
int screen;                             //our screen
 
31
#endif
 
32
           
 
33
if (starts) {                           //make sure it is initialized just once
 
34
 pacwarning("Colour is just initialized once\n");
 
35
 return;
 
36
}
 
37
starts=1;                               //to make sure only one construction
 
38
 
 
39
#ifdef XWIN
 
40
display=u->getdisplay();                //get pointer to display connection
 
41
screen=u->getscreen();                  //get the screen
 
42
 
 
43
Visual *vis=DefaultVisual(display,screen);      //get the visual type class
 
44
 
 
45
int colour=0;                           //colour?
 
46
 
 
47
//if it is not grayish then it is colour (only maybe)
 
48
if (Argument::argc==1 && vis->c_class!=GrayScale && vis->c_class!=StaticGray) colour=1;
 
49
 
 
50
//the following picks the first argument matching grey or colour
 
51
//in none given, no colour is assumed
 
52
if (Argument::argc>1) {                 //if there are arguments
 
53
 char** temp=Argument::args;            //initial pointer to strings
 
54
 char* s;                               //argument string
 
55
 while(s=*temp) {                       //while there is still an argument left
 
56
  if (!strcmp(s,"grey"))                //if argument is grey then no colours
 
57
   {colour=0; break; }
 
58
  if (!strcmp(s,"colour"))              //if argument is colour then colours
 
59
   {colour=1; break; }
 
60
  temp++;                               //increment to next string
 
61
 }
 
62
}    
 
63
 
 
64
if (colour) {                           //if colour chosen
 
65
 
 
66
cmap=DefaultColormap(display,DefaultScreen(display));   //get colourmap
 
67
 
 
68
//the colour initializing is almost straightforward, you set the RGB
 
69
//mark flags according to what attribute members were set
 
70
//then you allocate the colour, which you get with ?????.pixel
 
71
cyan.red=0; 
 
72
cyan.green=65535; 
 
73
cyan.blue=65535;
 
74
cyan.flags=DoRed|DoGreen|DoBlue;
 
75
if(XAllocColor(display,cmap,&cyan)==0) pacexit("Colour initialization error");
 
76
 
 
77
black.red=0;
 
78
black.green=0;
 
79
black.blue=0;
 
80
black.flags=DoRed|DoGreen|DoBlue;
 
81
if(XAllocColor(display,cmap,&black)==0) pacexit("Colour initialization error");
 
82
 
 
83
white.red=65535;
 
84
white.green=65535;
 
85
white.blue=65535;
 
86
white.flags=DoRed|DoGreen|DoBlue;
 
87
if(XAllocColor(display,cmap,&white)==0) pacexit("Colour initialization error");
 
88
 
 
89
lightblue.red=173*256; 
 
90
lightblue.green=216*256; 
 
91
lightblue.blue=230*256;
 
92
lightblue.flags=DoRed|DoGreen|DoBlue;
 
93
if(XAllocColor(display,cmap,&lightblue)==0) pacexit("Colour initialization error");
 
94
 
 
95
yellow.red=65535; 
 
96
yellow.green=65535; 
 
97
yellow.blue=0;
 
98
yellow.flags=DoRed|DoGreen|DoBlue;
 
99
if(XAllocColor(display,cmap,&yellow)==0) pacexit("Colour initialization error");
 
100
 
 
101
red.red=65535;
 
102
red.green=0;
 
103
red.blue=0;
 
104
red.flags=DoRed|DoGreen|DoBlue;
 
105
if(XAllocColor(display,cmap,&red)==0) pacexit("Colour initialization error");
 
106
 
 
107
orangered.red=65535;
 
108
orangered.green=69*256;
 
109
orangered.blue=0;
 
110
orangered.flags=DoRed|DoGreen|DoBlue;
 
111
if(XAllocColor(display,cmap,&orangered)==0) pacexit("Colour initialization error");
 
112
 
 
113
violetred.red=208*256;
 
114
violetred.green=32*256;
 
115
violetred.blue=144*256;
 
116
violetred.flags=DoRed|DoGreen|DoBlue;
 
117
if(XAllocColor(display,cmap,&violetred)==0) pacexit("Colour initialization error");
 
118
 
 
119
violet.red=238*256;
 
120
violet.green=130*256;
 
121
violet.blue=238*256;
 
122
violet.flags=DoRed|DoGreen|DoBlue;
 
123
if(XAllocColor(display,cmap,&violet)==0) pacexit("Colour initialization error");
 
124
 
 
125
deepskyblue.red=0;
 
126
deepskyblue.green=192*256-1;
 
127
deepskyblue.blue=65535;
 
128
deepskyblue.flags=DoRed|DoGreen|DoBlue;
 
129
if(XAllocColor(display,cmap,&deepskyblue)==0) pacexit("Colour initialization error");
 
130
 
 
131
gold.red=65535;
 
132
gold.green=216*256-1;
 
133
gold.blue=0;
 
134
gold.flags=DoRed|DoGreen|DoBlue;
 
135
if(XAllocColor(display,cmap,&gold)==0) pacexit("Colour initialization error");
 
136
 
 
137
lightyellow.red=65535; 
 
138
lightyellow.green=65535; 
 
139
lightyellow.blue=0;
 
140
lightyellow.flags=DoRed|DoGreen|DoBlue;
 
141
if(XAllocColor(display,cmap,&lightyellow)==0) pacexit("Colour initialization error");
 
142
  
 
143
 MYFOREGROUND =cyan.pixel;
 
144
 MYBACKGROUND =black.pixel;
 
145
 WALLCOLOUR =deepskyblue.pixel;
 
146
 PACMANCOLOUR =yellow.pixel;
 
147
 GHOSTCOLOUR1 =red.pixel;
 
148
 GHOSTCOLOUR2 =violetred.pixel;
 
149
 GHOSTCOLOUR3 =violet.pixel;
 
150
 GHOSTCOLOUR4 =orangered.pixel;
 
151
 RUNGHOSTCOLOUR =lightblue.pixel;
 
152
 FOODCOLOUR =lightyellow.pixel;
 
153
 SUPERFOODCOLOUR =gold.pixel;
 
154
 BONUSPOINTCOLOUR =gold.pixel;
 
155
 BONUSLIFECOLOUR =gold.pixel;
 
156
/*
 
157
#define MYFOREGROUND cyan.pixel
 
158
#define MYBACKGROUND black.pixel
 
159
#define WALLCOLOUR deepskyblue.pixel
 
160
#define PACMANCOLOUR yellow.pixel
 
161
#define GHOSTCOLOUR1 red.pixel
 
162
#define GHOSTCOLOUR2 violetred.pixel
 
163
#define GHOSTCOLOUR3 violet.pixel
 
164
#define GHOSTCOLOUR4 orangered.pixel
 
165
#define RUNGHOSTCOLOUR lightblue.pixel
 
166
#define FOODCOLOUR lightyellow.pixel
 
167
#define SUPERFOODCOLOUR gold.pixel
 
168
#define BONUSPOINTCOLOUR gold.pixel
 
169
#define BONUSLIFECOLOUR gold.pixel
 
170
*/
 
171
} else {                                        //if no colours chosen
 
172
cmap=DefaultColormap(display,DefaultScreen(display));
 
173
 
 
174
grey.red=192*256;
 
175
grey.green=192*256;
 
176
grey.blue=192*256;
 
177
grey.flags=DoRed|DoGreen|DoBlue;
 
178
if(XAllocColor(display,cmap,&grey)==0) pacexit("Colour initialization error");
 
179
 
 
180
dimgrey.red=105*256;
 
181
dimgrey.green=105*256;
 
182
dimgrey.blue=105*256;
 
183
dimgrey.flags=DoRed|DoGreen|DoBlue;
 
184
if(XAllocColor(display,cmap,&dimgrey)==0) pacexit("Colour initialization error");
 
185
 
 
186
lightgrey.red=211*256;
 
187
lightgrey.green=211*256;
 
188
lightgrey.blue=211*256;
 
189
lightgrey.flags=DoRed|DoGreen|DoBlue;
 
190
if(XAllocColor(display,cmap,&lightgrey)==0) pacexit("Colour initialization error");
 
191
 
 
192
lightslategrey.red=119*256;
 
193
lightslategrey.green=136*256;
 
194
lightslategrey.blue=153*256;
 
195
lightslategrey.flags=DoRed|DoGreen|DoBlue;
 
196
if(XAllocColor(display,cmap,&lightslategrey)==0) pacexit("Colour initialization error");
 
197
 
 
198
slategrey.red=112*256;
 
199
slategrey.green=128*256;
 
200
slategrey.blue=144*256;
 
201
slategrey.flags=DoRed|DoGreen|DoBlue;
 
202
if(XAllocColor(display,cmap,&slategrey)==0) pacexit("Colour initialization error");
 
203
 
 
204
darkslategrey.red=47*256;
 
205
darkslategrey.green=79*256;
 
206
darkslategrey.blue=79*256;
 
207
darkslategrey.flags=DoRed|DoGreen|DoBlue;
 
208
if(XAllocColor(display,cmap,&darkslategrey)==0) pacexit("Colour initialization error");
 
209
  
 
210
 MYFOREGROUND =WhitePixel(display,screen);
 
211
 MYBACKGROUND =BlackPixel(display,screen);
 
212
 WALLCOLOUR =darkslategrey.pixel;
 
213
 PACMANCOLOUR =WhitePixel(display,screen);
 
214
 GHOSTCOLOUR1 =slategrey.pixel;
 
215
 GHOSTCOLOUR2 =slategrey.pixel;
 
216
 GHOSTCOLOUR3 =slategrey.pixel;
 
217
 GHOSTCOLOUR4 =slategrey.pixel;
 
218
 RUNGHOSTCOLOUR =lightgrey.pixel;
 
219
 FOODCOLOUR =lightgrey.pixel;
 
220
 SUPERFOODCOLOUR =grey.pixel;
 
221
 BONUSPOINTCOLOUR =dimgrey.pixel;
 
222
 BONUSLIFECOLOUR =WhitePixel(display,screen);
 
223
/*  
 
224
#define MYFOREGROUND WhitePixel(display,screen)
 
225
#define MYBACKGROUND BlackPixel(display,screen)
 
226
#define WALLCOLOUR darkslategrey.pixel
 
227
#define PACMANCOLOUR WhitePixel(display,screen)
 
228
#define GHOSTCOLOUR1 slategrey.pixel
 
229
#define GHOSTCOLOUR2 slategrey.pixel
 
230
#define GHOSTCOLOUR3 slategrey.pixel
 
231
#define GHOSTCOLOUR4 slategrey.pixel
 
232
#define RUNGHOSTCOLOUR =lightgrey.pixel
 
233
#define FOODCOLOUR lightgrey.pixel
 
234
#define SUPERFOODCOLOUR grey.pixel
 
235
#define BONUSPOINTCOLOUR dimgrey.pixel
 
236
#define BONUSLIFECOLOUR WhitePixel(display,screen)
 
237
  */
 
238
}
 
239
/*
 
240
.red=;
 
241
.green=;
 
242
.blue=;
 
243
.flags=DoRed|DoGreen|DoBlue;
 
244
if(XAllocColor(display,cmap,&)==0) pacexit("Colour initialization error");
 
245
*/
 
246
    
 
247
#elif defined MSWIN                             //MS-Win only        
 
248
 
 
249
cyan=(RGB(0,255,255));
 
250
black=(RGB(0,0,0));
 
251
white=(RGB(255,255,255));
 
252
lightblue=(RGB(173,216,230));
 
253
yellow=(RGB(255,255,0));
 
254
red=(RGB(255,0,0));
 
255
orangered=(RGB(255,69,0));
 
256
violetred=(RGB(208,32,144));
 
257
violet=(RGB(238,130,238));
 
258
deepskyblue=(RGB(0,191,255));
 
259
gold=(RGB(255,215,0));
 
260
lightyellow=(RGB(255,255,0));
 
261
 
 
262
 MYFOREGROUND =cyan;
 
263
 MYBACKGROUND =black;
 
264
 WALLCOLOUR =deepskyblue;
 
265
 PACMANCOLOUR =yellow;
 
266
 GHOSTCOLOUR1 =red;
 
267
 GHOSTCOLOUR2 =violetred;
 
268
 GHOSTCOLOUR3 =violet;
 
269
 GHOSTCOLOUR4 =orangered;
 
270
 RUNGHOSTCOLOUR =lightblue;
 
271
 FOODCOLOUR =lightyellow;
 
272
 SUPERFOODCOLOUR =gold;
 
273
 BONUSPOINTCOLOUR =gold;
 
274
 BONUSLIFECOLOUR =gold;
 
275
 
 
276
  /*
 
277
#define MYFOREGROUND RGB(0,255,255)
 
278
#define MYBACKGROUND RGB(0,0,0)
 
279
#define WALLCOLOUR RGB(0,191,255)
 
280
#define PACMANCOLOUR RGB(255,255,0)
 
281
#define GHOSTCOLOUR1 RGB(255,0,0)
 
282
#define GHOSTCOLOUR2 RGB(208,32,144)
 
283
#define GHOSTCOLOUR3 RGB(238,130,238)
 
284
#define GHOSTCOLOUR4 RGB(255,69,0)
 
285
#define RUNGHOSTCOLOUR RGB(173,216,230)
 
286
#define FOODCOLOUR RGB(255,255,0)
 
287
#define SUPERFOODCOLOUR RGB(255,215,0)
 
288
#define BONUSPOINTCOLOUR RGB(255,215,0)
 
289
#define BONUSLIFECOLOUR RGB(255,215,0)
 
290
*/
 
291
#endif
 
292
}
 
293
 
 
294
Colour::~Colour() {
 
295
#ifdef XWIN                     //X-Win only
 
296
XFreeColormap(display,cmap);    //free the colourmap
 
297
 
 
298
#elif defined MSWIN             //MS-Win only
 
299
 
 
300
/*
 
301
DeleteObject(cyan);
 
302
DeleteObject(black);
 
303
DeleteObject(white);
 
304
DeleteObject(lightblue);
 
305
DeleteObject(yellow);
 
306
DeleteObject(lightyellow);
 
307
DeleteObject(red);
 
308
DeleteObject(orangered);
 
309
DeleteObject(violetred);
 
310
DeleteObject(violet);
 
311
DeleteObject(deepskyblue);
 
312
DeleteObject(gold);     
 
313
*/     
 
314
#endif
 
315
}
 
316