tomwalters@0
|
1 /*
|
tomwalters@0
|
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
|
tomwalters@0
|
3 ===========================================================================
|
tomwalters@0
|
4
|
tomwalters@0
|
5 Permission to use, copy, modify, and distribute this software without fee
|
tomwalters@0
|
6 is hereby granted for research purposes, provided that this copyright
|
tomwalters@0
|
7 notice appears in all copies and in all supporting documentation, and that
|
tomwalters@0
|
8 the software is not redistributed for any fee (except for a nominal
|
tomwalters@0
|
9 shipping charge). Anyone wanting to incorporate all or part of this
|
tomwalters@0
|
10 software in a commercial product must obtain a license from the Medical
|
tomwalters@0
|
11 Research Council.
|
tomwalters@0
|
12
|
tomwalters@0
|
13 The MRC makes no representations about the suitability of this
|
tomwalters@0
|
14 software for any purpose. It is provided "as is" without express or
|
tomwalters@0
|
15 implied warranty.
|
tomwalters@0
|
16
|
tomwalters@0
|
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
tomwalters@0
|
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
tomwalters@0
|
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
|
tomwalters@0
|
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
tomwalters@0
|
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
tomwalters@0
|
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
tomwalters@0
|
23 SOFTWARE.
|
tomwalters@0
|
24 */
|
tomwalters@0
|
25
|
tomwalters@0
|
26 /*
|
tomwalters@0
|
27 * switch_control.c
|
tomwalters@0
|
28 * ----------------
|
tomwalters@0
|
29 * the 'switch' for the Controls Window.
|
tomwalters@0
|
30 *
|
tomwalters@0
|
31 * M. Akeroyd. July 1993. version 1.10
|
tomwalters@0
|
32 * Revisions: MAA: Christmas 1993.
|
tomwalters@0
|
33 *
|
tomwalters@0
|
34 */
|
tomwalters@0
|
35
|
tomwalters@0
|
36
|
tomwalters@0
|
37
|
tomwalters@0
|
38 #include <X11/Xlib.h>
|
tomwalters@0
|
39 #include <X11/Xutil.h>
|
tomwalters@0
|
40 #include <X11/Xos.h>
|
tomwalters@0
|
41 #include <X11/Xatom.h>
|
tomwalters@0
|
42 #include <stdio.h>
|
tomwalters@0
|
43
|
tomwalters@0
|
44 #include "xreview.h"
|
tomwalters@0
|
45
|
tomwalters@0
|
46
|
tomwalters@0
|
47 /* General ..................*/
|
tomwalters@0
|
48
|
tomwalters@0
|
49 char progname[MAX_STRING_LENGTH];
|
tomwalters@0
|
50
|
tomwalters@0
|
51
|
tomwalters@0
|
52 /* X ........................*/
|
tomwalters@0
|
53
|
tomwalters@0
|
54 extern Display *display;
|
tomwalters@0
|
55 extern int screen_num;
|
tomwalters@0
|
56 extern Screen *screen_ptr;
|
tomwalters@0
|
57
|
tomwalters@0
|
58 extern toplevelWindow control;
|
tomwalters@0
|
59 extern toplevelWindow axes;
|
tomwalters@0
|
60
|
tomwalters@0
|
61 extern buttonWindow button_quit, button_close;
|
tomwalters@0
|
62 extern buttonWindow button_animate;
|
tomwalters@0
|
63 extern buttonWindow button_startf, button_startb, button_stopf, button_stopb;
|
tomwalters@0
|
64 extern buttonWindow button_skipf, button_skipb, button_faster, button_slower;
|
tomwalters@0
|
65 extern buttonWindow button_firstframe, button_lastframe, button_middle;
|
tomwalters@0
|
66 extern buttonWindow button_stepf, button_stepff, button_stepb, button_stepbb;
|
tomwalters@0
|
67
|
tomwalters@0
|
68 extern buttonWindow info_speed, info_start, info_stop, info_skip;
|
tomwalters@0
|
69 extern buttonWindow info_title, info_frame;
|
tomwalters@0
|
70 extern buttonWindow info_time, info_freq, info_frstep;
|
tomwalters@0
|
71
|
tomwalters@0
|
72 extern XFontStruct *font_info;
|
tomwalters@0
|
73 extern GC button_gc;
|
tomwalters@0
|
74 extern XEvent report;
|
tomwalters@0
|
75
|
tomwalters@0
|
76 extern int button_borderwidth;
|
tomwalters@0
|
77
|
tomwalters@0
|
78
|
tomwalters@0
|
79 /* .ctn .......................*/
|
tomwalters@0
|
80
|
tomwalters@0
|
81 extern int frame;
|
tomwalters@0
|
82 extern int no_frames;
|
tomwalters@0
|
83 extern double frstep_aid;
|
tomwalters@0
|
84 extern double pwidth;
|
tomwalters@0
|
85 extern double nwidth;
|
tomwalters@0
|
86 extern int mincf;
|
tomwalters@0
|
87 extern int maxcf;
|
tomwalters@0
|
88
|
tomwalters@0
|
89 extern int waittime_millisecs;
|
tomwalters@0
|
90 extern int animate_start;
|
tomwalters@0
|
91 extern int animate_stop;
|
tomwalters@0
|
92 extern int animate_skip;
|
tomwalters@0
|
93
|
tomwalters@0
|
94
|
tomwalters@0
|
95 /* Command line ...............*/
|
tomwalters@0
|
96 extern double scale;
|
tomwalters@0
|
97
|
tomwalters@0
|
98
|
tomwalters@0
|
99
|
tomwalters@0
|
100
|
tomwalters@0
|
101
|
tomwalters@0
|
102 /*-----------------------------------------------------------------------*/
|
tomwalters@0
|
103 /*-----------------------------------------------------------------------*/
|
tomwalters@0
|
104
|
tomwalters@0
|
105
|
tomwalters@0
|
106
|
tomwalters@0
|
107
|
tomwalters@0
|
108 void switch_control()
|
tomwalters@0
|
109 {
|
tomwalters@0
|
110 char tempstring[MAX_STRING_LENGTH];
|
tomwalters@0
|
111 int whitepixel = WhitePixel(display, screen_num);
|
tomwalters@0
|
112 int blackpixel = BlackPixel(display, screen_num);
|
tomwalters@0
|
113
|
tomwalters@0
|
114
|
tomwalters@0
|
115 switch(report.type) {
|
tomwalters@0
|
116
|
tomwalters@0
|
117 /*----------------------------------*/
|
tomwalters@0
|
118
|
tomwalters@0
|
119 case Expose:
|
tomwalters@0
|
120 if (report.xexpose.count != 0)
|
tomwalters@0
|
121 break;
|
tomwalters@0
|
122
|
tomwalters@0
|
123 if ((control.window_size == TOO_SMALL_X) ||
|
tomwalters@0
|
124 (control.window_size == TOO_BIG_X))
|
tomwalters@0
|
125 break;
|
tomwalters@0
|
126
|
tomwalters@0
|
127 XDrawLine(display, control.win, control.gc, \
|
tomwalters@0
|
128 0, 80*scale, control.width, 80*scale);
|
tomwalters@0
|
129 XDrawLine(display, control.win, control.gc, \
|
tomwalters@0
|
130 0, 162*scale, control.width, 162*scale);
|
tomwalters@0
|
131
|
tomwalters@0
|
132 XMapWindow(display, button_quit.win);
|
tomwalters@0
|
133 XMapWindow(display, button_close.win);
|
tomwalters@0
|
134 XMapWindow(display, button_animate.win);
|
tomwalters@0
|
135 XMapWindow(display, button_startf.win);
|
tomwalters@0
|
136 XMapWindow(display, button_startb.win);
|
tomwalters@0
|
137 XMapWindow(display, button_stopf.win);
|
tomwalters@0
|
138 XMapWindow(display, button_stopb.win);
|
tomwalters@0
|
139 XMapWindow(display, button_skipf.win);
|
tomwalters@0
|
140 XMapWindow(display, button_skipb.win);
|
tomwalters@0
|
141 XMapWindow(display, button_faster.win);
|
tomwalters@0
|
142 XMapWindow(display, button_slower.win);
|
tomwalters@0
|
143 XMapWindow(display, button_lastframe.win);
|
tomwalters@0
|
144 XMapWindow(display, button_firstframe.win);
|
tomwalters@0
|
145 XMapWindow(display, button_middle.win);
|
tomwalters@0
|
146 XMapWindow(display, button_stepf.win);
|
tomwalters@0
|
147 XMapWindow(display, button_stepff.win);
|
tomwalters@0
|
148 XMapWindow(display, button_stepb.win);
|
tomwalters@0
|
149 XMapWindow(display, button_stepbb.win);
|
tomwalters@0
|
150
|
tomwalters@0
|
151 drawbutton(control, button_quit, &button_gc, "Quit",\
|
tomwalters@0
|
152 whitepixel, blackpixel);
|
tomwalters@0
|
153 drawbutton(control, button_close, &button_gc, "Close", \
|
tomwalters@0
|
154 whitepixel, blackpixel);
|
tomwalters@0
|
155
|
tomwalters@0
|
156 drawbutton(control, button_animate, &button_gc, "Animate", \
|
tomwalters@0
|
157 whitepixel, blackpixel);
|
tomwalters@0
|
158 drawbutton(control, button_startf, &button_gc, "+1", \
|
tomwalters@0
|
159 whitepixel, blackpixel);
|
tomwalters@0
|
160 drawbutton(control, button_startb, &button_gc, "-1", \
|
tomwalters@0
|
161 whitepixel, blackpixel);
|
tomwalters@0
|
162 drawbutton(control, button_stopf, &button_gc, "+1", \
|
tomwalters@0
|
163 whitepixel, blackpixel);
|
tomwalters@0
|
164 drawbutton(control, button_stopb, &button_gc, "-1", \
|
tomwalters@0
|
165 whitepixel, blackpixel);
|
tomwalters@0
|
166 drawbutton(control, button_skipf, &button_gc, "+1", \
|
tomwalters@0
|
167 whitepixel, blackpixel);
|
tomwalters@0
|
168 drawbutton(control, button_skipb, &button_gc, "-1", \
|
tomwalters@0
|
169 whitepixel, blackpixel);
|
tomwalters@0
|
170 drawbutton(control, button_faster, &button_gc, "Fast", \
|
tomwalters@0
|
171 whitepixel, blackpixel);
|
tomwalters@0
|
172 drawbutton(control, button_slower, &button_gc, "Slow", \
|
tomwalters@0
|
173 whitepixel, blackpixel);
|
tomwalters@0
|
174
|
tomwalters@0
|
175 drawbutton(control, button_lastframe, &button_gc, "Last", \
|
tomwalters@0
|
176 whitepixel, blackpixel);
|
tomwalters@0
|
177 drawbutton(control, button_firstframe, &button_gc, "First", \
|
tomwalters@0
|
178 whitepixel, blackpixel);
|
tomwalters@0
|
179 drawbutton(control, button_middle, &button_gc, "Middle", \
|
tomwalters@0
|
180 whitepixel, blackpixel);
|
tomwalters@0
|
181 drawbutton(control, button_stepf, &button_gc, ">", \
|
tomwalters@0
|
182 whitepixel, blackpixel);
|
tomwalters@0
|
183 drawbutton(control, button_stepff, &button_gc, ">>", \
|
tomwalters@0
|
184 whitepixel, blackpixel);
|
tomwalters@0
|
185 drawbutton(control, button_stepb, &button_gc, "<", \
|
tomwalters@0
|
186 whitepixel, blackpixel);
|
tomwalters@0
|
187 drawbutton(control, button_stepbb, &button_gc, "<<", \
|
tomwalters@0
|
188 whitepixel, blackpixel);
|
tomwalters@0
|
189
|
tomwalters@0
|
190
|
tomwalters@0
|
191
|
tomwalters@0
|
192 XMapWindow(display, info_speed.win);
|
tomwalters@0
|
193 sprintf(tempstring, "Speed: %i", waittime_millisecs);
|
tomwalters@0
|
194 drawtext(info_speed, button_gc, font_info, tempstring);
|
tomwalters@0
|
195
|
tomwalters@0
|
196 XMapWindow(display, info_start.win);
|
tomwalters@0
|
197 sprintf(tempstring, "Start: %i", animate_start);
|
tomwalters@0
|
198 drawtext(info_start, button_gc, font_info, tempstring);
|
tomwalters@0
|
199
|
tomwalters@0
|
200 XMapWindow(display, info_stop.win);
|
tomwalters@0
|
201 sprintf(tempstring, "Stop: %i", animate_stop);
|
tomwalters@0
|
202 drawtext(info_stop, button_gc, font_info, tempstring);
|
tomwalters@0
|
203
|
tomwalters@0
|
204 XMapWindow(display, info_skip.win);
|
tomwalters@0
|
205 sprintf(tempstring, "Skip: %i", animate_skip);
|
tomwalters@0
|
206 drawtext(info_skip, button_gc, font_info, tempstring);
|
tomwalters@0
|
207
|
tomwalters@0
|
208 XMapWindow(display, info_frame.win);
|
tomwalters@0
|
209 sprintf(tempstring, "%i of %i", frame, no_frames);
|
tomwalters@0
|
210 drawtext(info_frame, button_gc, font_info, tempstring);
|
tomwalters@0
|
211
|
tomwalters@0
|
212 XMapWindow(display, info_title.win);
|
tomwalters@0
|
213 sprintf(tempstring, "%s", axes.window_name);
|
tomwalters@0
|
214 drawtext(info_title, button_gc, font_info, tempstring);
|
tomwalters@0
|
215
|
tomwalters@0
|
216 XMapWindow(display, info_freq.win);
|
tomwalters@0
|
217 sprintf(tempstring, "Freq %i-%iHz", mincf, maxcf);
|
tomwalters@0
|
218 drawtext(info_freq, button_gc, font_info, tempstring);
|
tomwalters@0
|
219
|
tomwalters@0
|
220 XMapWindow(display, info_time.win);
|
tomwalters@0
|
221 sprintf(tempstring, "Interval %.1f...%.1fms", pwidth, nwidth);
|
tomwalters@0
|
222 drawtext(info_time, button_gc, font_info, tempstring);
|
tomwalters@0
|
223
|
tomwalters@0
|
224 XMapWindow(display, info_frstep.win);
|
tomwalters@0
|
225 sprintf(tempstring, "frstep: %.1fms", frstep_aid);
|
tomwalters@0
|
226 drawtext(info_frstep, button_gc, font_info, tempstring);
|
tomwalters@0
|
227
|
tomwalters@0
|
228
|
tomwalters@0
|
229 break;
|
tomwalters@0
|
230
|
tomwalters@0
|
231
|
tomwalters@0
|
232 /*--------------------------------------*/
|
tomwalters@0
|
233
|
tomwalters@0
|
234
|
tomwalters@0
|
235 case ConfigureNotify:
|
tomwalters@0
|
236 if (report.xconfigure.window != control.win)
|
tomwalters@0
|
237 break;
|
tomwalters@0
|
238
|
tomwalters@0
|
239 control.width = report.xconfigure.width;
|
tomwalters@0
|
240 control.height = report.xconfigure.height;
|
tomwalters@0
|
241
|
tomwalters@0
|
242 control.window_size = BIG_ENOUGH_X;
|
tomwalters@0
|
243 if ((control.width < control.size_hints.min_width) || \
|
tomwalters@0
|
244 (control.height < control.size_hints.min_height))
|
tomwalters@0
|
245 control.window_size = TOO_SMALL_X;
|
tomwalters@0
|
246 if ((control.width > control.size_hints.max_width) || \
|
tomwalters@0
|
247 (control.height > control.size_hints.max_height))
|
tomwalters@0
|
248 control.window_size = TOO_BIG_X;
|
tomwalters@0
|
249 break;
|
tomwalters@0
|
250
|
tomwalters@0
|
251 /*--------------------------------------*/
|
tomwalters@0
|
252
|
tomwalters@0
|
253 default:
|
tomwalters@0
|
254 break;
|
tomwalters@0
|
255
|
tomwalters@0
|
256 } /* switch */
|
tomwalters@0
|
257
|
tomwalters@0
|
258 }
|
tomwalters@0
|
259
|
tomwalters@0
|
260
|
tomwalters@0
|
261
|
tomwalters@0
|
262
|
tomwalters@0
|
263
|
tomwalters@0
|
264
|
tomwalters@0
|
265 /* The End */
|
tomwalters@0
|
266 /*-------------------------------------------------------------------------*/
|
tomwalters@0
|
267 /*-------------------------------------------------------------------------*/
|