Graphviz 12.0.1~dev.20240716.0800
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 <cgraph/alloc.h>
12#include "hotkeymap.h"
13#include <stdint.h>
14
15static int get_mouse_mode(const char *s)
16{
17 if (strcmp(s, "MM_PAN") == 0)
18 return MM_PAN;
19 if (strcmp(s, "MM_ZOOM") == 0)
20 return MM_ZOOM;
21 if (strcmp(s, "MM_ROTATE") == 0)
22 return MM_ROTATE;
23 if (strcmp(s, "MM_SINGLE_SELECT") == 0)
24 return MM_SINGLE_SELECT;
25 if (strcmp(s, "MM_RECTANGULAR_SELECT") == 0)
27 if (strcmp(s, "MM_RECTANGULAR_X_SELECT") == 0)
29
30 if (strcmp(s, "MM_POLYGON_SELECT") == 0)
31 return MM_POLYGON_SELECT;
32
33 if (strcmp(s, "MM_MOVE") == 0)
34 return MM_MOVE;
35 if (strcmp(s, "MM_MOVE") == 0)
36 return MM_MOVE;
37 if (strcmp(s, "MM_MAGNIFIER") == 0)
38 return MM_MAGNIFIER;
39 if (strcmp(s, "MM_FISHEYE_MAGNIFIER") == 0)
41 if (strcmp(s, "MM_FISHEYE_PICK") == 0)
42 return MM_FISHEYE_PICK;
43
44 return -1;
45}
46
47static int get_button(const char *s)
48{
50 {
51 if (strcmp(s, "B_LSHIFT") == 0)
52 return B_LSHIFT;
53 if (strcmp(s, "B_RSHIFT") == 0)
54 return B_RSHIFT;
55 if (strcmp(s, "B_LCTRL") == 0)
56 return B_LCTRL;
57 if (strcmp(s, "B_RCTRL") == 0)
58 return B_RCTRL;
59 if (strcmp(s, "0") == 0)
60 return 0;
61 }
62 else
63 {
64 int mod = glutGetModifiers();
65 if (mod == GLUT_ACTIVE_ALT)
66
67 if (strcmp(s, "B_LSHIFT") == 0)
68 return GLUT_ACTIVE_SHIFT;
69 if (strcmp(s, "B_RSHIFT") == 0)
70 return GLUT_ACTIVE_SHIFT;
71 if (strcmp(s, "B_LCTRL") == 0)
72 return GLUT_ACTIVE_CTRL;
73 if (strcmp(s, "B_RCTRL") == 0)
74 return GLUT_ACTIVE_CTRL;
75 if (strcmp(s, "0") == 0)
76 return 0;
77 }
78 return 0;
79}
80
81static int get_view_mode(const char *s)
82{
83 if (strcmp(s, "ALL") == 0)
84 return smyrna_all;
85 if (strcmp(s, "2D") == 0)
86 return smyrna_2D;
87 if (strcmp(s, "3D") == 0)
88 return smyrna_3D;
89 if (strcmp(s, "FISHEYE") == 0)
90 return smyrna_fisheye;
91 if (strcmp(s, "NO_FISHEYE") == 0)
93 return -1;
94}
95
96static int get_mouse_button(const char *s)
97{
98
99 if (strcmp(s, "LEFT") == 0)
100 return glMouseLeftButton;
101 if (strcmp(s, "RIGHT") == 0)
102 return glMouseRightButton;
103 if (strcmp(s, "MIDDLE") == 0)
104 return glMouseMiddleButton;
105 return -1;
106}
107
108static int get_drag(const char *s)
109{
110 if (s[0] == '1')
111 return 1;
112 return 0;
113}
114
116{
117 // file parsing is temporarily not available
118 int i = 0;
119 FILE *file;
120 char linebuf[BUFSIZ];
121 char *a;
122 char *action_file = smyrnaPath("mouse_actions.txt");
123 file = fopen(action_file, "r");
124 if (file != NULL) {
125 int ind = 0;
126 while (fgets(linebuf, BUFSIZ, file) != NULL) {
127 int idx = 0;
128 a = strtok(linebuf, ",");
129
130 if (linebuf[0] == '#' || linebuf[0] == ' ' || strlen(linebuf) == 0)
131 continue;
132
134 v->mouse_action_count + 1,
135 sizeof(mouse_action_t));
138 v->mouse_actions[ind].index = i;
139
140 while ((a = strtok(NULL, ","))) {
141 //#Action(0),hotkey(1),view_mode(2),mouse_button(3),drag(4)
142 switch (idx) {
143 case 0:
144 v->mouse_actions[ind].hotkey = get_button(a);
145 break;
146 case 1:
147 v->mouse_actions[ind].mode = get_view_mode(a);
148 break;
149 case 2:
151 break;
152 case 3:
153 v->mouse_actions[ind].drag = get_drag(a);
154 break;
155
156 }
157 idx++;
158 }
159 ind++;
160 }
161 fclose(file);
162 }
163 free(action_file);
164}
165
167{
168 glMouseButtonType curMouseType = v->mouse.t;
169 int curDragging = v->mouse.dragX != 0 || v->mouse.dragY != 0;
170 smyrna_view_mode view_mode;
171 view_mode = smyrna_2D;
172 if (v->active_camera != SIZE_MAX)
173 view_mode = smyrna_3D;
175 view_mode = smyrna_fisheye;
176
177
178 for (size_t ind = 0; ind < v->mouse_action_count; ind++) {
179
180 if (v->mouse_actions[ind].hotkey == v->keymap.keyVal
181 && v->mouse_actions[ind].type == curMouseType
182 && v->mouse_actions[ind].drag == curDragging
183 &&
184 (v->mouse_actions[ind].mode == view_mode
185 || v->mouse_actions[ind].mode == smyrna_all
187 && view_mode != smyrna_fisheye)
188 )) {
189 return v->mouse_actions[ind].action;
190
191 }
192 }
193 return -1;
194}
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:89
@ glMouseRightButton
Definition glcompdefs.h:89
@ glMouseMiddleButton
Definition glcompdefs.h:90
@ glMouseLeftButton
Definition glcompdefs.h:89
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:149
int get_mode(ViewInfo *v)
Definition hotkeymap.c:166
static int get_drag(const char *s)
Definition hotkeymap.c:108
void load_mouse_actions(ViewInfo *v)
Definition hotkeymap.c:115
static int get_view_mode(const char *s)
Definition hotkeymap.c:81
static int get_button(const char *s)
Definition hotkeymap.c:47
static int get_mouse_mode(const char *s)
Definition hotkeymap.c:15
static int get_mouse_button(const char *s)
Definition hotkeymap.c:96
#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:68
#define MM_MAGNIFIER
Definition smyrnadefs.h:48
#define GUI_FULLSCREEN
Definition smyrnadefs.h:228
ViewInfo * view
Definition viewport.c:38
#define MM_SINGLE_SELECT
Definition smyrnadefs.h:44
#define MM_RECTANGULAR_X_SELECT
Definition smyrnadefs.h:46
#define MM_ROTATE
Definition smyrnadefs.h:43
#define MM_FISHEYE_PICK
Definition smyrnadefs.h:50
#define MM_RECTANGULAR_SELECT
Definition smyrnadefs.h:45
#define MM_POLYGON_SELECT
Definition smyrnadefs.h:51
#define MM_FISHEYE_MAGNIFIER
Definition smyrnadefs.h:49
smyrna_view_mode
Definition smyrnadefs.h:61
@ smyrna_2D
Definition smyrnadefs.h:61
@ smyrna_all
Definition smyrnadefs.h:61
@ smyrna_fisheye
Definition smyrnadefs.h:61
@ smyrna_all_but_fisheye
Definition smyrnadefs.h:61
@ smyrna_3D
Definition smyrnadefs.h:61
#define MM_ZOOM
Definition smyrnadefs.h:42
#define MM_MOVE
Definition smyrnadefs.h:47
#define MM_PAN
Definition smyrnadefs.h:41
topview * Topview
Definition smyrnadefs.h:334
keymap_t keymap
Definition smyrnadefs.h:366
mouse_action_t * mouse_actions
Definition smyrnadefs.h:367
size_t mouse_action_count
Definition smyrnadefs.h:368
glCompMouse mouse
Definition smyrnadefs.h:321
size_t active_camera
<number of cameras
Definition smyrnadefs.h:328
glMouseButtonType t
Definition glcompdefs.h:278
int keyVal
Definition smyrnadefs.h:65
smyrna_view_mode mode
Definition smyrnadefs.h:146
glMouseButtonType type
Definition smyrnadefs.h:144
int active
Definition smyrnadefs.h:239
struct topview::@55 fisheyeParams
Definition grammar.c:93