1 /*
2 * xtrojka (c) 1994,1995,1996 Maarten Los
3 *
4 * #include "COPYRIGHT"
5 *
6 * created: 31.xii.1995
7 * modified:
8 *
9 * handle drawing of the highscore status window
10 */
11
12 #include <stdio.h>
13 #include <pwd.h>
14 #include <time.h>
15
16 #include <X11/Intrinsic.h>
17 #include <X11/StringDefs.h>
18 #include <X11/Shell.h>
19 #include <X11/Xlib.h>
20
21 #include <X11/Xaw/Command.h>
22 #include <X11/Xaw/Form.h>
23 #include <X11/Xaw/Label.h>
24
25 #include "sh_slist.h"
26 #include "xtrojka.h"
27 #include "screen.h"
28 #include "window.h"
29 #include "font.h"
30 #include "scores.h"
31 #include "pictures.h"
32 #include "slist.h"
33
34 #include "debug.h"
35 #include "tr_core.h"
36 #include "_strdefs.h"
37
38 #define SLIST_X 30
39 #define SLIST_Y(y) (((y) + 1) * 18)
40
41
42 extern flag is_color;
43 extern GAME_STATE game_state;
44 extern AppData app_data;
45
46 extern Widget screen;
47 extern Widget main_screen;
48 extern Widget slist_screen;
49 extern Widget slist_shell;
50 extern SCORES scores[NUMSCORES];
51 extern flag changed[NUMSCORES];
52 extern int position;
53
54 extern Colormap the_colormap;
55 extern int the_depth;
56
57 extern Pixmap newPic;
58
59 Display *slist_dpy;
60 GC slist_gc;
61 Screen *slist_scr;
62 Font slist_font;
63 XFontStruct *slist_fontstr;
64 int slist_fh; /* font height */
65
66 /*
67 * implementation
68 */
69
init_slist_window(void)70 void init_slist_window(void)
71 {
72 XtTranslations mytrans;
73 Dimension s_width, s_height;
74
75 DEBUG("sh_slist.c", "init_slist_window")
76
77 mytrans=XtParseTranslationTable("<Expose>: redraw_slist()");
78
79
80 slist_shell = XtVaCreatePopupShell(
81 STR_WIN_SCORES,
82 applicationShellWidgetClass,
83 main_screen,
84 XtNcolormap, the_colormap,
85 XtNdepth, the_depth,
86 NULL
87 );
88 slist_dpy = XtDisplay(slist_shell);
89 slist_scr = XtScreen(slist_shell);
90 slist_gc = DefaultGCOfScreen(slist_scr);
91 slist_font = XLoadFont(slist_dpy, app_data.slist_font);
92 slist_fontstr = XQueryFont(slist_dpy, slist_font);
93 s_width = FontWidth(slist_fontstr) * 68 + 20;
94 s_height = FontHeight(slist_fontstr) * 20 + 20;
95
96 XSetFont(slist_dpy, slist_gc, slist_font);
97 DEBUG("sh_slist.c", "init_slist_window")
98
99 slist_screen = XtVaCreateManagedWidget(
100 "slist_screen",
101 widgetClass,
102 slist_shell,
103 XtNtranslations,mytrans,
104 XtNwidth, s_width,
105 XtNheight, s_height,
106 XtNcolormap, the_colormap,
107 XtNdepth, the_depth,
108 NULL
109 );
110
111 if(is_color)
112 XtVaSetValues(slist_screen,
113 XtNforeground, app_data.color[WHITE],
114 XtNbackground, app_data.color[BLUE],
115 NULL
116 );
117
118
119 }
120
draw_slist(mode)121 void draw_slist(mode)
122 int mode;
123 {
124 char string[100];
125 char date_st[30];
126 char user_st[30];
127 struct passwd *pw;
128 flag f_changed;
129 int i;
130
131 DEBUG("sh_slist.c", "draw_slist");
132
133 f_changed = file_changed(SCOREFILE);
134
135 if(f_changed) {
136 copy_oldscores();
137 read_scores();
138 compare_scores();
139 }
140
141 if(!f_changed && (mode == kUNFORCED)) {
142 return;
143 }
144
145 clear_window(slist_screen);
146
147 if(is_color)
148 set_color(slist_screen, WHITE, NO_COLOR);
149
150 draw_string(slist_screen, SLIST_X, SLIST_Y(0),
151 app_data.str_best_players);
152 draw_string(slist_screen, SLIST_X+1, SLIST_Y(0),
153 app_data.str_best_players);
154
155
156 for(i = 0; i < NUMSCORES; i++) {
157 if(scores[i].score == 0)
158 break;
159
160 strcpy(date_st, ctime(&(scores[i].date)));
161 date_st[strlen(date_st)-1] = '\0';
162 pw = getpwuid(scores[i].user);
163 if(pw)
164 strcpy(user_st, pw->pw_name);
165 else
166 sprintf(user_st,"(uid=%d)",scores[i].user);
167
168 compose_score_string(string, i,scores[i], user_st, date_st);
169
170 if(changed[i]) {
171 draw_newpic(3, SLIST_Y(i+1) + 8);
172 }
173 draw_string(slist_screen, SLIST_X, SLIST_Y(i+2), string);
174 if(position == i) {
175 if(is_color)
176 set_color(slist_screen, YELLOW, NO_COLOR);
177 draw_string(slist_screen,SLIST_X+1,SLIST_Y(i+2),string);
178 draw_string(slist_screen, SLIST_X, SLIST_Y(i+2), string);
179 if(is_color)
180 set_color(slist_screen, WHITE, NO_COLOR);
181 }
182 }
183 }
184
185
draw_newpic(x,y)186 void draw_newpic(x,y)
187 int x,y;
188 {
189 DEBUG("sh_slist.c", "draw_newpic")
190
191 if(is_color) {
192 set_color(slist_screen, CYAN, BLUE);
193 XCopyPlane(slist_dpy, newPic, XtWindow(slist_screen), slist_gc,
194 0,0, new_width, new_height, x,y, 1);
195 set_color(slist_screen, WHITE, BLUE);
196 } else {
197 XCopyArea(slist_dpy, newPic, XtWindow(slist_screen), slist_gc,
198 0,0, new_width, new_height, x,y);
199 }
200 }
201
202
show_slist(void)203 void show_slist(void)
204 {
205 /*
206 * pops up the score list window
207 */
208
209 DEBUG("sh_slist.c", "show_slist")
210
211 XtPopup(slist_shell, XtGrabNone);
212 }
213
214
hide_slist(void)215 void hide_slist(void)
216 {
217 /*
218 * pops down the score list window
219 */
220
221 DEBUG("sh_slist.c", "hide_slist")
222
223 XtPopdown(slist_shell);
224 }
225
226
227
redraw_slist(w,xexp,s,c)228 void redraw_slist(w, xexp, s, c)
229 Widget w;
230 XExposeEvent *xexp;
231 String *s;
232 Cardinal *c;
233 {
234 DEBUG("sh_slist.c", "redraw_slist")
235
236 if(xexp->type == Expose)
237 draw_slist(kFORCED);
238 }
239
240
241