Debian Codegraph @

cmd/smyrna/hotkeymap.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #include "config.h"
12
13 #include "hotkeymap.h"
14 #include <stdint.h>
15 #include <util/alloc.h>
16
17 static int get_mouse_mode(const char *s)
18 {
19 if (strcmp(s, "MM_PAN") == 0)
20 return MM_PAN;
21 if (strcmp(s, "MM_ZOOM") == 0)
22 return MM_ZOOM;
23 if (strcmp(s, "MM_ROTATE") == 0)
24 return MM_ROTATE;
25 if (strcmp(s, "MM_SINGLE_SELECT") == 0)
26 return MM_SINGLE_SELECT;
27 if (strcmp(s, "MM_RECTANGULAR_SELECT") == 0)
28 return MM_RECTANGULAR_SELECT;
29 if (strcmp(s, "MM_RECTANGULAR_X_SELECT") == 0)
30 return MM_RECTANGULAR_X_SELECT;
31
32 if (strcmp(s, "MM_POLYGON_SELECT") == 0)
33 return MM_POLYGON_SELECT;
34
35 if (strcmp(s, "MM_MOVE") == 0)
36 return MM_MOVE;
37 if (strcmp(s, "MM_MOVE") == 0)
38 return MM_MOVE;
39 if (strcmp(s, "MM_MAGNIFIER") == 0)
40 return MM_MAGNIFIER;
41 if (strcmp(s, "MM_FISHEYE_MAGNIFIER") == 0)
42 return MM_FISHEYE_MAGNIFIER;
43 if (strcmp(s, "MM_FISHEYE_PICK") == 0)
44 return MM_FISHEYE_PICK;
45
46 return -1;
47 }
48
49 static int get_button(const char *s)
50 {
51 if(view->guiMode != GUI_FULLSCREEN)
52 {
53 if (strcmp(s, "B_LSHIFT") == 0)
54 return B_LSHIFT;
55 if (strcmp(s, "B_RSHIFT") == 0)
56 return B_RSHIFT;
57 if (strcmp(s, "B_LCTRL") == 0)
58 return B_LCTRL;
59 if (strcmp(s, "B_RCTRL") == 0)
60 return B_RCTRL;
61 if (strcmp(s, "0") == 0)
62 return 0;
63 }
64 else
65 {
66 int mod = glutGetModifiers();
67 if (mod == GLUT_ACTIVE_ALT)
68
69 if (strcmp(s, "B_LSHIFT") == 0)
70 return GLUT_ACTIVE_SHIFT;
71 if (strcmp(s, "B_RSHIFT") == 0)
72 return GLUT_ACTIVE_SHIFT;
73 if (strcmp(s, "B_LCTRL") == 0)
74 return GLUT_ACTIVE_CTRL;
75 if (strcmp(s, "B_RCTRL") == 0)
76 return GLUT_ACTIVE_CTRL;
77 if (strcmp(s, "0") == 0)
78 return 0;
79 }
80 return 0;
81 }
82
83 static int get_view_mode(const char *s)
84 {
85 if (strcmp(s, "ALL") == 0)
86 return smyrna_all;
87 if (strcmp(s, "2D") == 0)
88 return smyrna_2D;
89 if (strcmp(s, "3D") == 0)
90 return smyrna_3D;
91 if (strcmp(s, "FISHEYE") == 0)
92 return smyrna_fisheye;
93 if (strcmp(s, "NO_FISHEYE") == 0)
94 return smyrna_all_but_fisheye;
95 return -1;
96 }
97
98 static int get_mouse_button(const char *s)
99 {
100
101 if (strcmp(s, "LEFT") == 0)
102 return glMouseLeftButton;
103 if (strcmp(s, "RIGHT") == 0)
104 return glMouseRightButton;
105 if (strcmp(s, "MIDDLE") == 0)
106 return glMouseMiddleButton;
107 return -1;
108 }
109
110 static int get_drag(const char *s)
111 {
112 if (s[0] == '1')
113 return 1;
114 return 0;
115 }
116
117 void load_mouse_actions(ViewInfo * v)
118 {
119 // file parsing is temporarily not available
120 int i = 0;
121 FILE *file;
122 char linebuf[BUFSIZ];
123 char *a;
124 char *action_file = smyrnaPath("mouse_actions.txt");
125 file = fopen(action_file, "r");
126 if (file != NULL) {
127 int ind = 0;
128 while (fgets(linebuf, BUFSIZ, file) != NULL) {
129 int idx = 0;
130 a = strtok(linebuf, ",");
131
132 if (linebuf[0] == '#' || linebuf[0] == ' ' || strlen(linebuf) == 0)
133 continue;
134
135 v->mouse_actions = gv_recalloc(v->mouse_actions, v->mouse_action_count,
136 v->mouse_action_count + 1,
137 sizeof(mouse_action_t));
138 v->mouse_action_count++;
139 v->mouse_actions[ind].action = get_mouse_mode(a);
140 v->mouse_actions[ind].index = i;
141
142 while ((a = strtok(NULL, ","))) {
143 //#Action(0),hotkey(1),view_mode(2),mouse_button(3),drag(4)
144 switch (idx) {
145 case 0:
146 v->mouse_actions[ind].hotkey = get_button(a);
147 break;
148 case 1:
149 v->mouse_actions[ind].mode = get_view_mode(a);
150 break;
151 case 2:
152 v->mouse_actions[ind].type = get_mouse_button(a);
153 break;
154 case 3:
155 v->mouse_actions[ind].drag = get_drag(a);
156 break;
157
158 }
159 idx++;
160 }
161 ind++;
162 }
163 fclose(file);
164 }
165 free(action_file);
166 }
167
168 int get_mode(ViewInfo * v)
169 {
170 glMouseButtonType curMouseType = v->mouse.t;
171 int curDragging = v->mouse.dragX != 0 || v->mouse.dragY != 0;
172 smyrna_view_mode view_mode;
173 view_mode = smyrna_2D;
174 if (v->active_camera != SIZE_MAX)
175 view_mode = smyrna_3D;
176 if (v->Topview->fisheyeParams.active)
177 view_mode = smyrna_fisheye;
178
179
180 for (size_t ind = 0; ind < v->mouse_action_count; ind++) {
181
182 if (v->mouse_actions[ind].hotkey == v->keyVal
183 && v->mouse_actions[ind].type == curMouseType
184 && v->mouse_actions[ind].drag == curDragging
185 &&
186 (v->mouse_actions[ind].mode == view_mode
187 || v->mouse_actions[ind].mode == smyrna_all
188 || (v->mouse_actions[ind].mode == smyrna_all_but_fisheye
189 && view_mode != smyrna_fisheye)
190 )) {
191 return v->mouse_actions[ind].action;
192
193 }
194 }
195 return -1;
196 }