Graphviz
13.0.0~dev.20241220.2304
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 "
hotkeymap.h
"
12
#include <stdint.h>
13
#include <
util/alloc.h
>
14
15
static
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)
26
return
MM_RECTANGULAR_SELECT
;
27
if
(strcmp(
s
,
"MM_RECTANGULAR_X_SELECT"
) == 0)
28
return
MM_RECTANGULAR_X_SELECT
;
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)
40
return
MM_FISHEYE_MAGNIFIER
;
41
if
(strcmp(
s
,
"MM_FISHEYE_PICK"
) == 0)
42
return
MM_FISHEYE_PICK
;
43
44
return
-1;
45
}
46
47
static
int
get_button
(
const
char
*
s
)
48
{
49
if
(
view
->
guiMode
!=
GUI_FULLSCREEN
)
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
81
static
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)
92
return
smyrna_all_but_fisheye
;
93
return
-1;
94
}
95
96
static
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
108
static
int
get_drag
(
const
char
*
s
)
109
{
110
if
(
s
[0] ==
'1'
)
111
return
1;
112
return
0;
113
}
114
115
void
load_mouse_actions
(
ViewInfo
* v)
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
133
v->
mouse_actions
=
gv_recalloc
(v->
mouse_actions
, v->
mouse_action_count
,
134
v->
mouse_action_count
+ 1,
135
sizeof
(
mouse_action_t
));
136
v->
mouse_action_count
++;
137
v->
mouse_actions
[ind].
action
=
get_mouse_mode
(a);
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:
150
v->
mouse_actions
[ind].
type
=
get_mouse_button
(a);
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
166
int
get_mode
(
ViewInfo
* v)
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
;
174
if
(v->
Topview
->
fisheyeParams
.
active
)
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->
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
186
|| (v->
mouse_actions
[ind].
mode
==
smyrna_all_but_fisheye
187
&& view_mode !=
smyrna_fisheye
)
188
)) {
189
return
v->
mouse_actions
[ind].
action
;
190
191
}
192
}
193
return
-1;
194
}
alloc.h
Memory allocation wrappers that exit on failure.
gv_recalloc
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
Definition
alloc.h:73
glMouseButtonType
glMouseButtonType
Definition
glcompdefs.h:67
glMouseRightButton
@ glMouseRightButton
Definition
glcompdefs.h:67
glMouseMiddleButton
@ glMouseMiddleButton
Definition
glcompdefs.h:68
glMouseLeftButton
@ glMouseLeftButton
Definition
glcompdefs.h:67
free
void free(void *)
SIZE_MAX
#define SIZE_MAX
Definition
gmlscan.c:347
NULL
node NULL
Definition
grammar.y:163
get_mode
int get_mode(ViewInfo *v)
Definition
hotkeymap.c:166
get_drag
static int get_drag(const char *s)
Definition
hotkeymap.c:108
load_mouse_actions
void load_mouse_actions(ViewInfo *v)
Definition
hotkeymap.c:115
get_view_mode
static int get_view_mode(const char *s)
Definition
hotkeymap.c:81
get_button
static int get_button(const char *s)
Definition
hotkeymap.c:47
get_mouse_mode
static int get_mouse_mode(const char *s)
Definition
hotkeymap.c:15
get_mouse_button
static int get_mouse_button(const char *s)
Definition
hotkeymap.c:96
hotkeymap.h
B_RCTRL
#define B_RCTRL
Definition
hotkeymap.h:18
B_RSHIFT
#define B_RSHIFT
Definition
hotkeymap.h:16
B_LSHIFT
#define B_LSHIFT
Definition
hotkeymap.h:15
B_LCTRL
#define B_LCTRL
Definition
hotkeymap.h:17
smyrnaPath
char * smyrnaPath(char *suffix)
Definition
main.c:68
MM_MAGNIFIER
#define MM_MAGNIFIER
Definition
smyrnadefs.h:48
GUI_FULLSCREEN
#define GUI_FULLSCREEN
Definition
smyrnadefs.h:211
view
ViewInfo * view
Definition
viewport.c:37
MM_SINGLE_SELECT
#define MM_SINGLE_SELECT
Definition
smyrnadefs.h:44
MM_RECTANGULAR_X_SELECT
#define MM_RECTANGULAR_X_SELECT
Definition
smyrnadefs.h:46
MM_ROTATE
#define MM_ROTATE
Definition
smyrnadefs.h:43
MM_FISHEYE_PICK
#define MM_FISHEYE_PICK
Definition
smyrnadefs.h:50
MM_RECTANGULAR_SELECT
#define MM_RECTANGULAR_SELECT
Definition
smyrnadefs.h:45
MM_POLYGON_SELECT
#define MM_POLYGON_SELECT
Definition
smyrnadefs.h:51
MM_FISHEYE_MAGNIFIER
#define MM_FISHEYE_MAGNIFIER
Definition
smyrnadefs.h:49
smyrna_view_mode
smyrna_view_mode
Definition
smyrnadefs.h:61
smyrna_2D
@ smyrna_2D
Definition
smyrnadefs.h:61
smyrna_all
@ smyrna_all
Definition
smyrnadefs.h:61
smyrna_fisheye
@ smyrna_fisheye
Definition
smyrnadefs.h:61
smyrna_all_but_fisheye
@ smyrna_all_but_fisheye
Definition
smyrnadefs.h:61
smyrna_3D
@ smyrna_3D
Definition
smyrnadefs.h:61
MM_ZOOM
#define MM_ZOOM
Definition
smyrnadefs.h:42
MM_MOVE
#define MM_MOVE
Definition
smyrnadefs.h:47
MM_PAN
#define MM_PAN
Definition
smyrnadefs.h:41
_ViewInfo
Definition
smyrnadefs.h:252
_ViewInfo::Topview
topview * Topview
Definition
smyrnadefs.h:313
_ViewInfo::keyVal
int keyVal
depressed key or 0 if none
Definition
smyrnadefs.h:344
_ViewInfo::guiMode
int guiMode
Definition
smyrnadefs.h:348
_ViewInfo::mouse_actions
mouse_action_t * mouse_actions
customizable mouse interaction list
Definition
smyrnadefs.h:345
_ViewInfo::mouse_action_count
size_t mouse_action_count
Definition
smyrnadefs.h:346
_ViewInfo::mouse
glCompMouse mouse
Definition
smyrnadefs.h:303
_ViewInfo::active_camera
size_t active_camera
<number of cameras
Definition
smyrnadefs.h:307
glCompMouse::dragY
float dragY
Definition
glcompdefs.h:245
glCompMouse::t
glMouseButtonType t
Definition
glcompdefs.h:239
glCompMouse::dragX
float dragX
Definition
glcompdefs.h:245
mouse_action_t
Definition
smyrnadefs.h:123
mouse_action_t::hotkey
int hotkey
Definition
smyrnadefs.h:126
mouse_action_t::drag
int drag
Definition
smyrnadefs.h:128
mouse_action_t::mode
smyrna_view_mode mode
Definition
smyrnadefs.h:129
mouse_action_t::index
int index
Definition
smyrnadefs.h:124
mouse_action_t::type
glMouseButtonType type
Definition
smyrnadefs.h:127
mouse_action_t::action
int action
Definition
smyrnadefs.h:125
topview::active
int active
Definition
smyrnadefs.h:222
topview::fisheyeParams
struct topview::@55 fisheyeParams
s
Definition
grammar.c:93
cmd
smyrna
hotkeymap.c
Generated by
1.9.8