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