1 /*
2  *	xtrojka (c) 1994,1995,1996 Maarten Los
3  *
4  *	#include "COPYRIGHT"
5  *
6  *	created:	27.xi.1995
7  *	modified:	27.xii.1995
8  *
9  *	Low level window/widget manager
10  */
11 
12 
13 #include <stdio.h>
14 
15 #include <X11/Intrinsic.h>
16 #include <X11/StringDefs.h>
17 #include <X11/Shell.h>
18 
19 #include <X11/Xaw/Command.h>
20 #include <X11/Xaw/Form.h>
21 #include <X11/Xaw/Label.h>
22 
23 #include "xtrojka.h"
24 #include "window.h"
25 #include "tr_core.h"
26 #include "sh_slist.h"
27 #include "sh_stat.h"
28 #include "debug.h"
29 
30 
31 Widget trojkamenu_but;
32 Widget speedmenu_but;
33 extern XtAppContext app_context;
34 
35 extern flag is_color;
36 
37 extern void redraw_leftpillar();
38 extern void redraw_rightpillar();
39 extern void redraw_screen();
40 extern void redraw_stat();
41 extern void redraw_slist();
42 
43 extern AppData app_data;
44 
45 extern Colormap the_colormap;
46 extern int the_depth;
47 
48 
49 Widget main_screen;
50 Widget form;
51 Widget slist_shell;
52 Widget leftpillar;
53 Widget rightpillar;
54 Widget screen;
55 Widget slist_screen;
56 Widget stat_screen;
57 Widget speed_label;
58 Widget speed_box;	/* for "Score:" and score */
59 Widget score_label;
60 Widget score_box;	/* for "Speed:" and speed */
61 
62 XFontStruct *font;
63 
64 XtTranslations mytrans;
65 
init_windows(void)66 void init_windows(void)
67 /*
68  *	initialize the whole widget stuff, INCLUDING the menu buttons.
69  *	The rest of the menu-stuff is handled in 'scrx_menu.c'
70  */
71 {
72 	static XtActionsRec redraw_actions[] = {
73 		{ "redraw_rightpillar", redraw_rightpillar },
74 		{ "redraw_leftpillar", redraw_leftpillar },
75 		{ "redraw_screen", redraw_screen },
76 		{ "redraw_stat", redraw_stat },
77 		{ "redraw_slist", redraw_slist }
78 	};
79 
80 	DEBUG("window.c", "init_windows")
81 
82 	DEBUG("\tinit_windows", "form")
83 	form = XtVaCreateManagedWidget(
84 		"form", formWidgetClass, main_screen,
85 		XtNcolormap, the_colormap,
86 		XtNdepth, the_depth,
87 		NULL
88 	);
89 
90 	DEBUG("\tinit_windows", "trojkamenu_but")
91 	trojkamenu_but = XtVaCreateManagedWidget(
92 		"trojka_button", commandWidgetClass, form,
93 		NULL
94 	);
95 
96 
97 	DEBUG("\tinit_windows", "speedmenu_but")
98 	speedmenu_but = XtVaCreateManagedWidget(
99 		"speed_button", commandWidgetClass, form,
100 		XtNfromHoriz,	trojkamenu_but,
101 		NULL
102 	);
103 
104 	DEBUG("\tinit_windows", "score_label")
105 	score_label = XtVaCreateManagedWidget(
106 		"score_label", labelWidgetClass, form,
107 		XtNfromVert,	trojkamenu_but,
108 		XtNborderWidth,	0,
109 		NULL
110 	);
111 
112 	DEBUG("\tinit_windows", "score_box")
113 	score_box = XtVaCreateManagedWidget(
114 		"score_box", labelWidgetClass, form,
115 		XtNfromVert,	trojkamenu_but,
116 		XtNfromHoriz,	score_label,
117 		XtNlabel,	"         ",
118 		XtNborderWidth,	0,
119 		NULL
120 	);
121 
122 	DEBUG("\tinit_windows", "speed_label")
123 	speed_label = XtVaCreateManagedWidget(
124 		"speed_label", labelWidgetClass, form,
125 		XtNfromVert,	trojkamenu_but,
126 		XtNfromHoriz,	score_box,
127 		XtNborderWidth,	0,
128 		NULL
129 	);
130 
131 	DEBUG("\tinit_windows", "speed_box")
132 	speed_box = XtVaCreateManagedWidget(
133 		"speed_box", labelWidgetClass, form,
134 		XtNlabel,	"       ",
135 		XtNfromVert,	trojkamenu_but,
136 		XtNfromHoriz,	speed_label,
137 		XtNborderWidth,	0,
138 		NULL
139 	);
140 
141 	DEBUG("\tinit_windows", "leftpillar")
142 	mytrans = XtParseTranslationTable("<Expose>: redraw_leftpillar()");
143 	leftpillar =  XtVaCreateManagedWidget(
144 		"leftpillar", widgetClass, form,
145 		XtNwidth,	PILLAR_XSIZE,
146 		XtNheight,	WIN_YSIZE,
147 		XtNfromVert,	score_box,
148 		XtNtranslations,mytrans,
149 		XtNborderWidth,	0,
150 		XtNcolormap, the_colormap,
151 		XtNdepth, the_depth,
152 		NULL
153 	);
154 
155 	DEBUG("\tinit_windows", "screen")
156 	mytrans = XtParseTranslationTable("<Expose>: redraw_screen()");
157 	screen =  XtVaCreateManagedWidget(
158 		"screen", widgetClass, form,
159 		XtNwidth,	WIN_XSIZE,
160 		XtNheight,	WIN_YSIZE,
161 		XtNfromHoriz,	leftpillar,
162 		XtNfromVert,	score_box,
163 		XtNtranslations,mytrans,
164 		XtNcolormap, the_colormap,
165 		XtNdepth, the_depth,
166 		NULL
167 	);
168 
169 
170 	DEBUG("\tinit_windows", "rightpillar")
171 	mytrans = XtParseTranslationTable("<Expose>: redraw_rightpillar()");
172 	rightpillar =  XtVaCreateManagedWidget(
173 		"rightpillar", widgetClass, form,
174 		XtNwidth,	PILLAR_XSIZE,
175 		XtNheight,	WIN_YSIZE,
176 		XtNfromHoriz,	screen,
177 		XtNfromVert,	score_box,
178 		XtNborderWidth,	0,
179 		XtNtranslations,mytrans,
180 		XtNcolormap, the_colormap,
181 		XtNdepth, the_depth,
182 		NULL
183 	);
184 
185 	DEBUG("\tinit_windows", "if(is_color...")
186 	if(is_color) {
187 		XtVaSetValues(screen,
188 			XtNforeground, app_data.color[WHITE],
189 			XtNbackground, app_data.color[BLACK],
190 			NULL
191 		);
192 	}
193 
194 	init_slist_window();
195 	init_stat_window();
196 
197 	XtAppAddActions(app_context, redraw_actions, XtNumber(redraw_actions));
198 }
199 
200 
201 
202 
203 
204 
fix_dimensions(shell)205 void fix_dimensions(shell)
206 Widget shell;
207 {
208 	Dimension width, height;
209 
210 	DEBUG("window.c", "fix_dimensions")
211 
212 	XtVaGetValues(shell,
213 		XtNwidth, &width,
214 		XtNheight, &height,
215 		NULL
216 	);
217 
218 	XtVaSetValues(shell,
219 		XtNmaxWidth, width,
220 		XtNminWidth, width,
221 		XtNmaxHeight, height,
222 		XtNminHeight, height,
223 		NULL
224 	);
225 }
226 
227 
228 
clear_window(w)229 void clear_window(w)
230 Widget w;
231 {
232 	DEBUG("window.c", "clear_window")
233 
234 	XClearWindow(XtDisplay(w), XtWindow(w));
235 }
236 
237 
238 
239 
240 
241