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