File: sh_stat.c

package info (click to toggle)
xtrojka 123-12
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 492 kB
  • ctags: 443
  • sloc: ansic: 3,087; makefile: 135; sh: 19
file content (214 lines) | stat: -rw-r--r-- 3,510 bytes parent folder | download | duplicates (4)
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
/*
 *	xtrojka (c) 1994,1995,1996 Maarten Los
 *
 *	#include "COPYRIGHT"	
 *
 *	created:	5.ii.1996
 *	modified:
 *
 *	Main file for the statistics window
 */

#include <stdio.h>

#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xlib.h>

#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>

#include "sh_stat.h"
#include "debug.h"
#include "tr_core.h"
#include "xtrojka.h"
#include "screen.h"
#include "window.h"

#include "pictures.h"
#include "_strdefs.h"

extern flag is_color;
extern Pixmap patPic[tc_blocks];

extern Widget screen;
extern Widget stat_screen;
extern Widget main_screen;

extern Colormap the_colormap;
extern int the_depth;

flag is_gc_created;
Widget stat_shell;	

Display *stat_dpy;
GC	stat_gc;
GC 	arc_gc;
XGCValues	arc_val;
Screen	*stat_scr;
int 	fheight;
int	scount;


void init_stat_window(void)
{
/*
 *	initialize the statistics window
 */
	XtTranslations mytrans;
	Dimension s_width, s_height;

	DEBUG("sh_stat.c", "init_stat_window")

	mytrans = XtParseTranslationTable("<Expose>: redraw_stat()");

	stat_shell = XtVaCreatePopupShell(
		STR_WIN_STAT,
		applicationShellWidgetClass,
		main_screen,
		XtNcolormap, the_colormap,
		XtNdepth, the_depth,
		NULL
	);


	stat_dpy = XtDisplay(stat_shell);
	stat_scr = XtScreen(stat_shell);
	stat_gc = DefaultGCOfScreen(stat_scr);
	is_gc_created = False;

	s_width = STAT_XSIZE;
	s_height = STAT_YSIZE;

	DEBUG("sh_stat.c", "init_stat_window")
	stat_screen =  XtVaCreateManagedWidget(
		"stat_screen",
		widgetClass,
		stat_shell,
		XtNwidth,	s_width,
		XtNheight,	s_height,
		XtNtranslations, mytrans,
		XtNcolormap, the_colormap,
		XtNdepth, the_depth,
		NULL
	);

	if(is_color)
		XtVaSetValues(stat_screen,
			XtNbackground,	app_data.color[BLACK],	
			NULL
		);
			
}


void show_stat(void)
{
/*
 *	popup stat box
 */
	DEBUG("sh_stat.c", "show_stat")

	XtPopup(stat_shell, XtGrabNone);
}


void redraw_stat(w, xexp, s, c)
Widget w;
XExposeEvent *xexp;
String *s;
Cardinal *c;
{
	DEBUG("sh_stat.c", "redraw_stat")

	if(!XtIsRealized(stat_shell))
		return;

	if(xexp->type != Expose)
		return;
/*
	fix_dimensions(stat_shell);
*/

	update_stat();
}


void update_stat(void)
{
	Widget w = stat_screen;
	Dimension xsize, ysize;
	unsigned long around = 360*64;
	unsigned long start_angle, inc_angle;
	int i;
	unsigned long vmask;

	DEBUG("sh_stat.c", "draw_stat")

	if(tv_blocks == 0)
		return;

	clear_window(stat_screen);

	if(!is_gc_created) {
		arc_val.graphics_exposures;
		arc_gc = XCreateGC(	stat_dpy,
					XtWindow(stat_shell),
					GCGraphicsExposures,
					&arc_val);
		is_gc_created = True;
	}

	start_angle = inc_angle = 0L;
	for(i = 0; i < tc_blocks; i++) {

		/*
		 *	calculate the angle and compensate for
		 *	precision loss
		 */
		inc_angle =
			 ((tv_block_count[i] * around) / tv_blocks);
		
/*
		if((start_angle >= around) || (i == tc_blocks - 1))
			new_angle = around - 1;
*/

		if(is_color) {
			arc_val.fill_style = FillSolid;
			arc_val.foreground = app_data.color[i+1];
			vmask = GCFillStyle | GCForeground;
		} else {
			arc_val.fill_style = FillTiled;
			arc_val.tile = patPic[i];
			vmask = GCFillStyle | GCTile;
		}
		
		XChangeGC(stat_dpy,
			arc_gc,	
			vmask,
			&arc_val);

			XtVaGetValues(w,
				XtNwidth, &xsize,
				XtNheight, &ysize,
				NULL
			);
			XFillArc(XtDisplay(w),
				XtWindow(w),
				arc_gc,
				0,0,
				xsize, ysize,
				(unsigned int)start_angle,
				(unsigned int)inc_angle);

		start_angle += inc_angle;
	}
	
}