comparison xaim/graphics.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1993
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal
9 shipping charge). Anyone wanting to incorporate all or part of this
10 software in a commercial product must obtain a license from the Medical
11 Research Council.
12
13 The MRC makes no representations about the suitability of this
14 software for any purpose. It is provided "as is" without express or
15 implied warranty.
16
17 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19 THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
20 OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 SOFTWARE.
24 */
25
26 /*
27 * graphics.c
28 * ----------
29 * Draws things ...
30 *
31 * NB: The method used for timing the animations (display a frame, wait until
32 * the clock has got above some threshold, display the next frame) doesn't
33 * seem to work on the linux 396 pc. Thus, it is ALL removed. This means
34 * you can't change the speed of that's animations.
35 * The 'flashtime' of the Control Buttons is also removed.
36 * For speed reasons, the bit that keeps the frame-nbumber in sync with
37 * the animations is also removed from the linux version (in animate_image)
38 *
39 * M. Akeroyd. July 1993. version 1.10
40 * Revisions: MAA Christmas 1993.
41 *
42 */
43
44
45
46 #include <X11/Xlib.h>
47 #include <X11/Xutil.h>
48 #include <X11/Xos.h>
49 #include <X11/Xatom.h>
50 #include <stdio.h>
51
52 #include "xreview.h"
53
54 #define FLASHTIME 200 /* how long to flash a button for, in msecs.
55 * 200 works very well on a Sparc or DECStation.
56 * The linux 386 pc doesn't like counting times,
57 * so is therefore 0. */
58 #ifdef HOST_SPARC
59 #define FLASHTIME 200
60 #endif
61 #ifdef HOST_DECSTATION
62 #define FLASHTIME 200
63 #endif
64 #ifdef HOST_LINUXPC
65 #define FLASHTIME 0
66 #endif
67
68
69
70 void drawtext(buttonWindow win, GC gc, XFontStruct *font_info_local, char *text);
71
72
73
74 /* General variables ....*/
75
76 extern char progname[MAX_STRING_LENGTH];
77
78 extern char *data_pointer;
79 extern char *data_pointer_sideways;
80 extern long location[MAX_FRAMES];
81 extern FILE *inputfp;
82 extern char inputfn[MAX_STRING_LENGTH];
83
84 extern int sidewaysflag;
85
86
87 /* X ....................*/
88
89 extern char display_name[MAX_STRING_LENGTH];
90 extern char fontname[MAX_STRING_LENGTH];
91
92 extern Display *display;
93 extern int screen_num;
94 extern Screen *screen_ptr;
95 extern int depth;
96 extern unsigned int display_width, display_height;
97
98 extern toplevelWindow control;
99 extern toplevelWindow axes;
100 extern buttonWindow info_frame;
101 extern XImage *reviewimage;
102
103 extern XFontStruct *font_info;
104 extern GC button_gc;
105
106
107 /* .ctn ..................*/
108
109 extern int no_frames;
110 extern int frame;
111 extern long waittime_millisecs;
112 extern long waittime_microsecs;
113
114
115 /* Command line ..........*/
116
117 extern int verboseflag;
118
119
120
121
122
123 /*--------------------------------------------------------------------*/
124 /*--------------------------------------------------------------------*/
125
126
127
128
129 void animate_image(int start, int stop, int skip)
130 {
131 long localtime;
132 char tempstring[100];
133 long address;
134 int reviewimage_bytesperline;
135 int x, y;
136 int tempy, tempx;
137 long frameconst, framesize;
138 int counter, counter2, counter3;
139 long framestop= 100000;
140 long limit;
141 long ylimit;
142 long newaddress;
143 long delta;
144 long required_bytes;
145 long lframe;
146 int framenth=1;
147
148 waittime_microsecs = (long) waittime_millisecs * 1000;
149
150 reviewimage_bytesperline = (int) ((int) ((axes.width -1) / 32) +1) *4;
151
152 if (sidewaysflag == ON) {
153 framesize = reviewimage_bytesperline * axes.height *depth;
154 frameconst = framesize;
155 counter =-1;
156 counter2 = 0;
157 ylimit = axes.height*reviewimage_bytesperline*depth;
158 limit= (long) ylimit + no_frames*(frameconst);
159
160 address=(long) location[start];
161 delta = axes.height*0;
162
163 for (lframe=1; lframe <=framestop; lframe++) {
164 if ((ylimit+(framenth*framesize)) >= limit){
165 lframe=framestop+10;
166 continue;}
167 counter+=1;
168 for (y=0; y<axes.height; y++){
169 tempy = y * reviewimage_bytesperline;
170 for (x=0; x<=(reviewimage_bytesperline-2); x+=1)
171 data_pointer[tempy+x] = data_pointer[tempy+x+1];
172 x=reviewimage_bytesperline-1;
173 data_pointer[tempy+x] = data_pointer[tempy+frameconst+counter];}
174 if (counter == reviewimage_bytesperline-1){
175 counter = -1;
176 frameconst += framesize;
177 framenth++;}
178 reviewimage->data = (char *) address;
179 counter2++;
180 if (counter2 == skip) {
181 counter2=0;
182 XPutImage(display, axes.win, axes.gc, reviewimage, \
183 0, 0, 0, 0, axes.width, axes.height);}
184 if ((lframe % 100) == 0) {
185 XClearWindow(display, info_frame.win);
186 sprintf(tempstring, "%i (%i)", framenth, no_frames);
187 drawtext(info_frame, button_gc, font_info, tempstring);}}
188
189 required_bytes = no_frames*axes.height*reviewimage_bytesperline*depth;
190 for (x=location[0]; x<=location[0]+required_bytes-1; x++)
191 data_pointer[x] = data_pointer_sideways[x];
192 XClearWindow(display, info_frame.win);
193 sprintf(tempstring, "%i (%i)", no_frames, no_frames);
194 drawtext(info_frame, button_gc, font_info, tempstring);}
195
196 else {
197 for (frame=start; frame<=stop; frame += skip){
198 reviewimage->data = (char *) location[frame];
199 XPutImage(display, axes.win, axes.gc, reviewimage, \
200 0, 0, 0, 0, axes.width, axes.height);
201 /* Since this next bit only seems to work on a Sparc or DECstation, leave
202 * it out if we're on a 386 pc
203 */
204 #ifndef HOST_LINUXPC
205 if (waittime_millisecs > 0) {
206 XClearWindow(display, info_frame.win);
207 sprintf(tempstring, "%i of %i", frame, no_frames);
208 drawtext(info_frame, button_gc, font_info, tempstring);}
209 localtime = (long) clock();
210 while (clock() - localtime <= waittime_microsecs)
211 ;
212 #endif
213 }
214 frame=stop;
215 XClearWindow(display, info_frame.win);
216 sprintf(tempstring, "%i of %i", frame, no_frames);
217 drawtext(info_frame, button_gc, font_info, tempstring);
218 }
219 }
220
221
222
223
224
225 /*--------------------------------------------------------------------------*/
226 /*--------------------------------------------------------------------------*/
227
228
229
230
231 void drawimage(int frame)
232 {
233 reviewimage->data = (char *) location[frame];
234
235 XPutImage(display, axes.win, axes.gc, reviewimage, 0, 0, 0, 0, axes.width, axes.height);
236 }
237
238
239
240 /*-------------------------------------------------------------------------*/
241 /*-------------------------------------------------------------------------*/
242
243
244
245
246 void drawtext(buttonWindow win, GC gc, XFontStruct *font_info_local, char *text)
247 {
248 /*
249 * Copied off basicwindow.c: place_text ()
250 * Draws 'text' centered horizontally and vertically in the Window.
251 * Well, vertically ish. It looks reasonably centered.
252 *
253 */
254
255 int len_text, width_text;
256 int width = win.width;
257 int height = win.height;
258
259 len_text = strlen(text);
260 width_text = XTextWidth(font_info_local, text, len_text);
261
262 XDrawString(display, win.win, gc, (width - width_text)/2, \
263 (height + font_info_local->ascent -1)/2, text, len_text);
264
265 }
266
267
268
269
270 /*-----------------------------------------------------------------------*/
271 /*-----------------------------------------------------------------------*/
272
273
274
275
276 void drawtext_xy(buttonWindow win, GC gc, XFontStruct *font_info_local, char text[], int width, int height)
277 {
278 /* x, y specified version of drawtext()
279 *
280 */
281
282 int len_text, width_text;
283
284 len_text = strlen(text);
285 width_text = XTextWidth(font_info_local, text, len_text);
286
287 XDrawString(display, win.win, gc, (width - width_text)/2, \
288 (height + font_info_local->ascent-1)/2, text, len_text);
289
290 }
291
292
293
294
295 /*-------------------------------------------------------------------------*/
296 /*-------------------------------------------------------------------------*/
297
298
299
300
301 void drawbutton(toplevelWindow top_win, buttonWindow button_local, GC *button_local_gc, char *text, int fill_colour, int border_colour)
302 {
303 int width = button_local.width;
304 int height = button_local.height;
305
306 /* Draw shadow */
307 XSetForeground(display, *button_local_gc, border_colour);
308 XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1,
309 width-2, height-2, 5, 5);
310 XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1,
311 width-2, height-2, 5, 5);
312
313 /* Draw button */
314 XSetForeground(display, *button_local_gc, fill_colour);
315 XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 0, 0,
316 width-2, height-2, 5, 5);
317 XSetForeground(display, *button_local_gc, border_colour);
318 XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 0, 0,
319 width-2, height-2, 5, 5);
320
321 /* Draw text: border_colour */
322 drawtext(button_local, *button_local_gc, font_info, text);
323
324 XFlush(display);
325 }
326
327
328
329
330 /*-------------------------------------------------------------------------*/
331 /*-------------------------------------------------------------------------*/
332
333
334
335
336 void flashbutton(toplevelWindow top_win, buttonWindow button_local, GC *button_local_gc, char *text)
337 {
338 int width = button_local.width;
339 int height = button_local.height;
340 long starttime;
341 int flashtime = FLASHTIME; /* msecs */
342
343 /* Redraw button where the shadow used to be */
344 XClearWindow(display, button_local.win);
345 XSetForeground(display, *button_local_gc, WhitePixel(display, screen_num));
346 XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1,
347 width-2, height-2, 5, 5);
348 XSetForeground(display, *button_local_gc, BlackPixel(display, screen_num));
349 XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1,
350 width-2, height-2, 5, 5);
351
352 /* Redraw the text */
353 drawtext_xy(button_local, *button_local_gc, font_info, \
354 text, width+2, height+2);
355 XFlush(display);
356
357 /* Wait ... */
358 starttime = (long) clock();
359 while ((clock() - starttime) <= (flashtime * 1000))
360 ;
361
362 /* Draw the old button */
363 drawbutton(top_win, button_local, button_local_gc, text,\
364 WhitePixel(display, screen_num), BlackPixel(display, screen_num));
365
366 }
367
368
369
370 /* The end.*/
371 /*-------------------------------------------------------------------------*/
372 /*-------------------------------------------------------------------------*/
373