-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeypress.c
217 lines (213 loc) · 6.45 KB
/
keypress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* keypress.c
*
* The KeyPress event handler for Xdisp.
*
* Handle_KeyPress()
*
* Copyright Bruce Pike, 1993-2000
*/
#include "xdisp.h"
/*---------------------------- Handle_KeyPress ----------------------*/
void Handle_KeyPress(XEvent *event)
{
XKeyEvent *key_event = (XKeyEvent *) event;
char buf[128];
KeySym ks;
XComposeStatus status;
int w, h, btmp, dw, dh;
/* initialize the input string */
buf[0]=0;
/* do it */
XLookupString(key_event,buf,128,&ks,&status);
if (buf[0]=='q' || buf[0]=='Q') Quit();
else if (buf[0]=='h' || buf[0]=='H' || buf[0]=='?') Open_Help_Widget();
else if (buf[0]=='b') Toggle_ColorBar();
else if (buf[0]=='i') Toggle_Interpolation();
else if (buf[0]=='C') Switch_Colormap();
else if (buf[0]=='v' || buf[0]=='V')
fprintf(stderr,"xdisp: %s\n",version);
else if (buf[0]=='c') Crop();
else if (buf[0]=='r') Rescale();
else if (buf[0]=='w') Show_Window_Level();
else if (buf[0]=='s') roi_stats(0,0,Width-1,Height-1,0);
else if (buf[0]=='a') Auto_Scale();
else if (buf[0]=='p') ps_file((caddr_t)&zero);
else if (buf[0]=='P') {
if (!(plot_active==-1)) {
Refresh();
plot_active = -1;
if ((plot_roi_size == 0)&&((zWidth<=Width)||(zHeight<=Height))) { /* draw a small cross hair */
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x-5,theEvent.xmotion.y,
theEvent.xmotion.x+5,theEvent.xmotion.y);
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x,theEvent.xmotion.y-5,
theEvent.xmotion.x,theEvent.xmotion.y+5);
}
else { /* draw a box */
dw = (int)floor(((float)((plot_roi_size*2 + 1)*zWidth) / (float)(Width*2))+0.5);
dh = (int)floor(((float)((plot_roi_size*2 + 1)*zWidth) / (float)(Width*2))+0.5);
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x-dw, theEvent.xmotion.y-dh,
theEvent.xmotion.x+dw, theEvent.xmotion.y-dh);
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x+dw, theEvent.xmotion.y-dh,
theEvent.xmotion.x+dw, theEvent.xmotion.y+dh);
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x+dw, theEvent.xmotion.y+dh,
theEvent.xmotion.x-dw, theEvent.xmotion.y+dh);
XDrawLine(theDisp,mainW,grGC,
theEvent.xmotion.x-dw, theEvent.xmotion.y+dh,
theEvent.xmotion.x-dw, theEvent.xmotion.y-dh);
}
}
else {
Open_Plot_Widget();
}
}
else if (buf[0]=='f' || buf[0]=='F') ps_file((caddr_t)&one);
else if (buf[0]=='e' || buf[0]=='E') ps_file((caddr_t)&two);
else if (buf[0]=='G') graphics_file((caddr_t)&gr_gif);
else if (buf[0]=='T') graphics_file((caddr_t)&gr_tiff);
else if (buf[0]=='B') flat_file((caddr_t)&zero);
else if (buf[0]=='S') flat_file((caddr_t)&one);
else if (buf[0]=='l') Load_All();
else if (buf[0]=='m') MIP();
else if (buf[0]=='M') matlab_file();
else if (buf[0]=='t') toggle();
else if (buf[0]=='o') Reorient_Volume();
else if (buf[0]=='U') Open_Input_Widget("Upper:");
else if (buf[0]=='L') Open_Input_Widget("Lower:");
else if (buf[0]=='d'){ /* cycle current volume dimension */
current_dim = (current_dim+1)%(ndimensions-2);
if (Verbose)
fprintf(stderr,"Current dimension: %d\n", current_dim);
}
else if (buf[0]=='+') { /* increment image */
if (slider_image[current_dim]<slider_length[current_dim]-1){
image_increment=1;
} else {
image_increment=-(slider_length[current_dim]-1);
}
New_Image();
}
else if (buf[0]=='-') { /* decrement image */
if (slider_image[current_dim]>0){
image_increment=-1;
} else {
image_increment=slider_length[current_dim]-1;
}
New_Image();
}
else if (buf[0]=='*') { /* increment image by 10 */
image_increment=10;
New_Image();
}
else if (buf[0]=='/') { /* decrement image by 10 */
image_increment=-10;
New_Image();
}
else if (buf[0]=='R') { /* refresh */
btmp = ext_roi_on;
ext_roi_on = FALSE;
DrawWindow(0,0,zWidth,zHeight);
ext_roi_on = btmp;
}
else if (buf[0]=='u') { /* unzoom image to original size */
w = Width;
h = Height;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='n' || buf[0]=='I') Reload();
else if (buf[0]=='z') { /* zoom down */
w = zWidth/2>0 ? zWidth/2 : zWidth;
h = zHeight/2>0 ? zHeight/2 : zHeight;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='Z') { /* zoom up */
w = zWidth*2;
h = zHeight*2;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='x') { /* zoom down x */
w = zWidth/2>0 ? zWidth/2 : zWidth;
h = zHeight;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='X') { /* zoom up x */
w = zWidth*2;
h = zHeight;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='y') { /* zoom down y */
w = zWidth;
h = zHeight/2>0 ? zHeight/2 : zHeight;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='Y') { /* zoom up y */
w = zWidth;
h = zHeight*2;
Resize(w,h);
XResizeWindow(theDisp,mainW,
w+(color_bar?color_bar_width:0),
h+info_height);
}
else if (buf[0]=='') { /* load new file in current xdisp window */
Open_File_Selector_Widget((caddr_t)&zero);
}
else if (buf[0]=='') { /* load new file and spawn new xdisp */
Open_File_Selector_Widget((caddr_t)&one);
}
else if (buf[0]==' ') { /* ^I open mincheader info window */
Open_Info_Widget();
}
else if (buf[0]=='') { /* flip image about x */
Flip_Image((caddr_t)&zero);
}
else if (buf[0]=='') { /* flip image about y */
Flip_Image((caddr_t)&one);
}
else if (buf[0]=='') TIC(); /* display a TIC */
else if (buf[0]=='') { /* rotate image clockwise */
Rotate_Image();
}
else if (buf[0]=='') { /* write clipped byte image */
flat_file((caddr_t)&two);
}
else if (buf[0]=='') { /* display horizontal profile */
H_Profile_Swicth();
}
else if (buf[0]=='') { /* display vertical profile */
V_Profile_Swicth();
}
else if (buf[0]=='') { /* display external ROIs*/
if ( ext_roi_on ) {
ext_roi_on = FALSE;
DrawWindow(0,0,zWidth,zHeight);
}
else {
ext_roi_on = TRUE;
draw_ext_roi(0,NULL,0,0);
}
}
buf[0]=0;
}