view xaim/switch_axes.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.
*/

/* 
*   switch_axes.c
*   -------------
*  'switch' code for the axes (=cartoon image) window.
*
*  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"



/* General .................*/


/* X ........................*/

extern Display *display;
extern int screen_num;
extern Screen *screen_ptr;

extern toplevelWindow control;
extern toplevelWindow axes;
extern buttonWindow info_speed, info_frame;
extern XFontStruct font_info;

extern XEvent report;
extern GC button_gc;


/* .ctn .....................*/

extern int frame;
extern int no_frames;

extern int animate_start;
extern int animate_stop;
extern int animate_skip;

extern long waittime_millisecs;


/* extras for the pcroy version */
extern int animate_start;
extern int animate_stop;
extern int animate_skip;

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/





void switch_axes()
{
  char tempstring[MAX_STRING_LENGTH];
  char buffer[20];
  int bufsize = 20;
  int charcount;
  XComposeStatus compose_X;
  KeySym keysym_X;

  switch(report.type) {
    
/*---------------------------------------------*/

  case Expose:
    if (report.xexpose.count != 0)
      break;
	
    if ((axes.window_size == TOO_SMALL_X) ||
	(axes.window_size == TOO_BIG_X))
      break;

    drawimage(frame); 
    break;
    
/*---------------------------------------------*/
	
  case ConfigureNotify:
    axes.width = report.xconfigure.width;
    axes.height = report.xconfigure.height;

    /* No resizing allowed */
    axes.window_size = BIG_ENOUGH_X;
    if ((axes.width < axes.size_hints.min_width) || \
	(axes.height < axes.size_hints.min_height))
      axes.window_size = TOO_SMALL_X;
    if ((axes.width > axes.size_hints.max_width) || \
	(axes.height > axes.size_hints.max_height))
      axes.window_size = TOO_BIG_X;
    break;
	
/*---------------------------------------------*/

  case ButtonPress:
    
    /* if button 1, animate */
    if (report.xbutton.button == Button1)  {
      animate_image(animate_start, animate_stop, animate_skip);
      break;}

    /* if button 2, map control window */
    if (report.xbutton.button == Button2)  {
      XMapWindow(display, control.win); 
      break;}
    
    /* If button 3, quit. */
    if (report.xbutton.button == Button3)  {
      exit_xreview(); 
    }
    
    break;

/*---------------------------------------------*/
	
  case KeyPress:
    
    charcount = XLookupString(&report.xkey, buffer, bufsize, &keysym_X, &compose_X);
    
    if ((keysym_X == XK_space) || (keysym_X == XK_Return)) {
      animate_image(animate_start, animate_stop, animate_skip);
      break;}

    if ((keysym_X == XK_N) || (keysym_X == XK_n)) {
      frame++;
      if (frame > no_frames) 
        frame = no_frames;
      drawimage(frame);
      XClearWindow(display, info_frame.win);
      sprintf(tempstring, "%i of %i", frame, no_frames);
      drawtext(info_frame, button_gc, font_info, tempstring);
      XFlush(display);}

    if ((keysym_X == XK_p) || (keysym_X == XK_p)) {
      frame--;
      if (frame < 1) 
        frame = 1;
      drawimage(frame);
      XClearWindow(display, info_frame.win);
      sprintf(tempstring, "%i of %i", frame, no_frames);
      drawtext(info_frame, button_gc, font_info, tempstring);
      XFlush(display);}

    if ((keysym_X == XK_F)|| (keysym_X == XK_f)){
      waittime_millisecs = (long) waittime_millisecs / 2;
#ifndef HOST_LINUXPC
      if (waittime_millisecs < 1)
	waittime_millisecs = 1;
#endif
      sprintf(tempstring, "Speed: %li", waittime_millisecs);
      XClearWindow(display, info_speed.win);
      drawtext(info_speed, button_gc, font_info, tempstring);
      XFlush(display);
      break;}

    if ((keysym_X == XK_S)|| (keysym_X == XK_s)){
#ifndef HOST_LINUXPC
      waittime_millisecs = (long) waittime_millisecs * 2;
#endif
      sprintf(tempstring, "Speed: %li", waittime_millisecs);
      XClearWindow(display, info_speed.win);
      drawtext(info_speed, button_gc, font_info, tempstring);
      XFlush(display);
      break;}
   
    if ((keysym_X == XK_q) || (keysym_X == XK_Q)) {
      exit_xreview(); }
       
    break;

/*---------------------------------------------*/
    
  default:
    break;

    
  } /* switch */

}




/* The End */
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/