1 /*
2  *	xtrojka (c) 1994,1995,1996 Maarten Los
3  *
4  *	#include "COPYRIGHT"
5  *
6  *	created:	31.xii.1995
7  *	modified:
8  *
9  *	Do drawing for the game window
10  */
11 
12 
13 #include <stdio.h>
14 
15 #include <X11/Intrinsic.h>
16 #include <X11/StringDefs.h>
17 #include <X11/Shell.h>
18 #include <X11/Xlib.h>
19 
20 #include <X11/Xaw/Command.h>
21 #include <X11/Xaw/Form.h>
22 #include <X11/Xaw/Label.h>
23 #include "sh_slist.h"
24 #include "sh_main.h"
25 
26 #include "debug.h"
27 #include "xtrojka.h"
28 #include "screen.h"
29 #include "window.h"
30 #include "pictures.h"
31 #include "menu.h"
32 #include "tr_core.h"
33 
34 extern flag is_color;
35 extern flag is_slick;
36 
37 extern GAME_STATE game_state;
38 
39 extern Widget screen;
40 extern Widget speed_box;	/* for "Score:" and score */
41 extern Widget score_box;	/* for "Speed:" and speed */
42 extern Widget leftpillar;
43 extern Widget rightpillar;
44 
45 extern Pixmap blockPic[tc_blocks + 1];
46 #ifdef XPM
47 extern Pic	blockPicXpm[tc_blocks];
48 extern Pic 	leftpillarPicXpm;
49 extern Pic	rightpillarPicXpm;
50 #endif
51 
52 extern Pixmap newPic;
53 extern Pixmap titlePic;
54 extern Pixmap rightpillarPic;
55 extern Pixmap leftpillarPic;
56 
57 extern int speed;
58 
59 /*
60  *	implemenation
61  */
trojka_explode_callback(a,b)62 void trojka_explode_callback(a,b)
63 int a,b;
64 {
65 }
66 
67 
trojka_make_block_callback(x,y,i)68 void trojka_make_block_callback(x,y,i)
69 int x,y,i;
70 /*
71  *	draws a block on the screen
72  */
73 {
74 	DEBUG("sh_main.c", "makeblock")
75 
76 	if(is_color) {
77 		set_color(screen, i, BLACK);
78 #ifdef XPM
79 		if(is_slick) {
80 			/*
81 			 * draw using a pixmap, except for an empty block which
82 			 * is drawn as a black rectangle
83 			 */
84 			if(i == 0) {
85 				set_color(screen, i, BLACK);
86 				XFillRectangle(XtDisplay(screen),
87 					XtWindow(screen),
88 					DefaultGCOfScreen(XtScreen(screen)),
89 					x*BLOCK_XSIZE+2,
90 					(tc_pm_top-y) * BLOCK_YSIZE,
91 					BLOCK_XSIZE-1, BLOCK_YSIZE-1
92 				);
93 			} else {
94 				i--;
95 				XCopyArea(XtDisplay(screen),
96 					blockPicXpm[i].pic, XtWindow(screen),
97 					DefaultGCOfScreen(XtScreen(screen)),
98 					0,0,
99 					blockPicXpm[i].attr.width,
100 					blockPicXpm[i].attr.height,
101 					x * BLOCK_XSIZE + 2,
102 					(tc_pm_top - y) * BLOCK_YSIZE
103 				);
104 			}
105 		} else {
106 #endif
107 			/*
108 			 * draw using a rectangle fill
109 			 */
110 			XFillRectangle(XtDisplay(screen), XtWindow(screen),
111 				DefaultGCOfScreen(XtScreen(screen)),
112 				x*BLOCK_XSIZE + 2, (tc_pm_top-y) * BLOCK_YSIZE,
113 				BLOCK_XSIZE-1, BLOCK_YSIZE-1);
114 #ifdef XPM
115 		}
116 #endif
117 	} else {
118 		/*
119 		 * draw a pattern
120 		 */
121 		XCopyArea(XtDisplay(screen), blockPic[i], XtWindow(screen),
122 			DefaultGCOfScreen(XtScreen(screen)),
123 			0,0, BLOCK_XSIZE, BLOCK_YSIZE,
124 			x * BLOCK_XSIZE + 2, (tc_pm_top - y) * BLOCK_YSIZE
125 		);
126 	}
127 }
128 
129 
trojka_wipe_block_callback(x,y)130 void trojka_wipe_block_callback(x,y)
131 int x,y;
132 /*
133  *	wipes a block from the screen
134  */
135 {
136 	DEBUG("sh_main.c", "wipeblock")
137 
138 	trojka_make_block_callback(x,y, 0);
139 }
140 
141 
trojka_trojka_callback(val)142 void trojka_trojka_callback(val)
143 tt_long val;
144 {	/* JUST A DUMMY FUNC */
145 /*
146 	printf("Trojka! (%ld)\n", val);
147 */
148 }
149 
150 
trojka_spider_callback(val)151 void trojka_spider_callback(val)
152 tt_long val;
153 {
154 /*
155 	printf("spider!(%ld)\n", val);
156 */
157 }
158 
trojka_bottom_callback(val)159 void trojka_bottom_callback(val)
160 tt_long val;
161 {
162 /*
163 	printf("bottom!(%ld)\n", val);
164 */
165 }
166 
167 
show_score(void)168 void show_score(void)
169 {
170 /*
171  *	display the score
172  */
173 	char str_score[10];
174 
175 	DEBUG("sh_main.c", "show_score")
176 
177 	if(!XtIsRealized(score_box))
178 		return;
179 
180 
181 	sprintf(str_score,"%lu", tv_score);
182 
183 
184 	XtVaSetValues(score_box,
185 		XtNlabel, str_score,
186 		NULL
187 	);
188 }
189 
190 
trojka_speedup_callback(cb_speed)191 void trojka_speedup_callback(cb_speed)
192 int cb_speed;
193 {
194 	set_speed_item(cb_speed);
195 }
196 
197 
show_speed(the_speed)198 void show_speed(the_speed)
199 int the_speed;
200 {
201 /*
202  *	Displays the speed
203  */
204 
205 	char	str_speed[10];
206 
207 	DEBUG("sh_main.c", "show_speed")
208 
209 	if(!XtIsRealized(speed_box))
210 		return;
211 
212 	sprintf(str_speed,"%d", the_speed);
213 	XtVaSetValues(speed_box,
214 		XtNlabel, str_speed,
215 		NULL
216 	);
217 }
218 
219 /*
220  *	these are redraw actions triggered by the expose event
221  */
redraw_leftpillar(w,xexp,s,c)222 void redraw_leftpillar(w, xexp, s, c)
223 Widget w;
224 XExposeEvent *xexp;
225 String *s;
226 Cardinal *c;
227 {
228 	DEBUG("sh_main.c", "redraw_leftpillar")
229 
230 	if(xexp->type != Expose)
231 		return;
232 
233 	if(is_color) {
234 #ifndef XPM
235 		set_color(leftpillar, BLACK, WHITE);
236 		XCopyPlane(XtDisplay(leftpillar), leftpillarPic,
237 			XtWindow(leftpillar),
238 			DefaultGCOfScreen(XtScreen(leftpillar)),
239 			0,0, PILLAR_XSIZE, PILLAR_YSIZE, 0,0, 1
240 		);
241 #else
242 		XCopyArea(XtDisplay(leftpillar),
243 			leftpillarPicXpm.pic,
244 			XtWindow(leftpillar),
245 			DefaultGCOfScreen(XtScreen(leftpillar)),
246 			0,0,
247 			leftpillarPicXpm.attr.width,
248 			leftpillarPicXpm.attr.height,
249 			0,0
250 		);
251 #endif
252 	} else {
253 		XCopyArea(XtDisplay(leftpillar), leftpillarPic,
254 			XtWindow(leftpillar),
255 			DefaultGCOfScreen(XtScreen(leftpillar)),
256 			0,0, PILLAR_XSIZE, PILLAR_YSIZE, 0,0
257 		);
258 	}
259 }
260 
261 
redraw_rightpillar(w,xexp,s,c)262 void redraw_rightpillar(w, xexp, s, c)
263 Widget w;
264 XExposeEvent *xexp;
265 String *s;
266 Cardinal *c;
267 {
268 	DEBUG("sh_main.c", "redraw_rightpillar")
269 
270 	if(xexp->type != Expose)
271 		return;
272 
273 	if(is_color) {
274 #ifndef XPM
275 		set_color(rightpillar, BLACK, WHITE);
276 		XCopyPlane(XtDisplay(rightpillar), rightpillarPic,
277 			XtWindow(rightpillar),
278 			DefaultGCOfScreen(XtScreen(rightpillar)),
279 			0,0, PILLAR_XSIZE, PILLAR_YSIZE, 0,0, 1);
280 #else
281 		XCopyArea(XtDisplay(rightpillar),
282 			rightpillarPicXpm.pic,
283 			XtWindow(rightpillar),
284 			DefaultGCOfScreen(XtScreen(rightpillar)),
285 			0,0,
286 			rightpillarPicXpm.attr.width,
287 			rightpillarPicXpm.attr.height,
288 			0,0
289 		);
290 #endif
291 	} else {
292 		XCopyArea(XtDisplay(rightpillar), rightpillarPic,
293 			XtWindow(rightpillar),
294 			DefaultGCOfScreen(XtScreen(rightpillar)),
295 			0,0, PILLAR_XSIZE, PILLAR_YSIZE, 0,0);
296 	}
297 }
298 
299 
draw_field(void)300 void draw_field(void)
301 {
302 	tt_command CMD_DRAWFIELD;
303 
304 	DEBUG("sh_main.c", "draw_field")
305 
306 	paint_widget(screen, BLACK, BLACK);
307 
308 	CMD_DRAWFIELD.command = tc_c_drawfield;
309 	trojka_api(&CMD_DRAWFIELD);
310 }
311 
312 
draw_title(void)313 void draw_title(void)
314 {
315 	DEBUG("sh_main.c", "draw_title")
316 
317 	if(is_color) {
318 		paint_widget(screen, PURPLE, YELLOW);
319 		set_color(screen, YELLOW, PURPLE);
320 		XCopyPlane(XtDisplay(screen),
321 			titlePic, XtWindow(screen),
322 			DefaultGCOfScreen(XtScreen(screen)),
323 			0,0, title_width, title_height, TITLE_X, TITLE_Y, 1);
324 	} else {
325 		clear_window(screen);
326 		XCopyArea(XtDisplay(screen),
327 			titlePic, XtWindow(screen),
328 			DefaultGCOfScreen(XtScreen(screen)),
329 			0,0, title_width, title_height, TITLE_X, TITLE_Y);
330 	}
331 }
332 
333 
redraw_screen(w,xexp,s,c)334 void redraw_screen(w, xexp, s, c)
335 Widget w;
336 XExposeEvent *xexp;
337 String *s;
338 Cardinal *c;
339 {
340 	DEBUG("sh_main.c", "redraw_screen")
341 
342 	if(xexp->type != Expose)
343 		return;
344 
345 	if(game_state == st_playing) {
346 
347 		/*
348 		 * draw field
349 		 */
350 		draw_field();
351 
352 	}
353 	if(game_state == st_idle) {
354 
355 		/*
356 		 *	draw title
357 		 */
358 		draw_title();
359 
360 	}
361 }
362 
363