1 /*
2 * xtrojka (c) 1994,1995,1996 Maarten Los
3 *
4 * #include "COPYRIGHT"
5 *
6 * created: 5.ii.1996
7 * modified:
8 *
9 * Main file for the statistics window
10 */
11
12 #include <stdio.h>
13
14 #include <X11/Intrinsic.h>
15 #include <X11/StringDefs.h>
16 #include <X11/Shell.h>
17 #include <X11/Xlib.h>
18
19 #include <X11/Xaw/Command.h>
20 #include <X11/Xaw/Form.h>
21 #include <X11/Xaw/Label.h>
22
23 #include "sh_stat.h"
24 #include "debug.h"
25 #include "tr_core.h"
26 #include "xtrojka.h"
27 #include "screen.h"
28 #include "window.h"
29
30 #include "pictures.h"
31 #include "_strdefs.h"
32
33 extern flag is_color;
34 extern Pixmap patPic[tc_blocks];
35
36 extern Widget screen;
37 extern Widget stat_screen;
38 extern Widget main_screen;
39
40 extern Colormap the_colormap;
41 extern int the_depth;
42
43 flag is_gc_created;
44 Widget stat_shell;
45
46 Display *stat_dpy;
47 GC stat_gc;
48 GC arc_gc;
49 XGCValues arc_val;
50 Screen *stat_scr;
51 int fheight;
52 int scount;
53
54
init_stat_window(void)55 void init_stat_window(void)
56 {
57 /*
58 * initialize the statistics window
59 */
60 XtTranslations mytrans;
61 Dimension s_width, s_height;
62
63 DEBUG("sh_stat.c", "init_stat_window")
64
65 mytrans = XtParseTranslationTable("<Expose>: redraw_stat()");
66
67 stat_shell = XtVaCreatePopupShell(
68 STR_WIN_STAT,
69 applicationShellWidgetClass,
70 main_screen,
71 XtNcolormap, the_colormap,
72 XtNdepth, the_depth,
73 NULL
74 );
75
76
77 stat_dpy = XtDisplay(stat_shell);
78 stat_scr = XtScreen(stat_shell);
79 stat_gc = DefaultGCOfScreen(stat_scr);
80 is_gc_created = False;
81
82 s_width = STAT_XSIZE;
83 s_height = STAT_YSIZE;
84
85 DEBUG("sh_stat.c", "init_stat_window")
86 stat_screen = XtVaCreateManagedWidget(
87 "stat_screen",
88 widgetClass,
89 stat_shell,
90 XtNwidth, s_width,
91 XtNheight, s_height,
92 XtNtranslations, mytrans,
93 XtNcolormap, the_colormap,
94 XtNdepth, the_depth,
95 NULL
96 );
97
98 if(is_color)
99 XtVaSetValues(stat_screen,
100 XtNbackground, app_data.color[BLACK],
101 NULL
102 );
103
104 }
105
106
show_stat(void)107 void show_stat(void)
108 {
109 /*
110 * popup stat box
111 */
112 DEBUG("sh_stat.c", "show_stat")
113
114 XtPopup(stat_shell, XtGrabNone);
115 }
116
117
redraw_stat(w,xexp,s,c)118 void redraw_stat(w, xexp, s, c)
119 Widget w;
120 XExposeEvent *xexp;
121 String *s;
122 Cardinal *c;
123 {
124 DEBUG("sh_stat.c", "redraw_stat")
125
126 if(!XtIsRealized(stat_shell))
127 return;
128
129 if(xexp->type != Expose)
130 return;
131 /*
132 fix_dimensions(stat_shell);
133 */
134
135 update_stat();
136 }
137
138
update_stat(void)139 void update_stat(void)
140 {
141 Widget w = stat_screen;
142 Dimension xsize, ysize;
143 unsigned long around = 360*64;
144 unsigned long start_angle, inc_angle;
145 int i;
146 unsigned long vmask;
147
148 DEBUG("sh_stat.c", "draw_stat")
149
150 if(tv_blocks == 0)
151 return;
152
153 clear_window(stat_screen);
154
155 if(!is_gc_created) {
156 arc_val.graphics_exposures;
157 arc_gc = XCreateGC( stat_dpy,
158 XtWindow(stat_shell),
159 GCGraphicsExposures,
160 &arc_val);
161 is_gc_created = True;
162 }
163
164 start_angle = inc_angle = 0L;
165 for(i = 0; i < tc_blocks; i++) {
166
167 /*
168 * calculate the angle and compensate for
169 * precision loss
170 */
171 inc_angle =
172 ((tv_block_count[i] * around) / tv_blocks);
173
174 /*
175 if((start_angle >= around) || (i == tc_blocks - 1))
176 new_angle = around - 1;
177 */
178
179 if(is_color) {
180 arc_val.fill_style = FillSolid;
181 arc_val.foreground = app_data.color[i+1];
182 vmask = GCFillStyle | GCForeground;
183 } else {
184 arc_val.fill_style = FillTiled;
185 arc_val.tile = patPic[i];
186 vmask = GCFillStyle | GCTile;
187 }
188
189 XChangeGC(stat_dpy,
190 arc_gc,
191 vmask,
192 &arc_val);
193
194 XtVaGetValues(w,
195 XtNwidth, &xsize,
196 XtNheight, &ysize,
197 NULL
198 );
199 XFillArc(XtDisplay(w),
200 XtWindow(w),
201 arc_gc,
202 0,0,
203 xsize, ysize,
204 (unsigned int)start_angle,
205 (unsigned int)inc_angle);
206
207 start_angle += inc_angle;
208 }
209
210 }
211
212
213
214
215