Graphviz 14.1.2~dev.20260118.1035
Loading...
Searching...
No Matches
hotkeymap.c
Go to the documentation of this file.
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
17static 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)
29 if (strcmp(s, "MM_RECTANGULAR_X_SELECT") == 0)
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)
43 if (strcmp(s, "MM_FISHEYE_PICK") == 0)
44 return MM_FISHEYE_PICK;
45
46 return -1;
47}
48
49static int get_button(const char *s)
50{
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
83static 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)
95 return -1;
96}
97
98static 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
110static int get_drag(const char *s)
111{
112 if (s[0] == '1')
113 return 1;
114 return 0;
115}
116
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
136 v->mouse_action_count + 1,
137 sizeof(mouse_action_t));
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:
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
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;
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
189 && view_mode != smyrna_fisheye)
190 )) {
191 return v->mouse_actions[ind].action;
192
193 }
194 }
195 return -1;
196}
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
Definition alloc.h:73
glMouseButtonType
Definition glcompdefs.h:67
@ glMouseRightButton
Definition glcompdefs.h:67
@ glMouseMiddleButton
Definition glcompdefs.h:68
@ glMouseLeftButton
Definition glcompdefs.h:67
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:181
int get_mode(ViewInfo *v)
Definition hotkeymap.c:168
static int get_drag(const char *s)
Definition hotkeymap.c:110
void load_mouse_actions(ViewInfo *v)
Definition hotkeymap.c:117
static int get_view_mode(const char *s)
Definition hotkeymap.c:83
static int get_button(const char *s)
Definition hotkeymap.c:49
static int get_mouse_mode(const char *s)
Definition hotkeymap.c:17
static int get_mouse_button(const char *s)
Definition hotkeymap.c:98
#define B_RCTRL
Definition hotkeymap.h:18
#define B_RSHIFT
Definition hotkeymap.h:16
#define B_LSHIFT
Definition hotkeymap.h:15
#define B_LCTRL
Definition hotkeymap.h:17
char * smyrnaPath(char *suffix)
Definition main.c:51
#define MM_MAGNIFIER
Definition smyrnadefs.h:46
#define GUI_FULLSCREEN
Definition smyrnadefs.h:203
ViewInfo * view
Definition viewport.c:40
#define MM_SINGLE_SELECT
Definition smyrnadefs.h:42
#define MM_RECTANGULAR_X_SELECT
Definition smyrnadefs.h:44
#define MM_ROTATE
Definition smyrnadefs.h:41
#define MM_FISHEYE_PICK
Definition smyrnadefs.h:48
#define MM_RECTANGULAR_SELECT
Definition smyrnadefs.h:43
#define MM_POLYGON_SELECT
Definition smyrnadefs.h:49
#define MM_FISHEYE_MAGNIFIER
Definition smyrnadefs.h:47
smyrna_view_mode
Definition smyrnadefs.h:59
@ smyrna_2D
Definition smyrnadefs.h:59
@ smyrna_all
Definition smyrnadefs.h:59
@ smyrna_fisheye
Definition smyrnadefs.h:59
@ smyrna_all_but_fisheye
Definition smyrnadefs.h:59
@ smyrna_3D
Definition smyrnadefs.h:59
#define MM_ZOOM
Definition smyrnadefs.h:40
#define MM_MOVE
Definition smyrnadefs.h:45
#define MM_PAN
Definition smyrnadefs.h:39
topview * Topview
Definition smyrnadefs.h:305
int keyVal
depressed key or 0 if none
Definition smyrnadefs.h:332
mouse_action_t * mouse_actions
customizable mouse interaction list
Definition smyrnadefs.h:333
size_t mouse_action_count
Definition smyrnadefs.h:334
glCompMouse mouse
Definition smyrnadefs.h:295
size_t active_camera
<number of cameras
Definition smyrnadefs.h:299
glMouseButtonType t
Definition glcompdefs.h:223
smyrna_view_mode mode
Definition smyrnadefs.h:126
glMouseButtonType type
Definition smyrnadefs.h:124
struct topview::@22 fisheyeParams
int active
Definition smyrnadefs.h:214
Definition grammar.c:90