File: display.c

package info (click to toggle)
xmille 2.0-13
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, lenny, sid, squeeze, stretch, wheezy
  • size: 1,128 kB
  • ctags: 1,040
  • sloc: ansic: 4,392; makefile: 745
file content (229 lines) | stat: -rw-r--r-- 3,934 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
# include	<X/Xlib.h>
# include	"background.h"
# include	"color.h"

struct color {
	char	*name;
	int	pixel;
};

struct color colorMap[NUM_COLOR] = {
	"black",	0,
	"white",	0,
	"red",		0,
	"green",	0,
	"light gray",	0,
	"blue",		0,
};

struct card_init {
	short	*bits;
	short	*mask;
	int	color;
};

extern short	go_bits[], go_mask_bits[];
extern short	stop_bits[], stop_mask_bits[];
extern short	right_bits[], right_mask_bits[];
extern short	speed_bits[], speed_mask_bits[];
extern short	end_bits[], end_mask_bits[];
extern short	accident_bits[], accident_mask_bits[];
extern short	repairs_bits[], repairs_mask_bits[];
extern short	ace_bits[], ace_mask_bits[];
extern short	flat_bits[], flat_mask_bits[];
extern short	spare_bits[], spare_mask_bits[];
extern short	puncture_bits[], puncture_mask_bits[];
extern short	out_bits[], out_mask_bits[];
extern short	gas_bits[], gas_mask_bits[];
extern short	extra_bits[], extra_mask_bits[];
extern short	miles_mask_bits[];
extern short	_25_bits[], _50_bits[], _75_bits[], _100_bits[], _200_bits[];

struct card_init card_inits[] = {
{
	go_bits,
	go_mask_bits,
	GREEN_COLOR,
},
{
	stop_bits,
	stop_mask_bits,
	RED_COLOR,
},
{
	right_bits,
	right_mask_bits,
	RED_COLOR,
},
{
	speed_bits,
	speed_mask_bits,
	RED_COLOR,
},
{
	end_bits,
	end_mask_bits,
	GREEN_COLOR,
},
{
	accident_bits,
	accident_mask_bits,
	RED_COLOR,
},
{
	repairs_bits,
	repairs_mask_bits,
	GREEN_COLOR,
},
{
	ace_bits,
	ace_mask_bits,
	BLUE_COLOR,
},
{
	flat_bits,
	flat_mask_bits,
	RED_COLOR,
},
{
	spare_bits,
	spare_mask_bits,
	GREEN_COLOR,
},
{
	puncture_bits,
	puncture_mask_bits,
	BLUE_COLOR,
},
{
	out_bits,
	out_mask_bits,
	RED_COLOR,
},
{
	gas_bits,
	gas_mask_bits,
	GREEN_COLOR,
},
{
	extra_bits,
	extra_mask_bits,
	BLUE_COLOR,
},
{
	_25_bits,
	miles_mask_bits,
	BLUE_COLOR,
},
{
	_50_bits,
	miles_mask_bits,
	BLUE_COLOR,
},
{
	_75_bits,
	miles_mask_bits,
	BLUE_COLOR,
},
{
	_100_bits,
	miles_mask_bits,
	BLUE_COLOR,
},
{
	_200_bits,
	miles_mask_bits,
	BLUE_COLOR,
},
};

# define NUM_CARDS	(sizeof (card_inits) / sizeof (card_inits[0]))

struct plane {
	Bitmap	bits;
	int	pixel;
};

struct card {
	int	nPlanes;
	struct plane	planes[5];
};

struct card cards[NUM_CARDS];

Window	w;

# define WINDOW_WIDTH	1000
# define WINDOW_HEIGHT	700

main ()
{
	Color	hardware_color, exact_color;
	XEvent	rep;
	Bitmap	fill;
	Pixmap	background;
	Pixmap	border;
	int	i;

	XOpenDisplay ("");
	for (i = 0; i < NUM_COLOR; i++) {
		XGetColor (colorMap[i].name, &hardware_color, &exact_color);
		colorMap[i].pixel = hardware_color.pixel;
	}
	fill = XStoreBitmap (WIDTH, HEIGHT, fill_bits);
	for (i = 0; i < NUM_CARDS; i++) {
		cards[i].planes[2].bits = XStoreBitmap (WIDTH, HEIGHT, card_inits[i].bits);
		cards[i].planes[2].pixel = colorMap[card_inits[i].color].pixel;
		cards[i].planes[1].bits = XStoreBitmap (WIDTH, HEIGHT, card_inits[i].mask);
		cards[i].planes[1].pixel = colorMap[BLACK_COLOR].pixel;
		cards[i].planes[0].bits = fill;
		cards[i].planes[0].pixel = colorMap[WHITE_COLOR].pixel;
		cards[i].nPlanes = 3;
	}
	background = XMakePixmap (0, colorMap[GREY_COLOR].pixel, colorMap[WHITE_COLOR].pixel);
	border = XMakePixmap (0, colorMap[WHITE_COLOR].pixel, colorMap[GREY_COLOR].pixel);
	w = XCreateWindow (RootWindow, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 1,
		WhitePixmap, background);
	XMapWindow (w);
	XSelectInput (w, ExposeWindow);
	displayAll ();
	for (;;) {
		XNextEvent (&rep);
		switch (rep.type) {
		case ExposeWindow:
			displayAll ();
			break;
		}
	}
}

displayAll ()
{
	struct card	*card;
	int		x, y;
	int		i;

	x = 10;
	y = 10;
	for (i = 0; i < NUM_CARDS; i++) {
		displayOne (&cards[i], x, y);
		x += WIDTH + 20;
		if (x + WIDTH > WINDOW_WIDTH) {
			x = 10;
			y += HEIGHT + 20;
		}
	}
	XFlush ();
}

displayOne (card, x, y)
struct card	*card;
int		x, y;
{
	int	i;

	for (i = 0; i < card->nPlanes; i++) {
		XPixFill (w, x, y, WIDTH, HEIGHT,
			card->planes[i].pixel, card->planes[i].bits, GXcopy, AllPlanes);
	}
}