File: hotkeymap.c

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (194 lines) | stat: -rw-r--r-- 4,954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Details at https://graphviz.org
 *************************************************************************/

#include "hotkeymap.h"
#include <stdint.h>
#include <util/alloc.h>

static int get_mouse_mode(const char *s)
{
    if (strcmp(s, "MM_PAN") == 0)
	return MM_PAN;
    if (strcmp(s, "MM_ZOOM") == 0)
	return MM_ZOOM;
    if (strcmp(s, "MM_ROTATE") == 0)
	return MM_ROTATE;
    if (strcmp(s, "MM_SINGLE_SELECT") == 0)
	return MM_SINGLE_SELECT;
    if (strcmp(s, "MM_RECTANGULAR_SELECT") == 0)
	return MM_RECTANGULAR_SELECT;
    if (strcmp(s, "MM_RECTANGULAR_X_SELECT") == 0)
	return MM_RECTANGULAR_X_SELECT;

    if (strcmp(s, "MM_POLYGON_SELECT") == 0)
	return MM_POLYGON_SELECT;

    if (strcmp(s, "MM_MOVE") == 0)
	return MM_MOVE;
    if (strcmp(s, "MM_MOVE") == 0)
	return MM_MOVE;
    if (strcmp(s, "MM_MAGNIFIER") == 0)
	return MM_MAGNIFIER;
    if (strcmp(s, "MM_FISHEYE_MAGNIFIER") == 0)
	return MM_FISHEYE_MAGNIFIER;
    if (strcmp(s, "MM_FISHEYE_PICK") == 0)
	return MM_FISHEYE_PICK;

    return -1;
}

static int get_button(const char *s)
{
    if(view->guiMode != GUI_FULLSCREEN)
    {
	if (strcmp(s, "B_LSHIFT") == 0)
	    return B_LSHIFT;
	if (strcmp(s, "B_RSHIFT") == 0)
	    return B_RSHIFT;
	if (strcmp(s, "B_LCTRL") == 0)
	    return B_LCTRL;
	if (strcmp(s, "B_RCTRL") == 0)
	    return B_RCTRL;
	if (strcmp(s, "0") == 0)
	    return 0;
    }
    else
    {
		int mod = glutGetModifiers();
		if (mod == GLUT_ACTIVE_ALT)

	if (strcmp(s, "B_LSHIFT") == 0)
	    return GLUT_ACTIVE_SHIFT;
	if (strcmp(s, "B_RSHIFT") == 0)
	    return GLUT_ACTIVE_SHIFT;
	if (strcmp(s, "B_LCTRL") == 0)
	    return GLUT_ACTIVE_CTRL;
	if (strcmp(s, "B_RCTRL") == 0)
	    return GLUT_ACTIVE_CTRL;
	if (strcmp(s, "0") == 0)
	    return 0;
    }
    return 0;
}

static int get_view_mode(const char *s)
{
    if (strcmp(s, "ALL") == 0)
	return smyrna_all;
    if (strcmp(s, "2D") == 0)
	return smyrna_2D;
    if (strcmp(s, "3D") == 0)
	return smyrna_3D;
    if (strcmp(s, "FISHEYE") == 0)
	return smyrna_fisheye;
    if (strcmp(s, "NO_FISHEYE") == 0)
	return smyrna_all_but_fisheye;
    return -1;
}

static int get_mouse_button(const char *s)
{

    if (strcmp(s, "LEFT") == 0)
	return glMouseLeftButton;
    if (strcmp(s, "RIGHT") == 0)
	return glMouseRightButton;
    if (strcmp(s, "MIDDLE") == 0)
	return glMouseMiddleButton;
    return -1;
}

static int get_drag(const char *s)
{
    if (s[0] == '1')
	return 1;
    return 0;
}

void load_mouse_actions(ViewInfo * v)
{
    // file parsing is temporarily not available
    int i = 0;
    FILE *file;
    char linebuf[BUFSIZ];
    char *a;
    char *action_file = smyrnaPath("mouse_actions.txt");
    file = fopen(action_file, "r");
    if (file != NULL) {
	int ind = 0;
	while (fgets(linebuf, BUFSIZ, file) != NULL) {
	    int idx = 0;
	    a = strtok(linebuf, ",");

	    if (linebuf[0] == '#' || linebuf[0] == ' ' || strlen(linebuf) == 0)
		continue;

	    v->mouse_actions = gv_recalloc(v->mouse_actions, v->mouse_action_count,
	                                   v->mouse_action_count + 1,
	                                   sizeof(mouse_action_t));
	    v->mouse_action_count++;
	    v->mouse_actions[ind].action = get_mouse_mode(a);
	    v->mouse_actions[ind].index = i;

	    while ((a = strtok(NULL, ","))) {
		//#Action(0),hotkey(1),view_mode(2),mouse_button(3),drag(4)
		switch (idx) {
		case 0:
		    v->mouse_actions[ind].hotkey = get_button(a);
		    break;
		case 1:
		    v->mouse_actions[ind].mode = get_view_mode(a);
		    break;
		case 2:
		    v->mouse_actions[ind].type = get_mouse_button(a);
		    break;
		case 3:
		    v->mouse_actions[ind].drag = get_drag(a);
		    break;

		}
		idx++;
	    }
	    ind++;
	}
	fclose(file);
    }
    free(action_file);
}

int get_mode(ViewInfo * v)
{
    glMouseButtonType curMouseType = v->mouse.t;
    int curDragging = v->mouse.dragX != 0 || v->mouse.dragY != 0;
    smyrna_view_mode view_mode;
    view_mode = smyrna_2D;
    if (v->active_camera != SIZE_MAX)
	view_mode = smyrna_3D;
    if (v->Topview->fisheyeParams.active)
	view_mode = smyrna_fisheye;


    for (size_t ind = 0; ind < v->mouse_action_count; ind++) {

	if (v->mouse_actions[ind].hotkey == v->keyVal
	    && v->mouse_actions[ind].type == curMouseType
	    && v->mouse_actions[ind].drag == curDragging
	    &&
	    (v->mouse_actions[ind].mode == view_mode
	     || v->mouse_actions[ind].mode == smyrna_all
	     || (v->mouse_actions[ind].mode == smyrna_all_but_fisheye
		 && view_mode != smyrna_fisheye)
	    )) {
	    return v->mouse_actions[ind].action;

	}
    }
    return -1;
}