appmouse.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 "appmouse.h"
  11. #include "topfisheyeview.h"
  12. #include "arcball.h"
  13. #include "glmotion.h"
  14. #include "hotkeymap.h"
  15. #include "selectionfuncs.h"
  16. #include <stdint.h>
  17. #include "topviewfuncs.h"
  18. static int lastAction;
  19. static void apply_actions(ViewInfo* v,int x,int y)
  20. {
  21. int a;
  22. gdouble seconds;
  23. a=get_mode(v);
  24. if (a == MM_PAN && view->guiMode == GUI_FULLSCREEN &&
  25. v->active_camera != SIZE_MAX)
  26. a=MM_ROTATE;
  27. switch (a) {
  28. case MM_ROTATE :
  29. seconds = g_timer_elapsed(view->timer3, NULL);
  30. if (seconds > 0.1) {
  31. g_timer_stop(view->timer3);
  32. view->arcball->MousePt.s.X = (float)x;
  33. view->arcball->MousePt.s.Y = (float)y;
  34. if (!view->arcball->isDragging) {
  35. arcmouseClick();
  36. view->arcball->isDragging = 1;
  37. }
  38. else
  39. arcmouseDrag();
  40. g_timer_start(view->timer3);
  41. }
  42. return;
  43. case MM_PAN :
  44. glmotion_pan(v);
  45. break;
  46. case MM_MOVE :
  47. break;
  48. case MM_RECTANGULAR_SELECT :
  49. if (!view->mouse.down) {
  50. pick_objects_rect(view->g[view->activeGraph]) ;
  51. }
  52. break;
  53. case MM_POLYGON_SELECT :
  54. add_selpoly(view->g[view->activeGraph],&view->Topview->sel.selPoly,view->mouse.GLfinalPos);
  55. break;
  56. case MM_SINGLE_SELECT :
  57. pick_object_xyz(view->g[view->activeGraph],view->Topview,view->mouse.GLfinalPos.x,view->mouse.GLfinalPos.y,view->mouse.GLfinalPos.z);
  58. break;
  59. case MM_FISHEYE_PICK :
  60. if (view->activeGraph >= 0) {
  61. if (view->Topview->fisheyeParams.active)
  62. changetopfishfocus(view->Topview, &view->mouse.GLpos.x, &view->mouse.GLpos.y, 1);
  63. }
  64. break;
  65. }
  66. lastAction=a;
  67. }
  68. static void appmouse_down(ViewInfo* v,int x,int y)
  69. {
  70. view->mouse.dragX = 0;
  71. view->mouse.dragY = 0;
  72. v->mouse.down=1;
  73. v->mouse.x = x;
  74. v->mouse.y = y;
  75. to3D(x,y,&v->mouse.GLinitPos.x,&v->mouse.GLinitPos.y,&v->mouse.GLinitPos.z);
  76. to3D( x,y, &v->mouse.GLpos.x,&v->mouse.GLpos.y,&v->mouse.GLpos.z);
  77. }
  78. void appmouse_up(ViewInfo *v, int x, int y) {
  79. v->mouse.down=0;
  80. to3D(x,y, &v->mouse.GLfinalPos.x,&v->mouse.GLfinalPos.y,&v->mouse.GLfinalPos.z);
  81. apply_actions(v,x,y);
  82. view->mouse.dragX = 0;
  83. view->mouse.dragY = 0;
  84. view->arcball->isDragging=0;
  85. }
  86. void appmouse_drag(ViewInfo *v, int x, int y) {
  87. v->mouse.x = x;
  88. v->mouse.y = y;
  89. to3D( x,y, &v->mouse.GLpos.x,&v->mouse.GLpos.y,&v->mouse.GLpos.z);
  90. apply_actions(v,x,y);
  91. }
  92. void appmouse_left_click_down(ViewInfo* v,int x,int y)
  93. {
  94. v->mouse.t=glMouseLeftButton;
  95. appmouse_down(v,x,y);
  96. }
  97. void appmouse_right_click_down(ViewInfo* v,int x,int y)
  98. {
  99. v->mouse.t=glMouseRightButton;
  100. appmouse_down(v,x,y);
  101. }
  102. void appmouse_middle_click_down(ViewInfo* v,int x,int y)
  103. {
  104. v->mouse.t=glMouseMiddleButton;
  105. appmouse_down(v,x,y);
  106. }
  107. void appmouse_move(ViewInfo* v,int x,int y)
  108. {
  109. to3D( x,y, &v->mouse.GLpos.x,&v->mouse.GLpos.y,&v->mouse.GLpos.z);
  110. }
  111. void appmouse_key_release(ViewInfo* v)
  112. {
  113. if(lastAction==MM_POLYGON_SELECT)
  114. {
  115. glCompPoly_free(&view->Topview->sel.selPoly);
  116. glexpose();
  117. }
  118. v->keyVal = 0;
  119. }
  120. void appmouse_key_press(ViewInfo* v,int key)
  121. {
  122. v->keyVal = key;
  123. }