1 /* $Id$Revision: */
2 /* vim:set shiftwidth=4 ts=8: */
3
4 /*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14 #include "hotkeymap.h"
15
get_mouse_mode(const char * s)16 int static get_mouse_mode(const char *s)
17 {
18 if (strcmp(s, "MM_PAN") == 0)
19 return MM_PAN;
20 if (strcmp(s, "MM_ZOOM") == 0)
21 return MM_ZOOM;
22 if (strcmp(s, "MM_ROTATE") == 0)
23 return MM_ROTATE;
24 if (strcmp(s, "MM_SINGLE_SELECT") == 0)
25 return MM_SINGLE_SELECT;
26 if (strcmp(s, "MM_RECTANGULAR_SELECT") == 0)
27 return MM_RECTANGULAR_SELECT;
28 if (strcmp(s, "MM_RECTANGULAR_X_SELECT") == 0)
29 return MM_RECTANGULAR_X_SELECT;
30
31 if (strcmp(s, "MM_POLYGON_SELECT") == 0)
32 return MM_POLYGON_SELECT;
33
34 if (strcmp(s, "MM_MOVE") == 0)
35 return MM_MOVE;
36 if (strcmp(s, "MM_MOVE") == 0)
37 return MM_MOVE;
38 if (strcmp(s, "MM_MAGNIFIER") == 0)
39 return MM_MAGNIFIER;
40 if (strcmp(s, "MM_FISHEYE_MAGNIFIER") == 0)
41 return MM_FISHEYE_MAGNIFIER;
42 if (strcmp(s, "MM_FISHEYE_PICK") == 0)
43 return MM_FISHEYE_PICK;
44
45
46 return -1;
47
48 }
49
50
get_button(const char * s)51 int static get_button(const char *s)
52 {
53 if(view->guiMode != GUI_FULLSCREEN)
54 {
55 if (strcmp(s, "B_LSHIFT") == 0)
56 return B_LSHIFT;
57 if (strcmp(s, "B_RSHIFT") == 0)
58 return B_RSHIFT;
59 if (strcmp(s, "B_LCTRL") == 0)
60 return B_LCTRL;
61 if (strcmp(s, "B_RCTRL") == 0)
62 return B_RCTRL;
63 if (strcmp(s, "0") == 0)
64 return 0;
65 }
66 else
67 {
68 int mod = glutGetModifiers();
69 if (mod == GLUT_ACTIVE_ALT)
70
71 if (strcmp(s, "B_LSHIFT") == 0)
72 return GLUT_ACTIVE_SHIFT;
73 if (strcmp(s, "B_RSHIFT") == 0)
74 return GLUT_ACTIVE_SHIFT;
75 if (strcmp(s, "B_LCTRL") == 0)
76 return GLUT_ACTIVE_CTRL;
77 if (strcmp(s, "B_RCTRL") == 0)
78 return GLUT_ACTIVE_CTRL;
79 if (strcmp(s, "0") == 0)
80 return 0;
81 }
82 return 0;
83
84 }
get_view_mode(const char * s)85 int static get_view_mode(const char *s)
86 {
87 if (strcmp(s, "ALL") == 0)
88 return smyrna_all;
89 if (strcmp(s, "2D") == 0)
90 return smyrna_2D;
91 if (strcmp(s, "3D") == 0)
92 return smyrna_3D;
93 if (strcmp(s, "FISHEYE") == 0)
94 return smyrna_fisheye;
95 if (strcmp(s, "NO_FISHEYE") == 0)
96 return smyrna_all_but_fisheye;
97 return -1;
98 }
get_mouse_button(const char * s)99 int static get_mouse_button(const char *s)
100 {
101
102 if (strcmp(s, "LEFT") == 0)
103 return glMouseLeftButton;
104 if (strcmp(s, "RIGHT") == 0)
105 return glMouseRightButton;
106 if (strcmp(s, "MIDDLE") == 0)
107 return glMouseMiddleButton;
108 return -1;
109 }
get_drag(const char * s)110 int static get_drag(const char *s)
111 {
112 if (s[0] == '1')
113 return 1;
114 return 0;
115 }
116
117
118
load_mouse_actions(char * modefile,ViewInfo * v)119 void load_mouse_actions(char *modefile, ViewInfo * v)
120 {
121 /*#define MM_PAN 0
122 #define MM_ZOOM 1
123 #define MM_ROTATE 2
124 #define MM_SINGLE_SELECT 3
125 #define MM_RECTANGULAR_SELECT 4
126 #define MM_RECTANGULAR_X_SELECT 5
127 #define MM_MOVE 10
128 #define MM_MAGNIFIER 20
129 #define MM_FISHEYE_MAGNIFIER 21*/
130 /*file parsing is temporarrily not available */
131 int i = 0;
132 FILE *file;
133 char line[BUFSIZ];
134 char *a;
135 char *action_file = smyrnaPath("mouse_actions.txt");
136 file = fopen(action_file, "r");
137 if (file != NULL) {
138 int ind = 0;
139 while (fgets(line, BUFSIZ, file) != NULL) {
140 int idx = 0;
141 a = strtok(line, ",");
142
143 if ((line[0] == '#') || (line[0] == ' ')
144 || (strlen(line) == 0))
145 continue;
146
147 v->mouse_action_count++;
148 v->mouse_actions =
149 realloc(v->mouse_actions,
150 v->mouse_action_count * sizeof(mouse_action_t));
151 v->mouse_actions[ind].action = get_mouse_mode(a);
152 v->mouse_actions[ind].index = i;
153
154 while ((a = strtok(NULL, ","))) {
155 //#Action(0),hotkey(1),view_mode(2),mouse_button(3),drag(4)
156 switch (idx) {
157 case 0:
158 v->mouse_actions[ind].hotkey = get_button(a);
159 break;
160 case 1:
161 v->mouse_actions[ind].mode = get_view_mode(a);
162 break;
163 case 2:
164 v->mouse_actions[ind].type = get_mouse_button(a);
165 break;
166 case 3:
167 v->mouse_actions[ind].drag = get_drag(a);
168 break;
169
170 }
171 idx++;
172 }
173 ind++;
174 }
175 fclose(file);
176 }
177 free(action_file);
178
179
180 /*
181 v->mouse_action_count=7;
182 v->mouse_actions=realloc(v->mouse_actions,v->mouse_action_count * sizeof(mouse_action_t));
183 v->mouse_actions[ind].action=MM_PAN;
184 v->mouse_actions[ind].drag=1;
185 v->mouse_actions[ind].hotkey=0;
186 v->mouse_actions[ind].index=ind;
187 v->mouse_actions[ind].mode=smyrna_all;
188 v->mouse_actions[ind].type=glMouseLeftButton;
189
190 ind++;
191
192 v->mouse_actions[ind].action=MM_ROTATE;
193 v->mouse_actions[ind].drag=1;
194 v->mouse_actions[ind].hotkey=B_LSHIFT;
195 v->mouse_actions[ind].index=ind;
196 v->mouse_actions[ind].mode=smyrna_3D;
197 v->mouse_actions[ind].type=glMouseLeftButton;
198
199 ind++;
200
201 v->mouse_actions[ind].action=MM_SINGLE_SELECT;
202 v->mouse_actions[ind].drag=0;
203 v->mouse_actions[ind].hotkey=0;
204 v->mouse_actions[ind].index=ind;
205 v->mouse_actions[ind].mode=smyrna_all_but_fisheye;
206 v->mouse_actions[ind].type=glMouseLeftButton;
207
208 ind++;
209
210 v->mouse_actions[ind].action=MM_RECTANGULAR_SELECT;
211 v->mouse_actions[ind].drag=1;
212 v->mouse_actions[ind].hotkey=0;
213 v->mouse_actions[ind].index=ind;
214 v->mouse_actions[ind].mode=smyrna_all;
215 v->mouse_actions[ind].type=glMouseRightButton;
216
217 ind++;
218
219 v->mouse_actions[ind].action=MM_MOVE;
220 v->mouse_actions[ind].drag=1;
221 v->mouse_actions[ind].hotkey=B_LCTRL;
222 v->mouse_actions[ind].index=ind;
223 v->mouse_actions[ind].mode=smyrna_2D;
224 v->mouse_actions[ind].type=glMouseLeftButton;
225
226 ind++;
227
228 v->mouse_actions[ind].action=MM_FISHEYE_MAGNIFIER;
229 v->mouse_actions[ind].drag=1;
230 v->mouse_actions[ind].hotkey=B_LSHIFT;
231 v->mouse_actions[ind].index=ind;
232 v->mouse_actions[ind].mode=smyrna_2D;
233 v->mouse_actions[ind].type=glMouseLeftButton;
234
235 ind++;
236
237 v->mouse_actions[ind].action=MM_FISHEYE_PICK;
238 v->mouse_actions[ind].drag=0;
239 v->mouse_actions[ind].hotkey=0;
240 v->mouse_actions[ind].index=ind;
241 v->mouse_actions[ind].mode=smyrna_fisheye;
242 v->mouse_actions[ind].type=glMouseRightButton;
243 */
244 }
245
get_key_action(ViewInfo * v,int key)246 int get_key_action(ViewInfo * v, int key)
247 {
248 int ind = 0;
249 for (; ind < v->mouse_action_count; ind++) {
250
251 if (v->mouse_actions[ind].hotkey == key)
252 return v->mouse_actions[ind].action;
253 }
254 return -1;
255 }
256
257
get_mode(ViewInfo * v)258 int get_mode(ViewInfo * v)
259 {
260
261
262 /*#define F_BUTTON1 B_LSHIFT
263 #define F_BUTTON2 B_RSHIFT
264 #define F_BUTTON3 B_LCTRL
265 #define F_BUTTON4 B_LCTRL
266
267 #define MOUSE_BUTTON_1 LEFT_MOUSE_BUTTON
268 #define MOUSE_BUTTON_2 RIGHT_MOUSE_BUTTON
269 #define MOUSE_BUTTON_3 MIDDLE_MOUSE_BUTTON*/
270 //typedef enum {smyrna_2D,smyrna_3D,smyrna_fisheye} smyrna_view_mode;
271 int ind = 0;
272 glMouseButtonType curMouseType = v->mouse.t;
273 int curDragging = ((v->mouse.dragX != 0) || (v->mouse.dragY != 0));
274 smyrna_view_mode view_mode;
275 view_mode = smyrna_2D;
276 if (v->active_camera >= 0)
277 view_mode = smyrna_3D;
278 if (v->Topview->fisheyeParams.active)
279 view_mode = smyrna_fisheye;
280
281
282 for (; ind < v->mouse_action_count; ind++) {
283
284 if ((v->mouse_actions[ind].hotkey == v->keymap.keyVal)
285 && (v->mouse_actions[ind].type == curMouseType)
286 && (v->mouse_actions[ind].drag == curDragging)
287 &&
288 ((v->mouse_actions[ind].mode == view_mode)
289 || (v->mouse_actions[ind].mode == smyrna_all)
290 || ((v->mouse_actions[ind].mode == smyrna_all_but_fisheye)
291 && (view_mode != smyrna_fisheye))
292 )) {
293 return v->mouse_actions[ind].action;
294
295 }
296 }
297 return -1;
298
299
300
301
302
303 /* if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal ==F_BUTTON1) && (view->active_camera==-1))
304 return MM_FISHEYE_MAGNIFIER;
305 if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal == F_BUTTON1) && (view->active_camera>-1))
306 return MM_ROTATE;
307 if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->keymap.down) && (view->keymap.keyVal == F_BUTTON3))
308 return MM_MOVE;
309 if ((view->mouse.t==MOUSE_BUTTON_1)&&(view->mouse.down) )
310 return MM_PAN;
311 if ((view->mouse.t==MOUSE_BUTTON_2)&&(view->mouse.down) )
312 return MM_RECTANGULAR_SELECT;*/
313
314
315
316 }
317