glmotion.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "glmotion.h"
  11. #include <gtk/gtk.h>
  12. #include <gdk/gdkkeysyms.h>
  13. #include <gtk/gtkgl.h>
  14. #include <gdk/gdkcursor.h>
  15. #include "draw.h"
  16. #include <glcomp/glutils.h>
  17. #include "hotkeymap.h"
  18. #include <stdint.h>
  19. /*real zoom in out is done here, all other functions send this one what they desire, it is not guranteed,*/
  20. static void graph_zoom(float real_zoom)
  21. {
  22. float old_zoom;
  23. if (view->active_camera == SIZE_MAX)
  24. old_zoom = view->zoom;
  25. else
  26. old_zoom = view->cameras[view->active_camera]->r;
  27. if (real_zoom < view->Topview->fitin_zoom * MAX_ZOOM)
  28. real_zoom = view->Topview->fitin_zoom * MAX_ZOOM;
  29. if (real_zoom > view->Topview->fitin_zoom * MIN_ZOOM)
  30. real_zoom = view->Topview->fitin_zoom * MIN_ZOOM;
  31. if (view->active_camera == SIZE_MAX)
  32. view->zoom = real_zoom;
  33. else
  34. view->cameras[view->active_camera]->r = real_zoom * -1;
  35. /*adjust pan values */
  36. view->panx = old_zoom * view->panx / real_zoom;
  37. view->pany = old_zoom * view->pany / real_zoom;
  38. }
  39. void glmotion_zoom_inc(int zoomin)
  40. {
  41. if (zoomin) /*zooming in , zoom value should be decreased */
  42. graph_zoom(view->zoom - view->zoom * 0.25f);
  43. else
  44. graph_zoom(view->zoom + view->zoom * 0.25f); /*zoom out */
  45. glexpose();
  46. }
  47. void glmotion_zoom(void)
  48. {
  49. float real_zoom;
  50. if (view->active_camera == SIZE_MAX) {
  51. real_zoom =
  52. view->zoom + view->mouse.dragX / 10 * (view->zoom * -1 / 20);
  53. } else {
  54. real_zoom =
  55. (view->cameras[view->active_camera]->r +
  56. view->mouse.dragX / 10 * (view->cameras[view->active_camera]->r /
  57. 20)) * -1;
  58. }
  59. graph_zoom(real_zoom);
  60. }
  61. void glmotion_pan(ViewInfo * v)
  62. {
  63. float gldx, gldy;
  64. if (v->active_camera == SIZE_MAX) {
  65. gldx = GetOGLDistance(v->mouse.dragX) / v->zoom * -1;
  66. gldy = GetOGLDistance(v->mouse.dragY) / v->zoom * -1;
  67. v->panx = v->panx - gldx;
  68. v->pany = v->pany + gldy;
  69. } else {
  70. gldx = GetOGLDistance(v->mouse.dragX) / v->cameras[v->active_camera]->r;
  71. gldy = GetOGLDistance(v->mouse.dragY) / v->cameras[v->active_camera]->r;
  72. v->cameras[v->active_camera]->x -= gldx;
  73. v->cameras[v->active_camera]->y -= gldy;
  74. v->cameras[v->active_camera]->targetx -= gldx;
  75. v->cameras[v->active_camera]->targety += gldy;
  76. }
  77. }