hotkeymap.c 4.8 KB

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