annotate 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
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 * switch_axes.c
tomwalters@0 28 * -------------
tomwalters@0 29 * 'switch' code for the axes (=cartoon image) window.
tomwalters@0 30 *
tomwalters@0 31 * M. Akeroyd. July 1993. version 1.10
tomwalters@0 32 * Revisions: MAA: Christmas 1993.
tomwalters@0 33 */
tomwalters@0 34
tomwalters@0 35
tomwalters@0 36
tomwalters@0 37 #include <X11/Xlib.h>
tomwalters@0 38 #include <X11/Xutil.h>
tomwalters@0 39 #include <X11/Xos.h>
tomwalters@0 40 #include <X11/Xatom.h>
tomwalters@0 41 #include <stdio.h>
tomwalters@0 42
tomwalters@0 43 #include "xreview.h"
tomwalters@0 44
tomwalters@0 45
tomwalters@0 46
tomwalters@0 47 /* General .................*/
tomwalters@0 48
tomwalters@0 49
tomwalters@0 50 /* X ........................*/
tomwalters@0 51
tomwalters@0 52 extern Display *display;
tomwalters@0 53 extern int screen_num;
tomwalters@0 54 extern Screen *screen_ptr;
tomwalters@0 55
tomwalters@0 56 extern toplevelWindow control;
tomwalters@0 57 extern toplevelWindow axes;
tomwalters@0 58 extern buttonWindow info_speed, info_frame;
tomwalters@0 59 extern XFontStruct font_info;
tomwalters@0 60
tomwalters@0 61 extern XEvent report;
tomwalters@0 62 extern GC button_gc;
tomwalters@0 63
tomwalters@0 64
tomwalters@0 65 /* .ctn .....................*/
tomwalters@0 66
tomwalters@0 67 extern int frame;
tomwalters@0 68 extern int no_frames;
tomwalters@0 69
tomwalters@0 70 extern int animate_start;
tomwalters@0 71 extern int animate_stop;
tomwalters@0 72 extern int animate_skip;
tomwalters@0 73
tomwalters@0 74 extern long waittime_millisecs;
tomwalters@0 75
tomwalters@0 76
tomwalters@0 77 /* extras for the pcroy version */
tomwalters@0 78 extern int animate_start;
tomwalters@0 79 extern int animate_stop;
tomwalters@0 80 extern int animate_skip;
tomwalters@0 81
tomwalters@0 82 /*--------------------------------------------------------------------*/
tomwalters@0 83 /*--------------------------------------------------------------------*/
tomwalters@0 84
tomwalters@0 85
tomwalters@0 86
tomwalters@0 87
tomwalters@0 88
tomwalters@0 89 void switch_axes()
tomwalters@0 90 {
tomwalters@0 91 char tempstring[MAX_STRING_LENGTH];
tomwalters@0 92 char buffer[20];
tomwalters@0 93 int bufsize = 20;
tomwalters@0 94 int charcount;
tomwalters@0 95 XComposeStatus compose_X;
tomwalters@0 96 KeySym keysym_X;
tomwalters@0 97
tomwalters@0 98 switch(report.type) {
tomwalters@0 99
tomwalters@0 100 /*---------------------------------------------*/
tomwalters@0 101
tomwalters@0 102 case Expose:
tomwalters@0 103 if (report.xexpose.count != 0)
tomwalters@0 104 break;
tomwalters@0 105
tomwalters@0 106 if ((axes.window_size == TOO_SMALL_X) ||
tomwalters@0 107 (axes.window_size == TOO_BIG_X))
tomwalters@0 108 break;
tomwalters@0 109
tomwalters@0 110 drawimage(frame);
tomwalters@0 111 break;
tomwalters@0 112
tomwalters@0 113 /*---------------------------------------------*/
tomwalters@0 114
tomwalters@0 115 case ConfigureNotify:
tomwalters@0 116 axes.width = report.xconfigure.width;
tomwalters@0 117 axes.height = report.xconfigure.height;
tomwalters@0 118
tomwalters@0 119 /* No resizing allowed */
tomwalters@0 120 axes.window_size = BIG_ENOUGH_X;
tomwalters@0 121 if ((axes.width < axes.size_hints.min_width) || \
tomwalters@0 122 (axes.height < axes.size_hints.min_height))
tomwalters@0 123 axes.window_size = TOO_SMALL_X;
tomwalters@0 124 if ((axes.width > axes.size_hints.max_width) || \
tomwalters@0 125 (axes.height > axes.size_hints.max_height))
tomwalters@0 126 axes.window_size = TOO_BIG_X;
tomwalters@0 127 break;
tomwalters@0 128
tomwalters@0 129 /*---------------------------------------------*/
tomwalters@0 130
tomwalters@0 131 case ButtonPress:
tomwalters@0 132
tomwalters@0 133 /* if button 1, animate */
tomwalters@0 134 if (report.xbutton.button == Button1) {
tomwalters@0 135 animate_image(animate_start, animate_stop, animate_skip);
tomwalters@0 136 break;}
tomwalters@0 137
tomwalters@0 138 /* if button 2, map control window */
tomwalters@0 139 if (report.xbutton.button == Button2) {
tomwalters@0 140 XMapWindow(display, control.win);
tomwalters@0 141 break;}
tomwalters@0 142
tomwalters@0 143 /* If button 3, quit. */
tomwalters@0 144 if (report.xbutton.button == Button3) {
tomwalters@0 145 exit_xreview();
tomwalters@0 146 }
tomwalters@0 147
tomwalters@0 148 break;
tomwalters@0 149
tomwalters@0 150 /*---------------------------------------------*/
tomwalters@0 151
tomwalters@0 152 case KeyPress:
tomwalters@0 153
tomwalters@0 154 charcount = XLookupString(&report.xkey, buffer, bufsize, &keysym_X, &compose_X);
tomwalters@0 155
tomwalters@0 156 if ((keysym_X == XK_space) || (keysym_X == XK_Return)) {
tomwalters@0 157 animate_image(animate_start, animate_stop, animate_skip);
tomwalters@0 158 break;}
tomwalters@0 159
tomwalters@0 160 if ((keysym_X == XK_N) || (keysym_X == XK_n)) {
tomwalters@0 161 frame++;
tomwalters@0 162 if (frame > no_frames)
tomwalters@0 163 frame = no_frames;
tomwalters@0 164 drawimage(frame);
tomwalters@0 165 XClearWindow(display, info_frame.win);
tomwalters@0 166 sprintf(tempstring, "%i of %i", frame, no_frames);
tomwalters@0 167 drawtext(info_frame, button_gc, font_info, tempstring);
tomwalters@0 168 XFlush(display);}
tomwalters@0 169
tomwalters@0 170 if ((keysym_X == XK_p) || (keysym_X == XK_p)) {
tomwalters@0 171 frame--;
tomwalters@0 172 if (frame < 1)
tomwalters@0 173 frame = 1;
tomwalters@0 174 drawimage(frame);
tomwalters@0 175 XClearWindow(display, info_frame.win);
tomwalters@0 176 sprintf(tempstring, "%i of %i", frame, no_frames);
tomwalters@0 177 drawtext(info_frame, button_gc, font_info, tempstring);
tomwalters@0 178 XFlush(display);}
tomwalters@0 179
tomwalters@0 180 if ((keysym_X == XK_F)|| (keysym_X == XK_f)){
tomwalters@0 181 waittime_millisecs = (long) waittime_millisecs / 2;
tomwalters@0 182 #ifndef HOST_LINUXPC
tomwalters@0 183 if (waittime_millisecs < 1)
tomwalters@0 184 waittime_millisecs = 1;
tomwalters@0 185 #endif
tomwalters@0 186 sprintf(tempstring, "Speed: %li", waittime_millisecs);
tomwalters@0 187 XClearWindow(display, info_speed.win);
tomwalters@0 188 drawtext(info_speed, button_gc, font_info, tempstring);
tomwalters@0 189 XFlush(display);
tomwalters@0 190 break;}
tomwalters@0 191
tomwalters@0 192 if ((keysym_X == XK_S)|| (keysym_X == XK_s)){
tomwalters@0 193 #ifndef HOST_LINUXPC
tomwalters@0 194 waittime_millisecs = (long) waittime_millisecs * 2;
tomwalters@0 195 #endif
tomwalters@0 196 sprintf(tempstring, "Speed: %li", waittime_millisecs);
tomwalters@0 197 XClearWindow(display, info_speed.win);
tomwalters@0 198 drawtext(info_speed, button_gc, font_info, tempstring);
tomwalters@0 199 XFlush(display);
tomwalters@0 200 break;}
tomwalters@0 201
tomwalters@0 202 if ((keysym_X == XK_q) || (keysym_X == XK_Q)) {
tomwalters@0 203 exit_xreview(); }
tomwalters@0 204
tomwalters@0 205 break;
tomwalters@0 206
tomwalters@0 207 /*---------------------------------------------*/
tomwalters@0 208
tomwalters@0 209 default:
tomwalters@0 210 break;
tomwalters@0 211
tomwalters@0 212
tomwalters@0 213 } /* switch */
tomwalters@0 214
tomwalters@0 215 }
tomwalters@0 216
tomwalters@0 217
tomwalters@0 218
tomwalters@0 219
tomwalters@0 220 /* The End */
tomwalters@0 221 /*--------------------------------------------------------------------------*/
tomwalters@0 222 /*--------------------------------------------------------------------------*/