tomwalters@0: /* tomwalters@0: Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 tomwalters@0: =========================================================================== tomwalters@0: tomwalters@0: Permission to use, copy, modify, and distribute this software without fee tomwalters@0: is hereby granted for research purposes, provided that this copyright tomwalters@0: notice appears in all copies and in all supporting documentation, and that tomwalters@0: the software is not redistributed for any fee (except for a nominal tomwalters@0: shipping charge). Anyone wanting to incorporate all or part of this tomwalters@0: software in a commercial product must obtain a license from the Medical tomwalters@0: Research Council. tomwalters@0: tomwalters@0: The MRC makes no representations about the suitability of this tomwalters@0: software for any purpose. It is provided "as is" without express or tomwalters@0: implied warranty. tomwalters@0: tomwalters@0: THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING tomwalters@0: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL tomwalters@0: THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES tomwalters@0: OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, tomwalters@0: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, tomwalters@0: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS tomwalters@0: SOFTWARE. tomwalters@0: */ tomwalters@0: tomwalters@0: /* tomwalters@0: * graphics.c tomwalters@0: * ---------- tomwalters@0: * Draws things ... tomwalters@0: * tomwalters@0: * NB: The method used for timing the animations (display a frame, wait until tomwalters@0: * the clock has got above some threshold, display the next frame) doesn't tomwalters@0: * seem to work on the linux 396 pc. Thus, it is ALL removed. This means tomwalters@0: * you can't change the speed of that's animations. tomwalters@0: * The 'flashtime' of the Control Buttons is also removed. tomwalters@0: * For speed reasons, the bit that keeps the frame-nbumber in sync with tomwalters@0: * the animations is also removed from the linux version (in animate_image) tomwalters@0: * tomwalters@0: * M. Akeroyd. July 1993. version 1.10 tomwalters@0: * Revisions: MAA Christmas 1993. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: #include tomwalters@0: tomwalters@0: #include "xreview.h" tomwalters@0: tomwalters@0: #define FLASHTIME 200 /* how long to flash a button for, in msecs. tomwalters@0: * 200 works very well on a Sparc or DECStation. tomwalters@0: * The linux 386 pc doesn't like counting times, tomwalters@0: * so is therefore 0. */ tomwalters@0: #ifdef HOST_SPARC tomwalters@0: #define FLASHTIME 200 tomwalters@0: #endif tomwalters@0: #ifdef HOST_DECSTATION tomwalters@0: #define FLASHTIME 200 tomwalters@0: #endif tomwalters@0: #ifdef HOST_LINUXPC tomwalters@0: #define FLASHTIME 0 tomwalters@0: #endif tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void drawtext(buttonWindow win, GC gc, XFontStruct *font_info_local, char *text); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* General variables ....*/ tomwalters@0: tomwalters@0: extern char progname[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: extern char *data_pointer; tomwalters@0: extern char *data_pointer_sideways; tomwalters@0: extern long location[MAX_FRAMES]; tomwalters@0: extern FILE *inputfp; tomwalters@0: extern char inputfn[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: extern int sidewaysflag; tomwalters@0: tomwalters@0: tomwalters@0: /* X ....................*/ tomwalters@0: tomwalters@0: extern char display_name[MAX_STRING_LENGTH]; tomwalters@0: extern char fontname[MAX_STRING_LENGTH]; tomwalters@0: tomwalters@0: extern Display *display; tomwalters@0: extern int screen_num; tomwalters@0: extern Screen *screen_ptr; tomwalters@0: extern int depth; tomwalters@0: extern unsigned int display_width, display_height; tomwalters@0: tomwalters@0: extern toplevelWindow control; tomwalters@0: extern toplevelWindow axes; tomwalters@0: extern buttonWindow info_frame; tomwalters@0: extern XImage *reviewimage; tomwalters@0: tomwalters@0: extern XFontStruct *font_info; tomwalters@0: extern GC button_gc; tomwalters@0: tomwalters@0: tomwalters@0: /* .ctn ..................*/ tomwalters@0: tomwalters@0: extern int no_frames; tomwalters@0: extern int frame; tomwalters@0: extern long waittime_millisecs; tomwalters@0: extern long waittime_microsecs; tomwalters@0: tomwalters@0: tomwalters@0: /* Command line ..........*/ tomwalters@0: tomwalters@0: extern int verboseflag; tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------*/ tomwalters@0: /*--------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void animate_image(int start, int stop, int skip) tomwalters@0: { tomwalters@0: long localtime; tomwalters@0: char tempstring[100]; tomwalters@0: long address; tomwalters@0: int reviewimage_bytesperline; tomwalters@0: int x, y; tomwalters@0: int tempy, tempx; tomwalters@0: long frameconst, framesize; tomwalters@0: int counter, counter2, counter3; tomwalters@0: long framestop= 100000; tomwalters@0: long limit; tomwalters@0: long ylimit; tomwalters@0: long newaddress; tomwalters@0: long delta; tomwalters@0: long required_bytes; tomwalters@0: long lframe; tomwalters@0: int framenth=1; tomwalters@0: tomwalters@0: waittime_microsecs = (long) waittime_millisecs * 1000; tomwalters@0: tomwalters@0: reviewimage_bytesperline = (int) ((int) ((axes.width -1) / 32) +1) *4; tomwalters@0: tomwalters@0: if (sidewaysflag == ON) { tomwalters@0: framesize = reviewimage_bytesperline * axes.height *depth; tomwalters@0: frameconst = framesize; tomwalters@0: counter =-1; tomwalters@0: counter2 = 0; tomwalters@0: ylimit = axes.height*reviewimage_bytesperline*depth; tomwalters@0: limit= (long) ylimit + no_frames*(frameconst); tomwalters@0: tomwalters@0: address=(long) location[start]; tomwalters@0: delta = axes.height*0; tomwalters@0: tomwalters@0: for (lframe=1; lframe <=framestop; lframe++) { tomwalters@0: if ((ylimit+(framenth*framesize)) >= limit){ tomwalters@0: lframe=framestop+10; tomwalters@0: continue;} tomwalters@0: counter+=1; tomwalters@0: for (y=0; ydata = (char *) address; tomwalters@0: counter2++; tomwalters@0: if (counter2 == skip) { tomwalters@0: counter2=0; tomwalters@0: XPutImage(display, axes.win, axes.gc, reviewimage, \ tomwalters@0: 0, 0, 0, 0, axes.width, axes.height);} tomwalters@0: if ((lframe % 100) == 0) { tomwalters@0: XClearWindow(display, info_frame.win); tomwalters@0: sprintf(tempstring, "%i (%i)", framenth, no_frames); tomwalters@0: drawtext(info_frame, button_gc, font_info, tempstring);}} tomwalters@0: tomwalters@0: required_bytes = no_frames*axes.height*reviewimage_bytesperline*depth; tomwalters@0: for (x=location[0]; x<=location[0]+required_bytes-1; x++) tomwalters@0: data_pointer[x] = data_pointer_sideways[x]; tomwalters@0: XClearWindow(display, info_frame.win); tomwalters@0: sprintf(tempstring, "%i (%i)", no_frames, no_frames); tomwalters@0: drawtext(info_frame, button_gc, font_info, tempstring);} tomwalters@0: tomwalters@0: else { tomwalters@0: for (frame=start; frame<=stop; frame += skip){ tomwalters@0: reviewimage->data = (char *) location[frame]; tomwalters@0: XPutImage(display, axes.win, axes.gc, reviewimage, \ tomwalters@0: 0, 0, 0, 0, axes.width, axes.height); tomwalters@0: /* Since this next bit only seems to work on a Sparc or DECstation, leave tomwalters@0: * it out if we're on a 386 pc tomwalters@0: */ tomwalters@0: #ifndef HOST_LINUXPC tomwalters@0: if (waittime_millisecs > 0) { tomwalters@0: XClearWindow(display, info_frame.win); tomwalters@0: sprintf(tempstring, "%i of %i", frame, no_frames); tomwalters@0: drawtext(info_frame, button_gc, font_info, tempstring);} tomwalters@0: localtime = (long) clock(); tomwalters@0: while (clock() - localtime <= waittime_microsecs) tomwalters@0: ; tomwalters@0: #endif tomwalters@0: } tomwalters@0: frame=stop; tomwalters@0: XClearWindow(display, info_frame.win); tomwalters@0: sprintf(tempstring, "%i of %i", frame, no_frames); tomwalters@0: drawtext(info_frame, button_gc, font_info, tempstring); tomwalters@0: } tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: /*--------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void drawimage(int frame) tomwalters@0: { tomwalters@0: reviewimage->data = (char *) location[frame]; tomwalters@0: tomwalters@0: XPutImage(display, axes.win, axes.gc, reviewimage, 0, 0, 0, 0, axes.width, axes.height); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void drawtext(buttonWindow win, GC gc, XFontStruct *font_info_local, char *text) tomwalters@0: { tomwalters@0: /* tomwalters@0: * Copied off basicwindow.c: place_text () tomwalters@0: * Draws 'text' centered horizontally and vertically in the Window. tomwalters@0: * Well, vertically ish. It looks reasonably centered. tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int len_text, width_text; tomwalters@0: int width = win.width; tomwalters@0: int height = win.height; tomwalters@0: tomwalters@0: len_text = strlen(text); tomwalters@0: width_text = XTextWidth(font_info_local, text, len_text); tomwalters@0: tomwalters@0: XDrawString(display, win.win, gc, (width - width_text)/2, \ tomwalters@0: (height + font_info_local->ascent -1)/2, text, len_text); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*-----------------------------------------------------------------------*/ tomwalters@0: /*-----------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void drawtext_xy(buttonWindow win, GC gc, XFontStruct *font_info_local, char text[], int width, int height) tomwalters@0: { tomwalters@0: /* x, y specified version of drawtext() tomwalters@0: * tomwalters@0: */ tomwalters@0: tomwalters@0: int len_text, width_text; tomwalters@0: tomwalters@0: len_text = strlen(text); tomwalters@0: width_text = XTextWidth(font_info_local, text, len_text); tomwalters@0: tomwalters@0: XDrawString(display, win.win, gc, (width - width_text)/2, \ tomwalters@0: (height + font_info_local->ascent-1)/2, text, len_text); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void drawbutton(toplevelWindow top_win, buttonWindow button_local, GC *button_local_gc, char *text, int fill_colour, int border_colour) tomwalters@0: { tomwalters@0: int width = button_local.width; tomwalters@0: int height = button_local.height; tomwalters@0: tomwalters@0: /* Draw shadow */ tomwalters@0: XSetForeground(display, *button_local_gc, border_colour); tomwalters@0: XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: tomwalters@0: /* Draw button */ tomwalters@0: XSetForeground(display, *button_local_gc, fill_colour); tomwalters@0: XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 0, 0, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: XSetForeground(display, *button_local_gc, border_colour); tomwalters@0: XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 0, 0, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: tomwalters@0: /* Draw text: border_colour */ tomwalters@0: drawtext(button_local, *button_local_gc, font_info, text); tomwalters@0: tomwalters@0: XFlush(display); tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: void flashbutton(toplevelWindow top_win, buttonWindow button_local, GC *button_local_gc, char *text) tomwalters@0: { tomwalters@0: int width = button_local.width; tomwalters@0: int height = button_local.height; tomwalters@0: long starttime; tomwalters@0: int flashtime = FLASHTIME; /* msecs */ tomwalters@0: tomwalters@0: /* Redraw button where the shadow used to be */ tomwalters@0: XClearWindow(display, button_local.win); tomwalters@0: XSetForeground(display, *button_local_gc, WhitePixel(display, screen_num)); tomwalters@0: XmuFillRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: XSetForeground(display, *button_local_gc, BlackPixel(display, screen_num)); tomwalters@0: XmuDrawRoundedRectangle(display, button_local.win, *button_local_gc, 1, 1, tomwalters@0: width-2, height-2, 5, 5); tomwalters@0: tomwalters@0: /* Redraw the text */ tomwalters@0: drawtext_xy(button_local, *button_local_gc, font_info, \ tomwalters@0: text, width+2, height+2); tomwalters@0: XFlush(display); tomwalters@0: tomwalters@0: /* Wait ... */ tomwalters@0: starttime = (long) clock(); tomwalters@0: while ((clock() - starttime) <= (flashtime * 1000)) tomwalters@0: ; tomwalters@0: tomwalters@0: /* Draw the old button */ tomwalters@0: drawbutton(top_win, button_local, button_local_gc, text,\ tomwalters@0: WhitePixel(display, screen_num), BlackPixel(display, screen_num)); tomwalters@0: tomwalters@0: } tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: /* The end.*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: /*-------------------------------------------------------------------------*/ tomwalters@0: