navigate.cc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "lisp/li_init.hh"
  9. #include "m1_info.hh"
  10. #include "max_object.hh"
  11. #include "render.hh"
  12. #include "math/pi.hh"
  13. #include "app/app.hh"
  14. #include "st_edit.hh"
  15. class m1_navigate_state_class : public m1_utility_state_class
  16. {
  17. public:
  18. enum
  19. // Grab Masks for functions
  20. {
  21. moving = m1_utility_window_class::LEFT,
  22. zooming = m1_utility_window_class::RIGHT,
  23. panning = m1_utility_window_class::MIDDLE
  24. };
  25. virtual i4_bool mouse_down()
  26. {
  27. if (buttons() & moving)
  28. {
  29. if (!i4_current_app->get_window_manager()->shift_pressed() && m1_info.preselect_poly>=0)
  30. li_call("select_none");
  31. m1_render_window->select_poly(m1_info.preselect_poly);
  32. m1_st_edit->select_point(m1_info.preselect_point);
  33. return i4_T;
  34. }
  35. return i4_F;
  36. }
  37. virtual i4_bool mouse_drag()
  38. {
  39. //{{{ Handle Moving
  40. if (buttons() & moving)
  41. {
  42. i4_float theta = m1_render_window->theta + 0.01*(mouse_x() - last_x());
  43. i4_float phi = m1_render_window->phi - 0.01*(mouse_y() - last_y());
  44. if (theta<0.0)
  45. theta += i4_pi()*2;
  46. else if (theta>i4_pi()*2)
  47. theta -= i4_pi()*2;
  48. if (phi<0.0)
  49. phi += i4_pi()*2;
  50. else if (phi>i4_pi()*2)
  51. phi -= i4_pi()*2;
  52. m1_render_window->theta = theta;
  53. m1_render_window->phi = phi;
  54. m1_render_window->recalc_view();
  55. return i4_T;
  56. }
  57. //}}}
  58. //{{{ Handle Zooming
  59. if (buttons() & zooming)
  60. {
  61. m1_render_window->dist *= exp(i4_float(mouse_y() - last_y())/height() * log(4));
  62. m1_render_window->recalc_view();
  63. return i4_T;
  64. }
  65. //}}}
  66. //{{{ Handle Panning
  67. if (buttons() & zooming)
  68. {
  69. i4_float p_x = i4_float(mouse_x() - last_x())/width();
  70. i4_float p_y = i4_float(mouse_y() - last_y())/height();
  71. m1_render_window->pan(p_x,p_y);
  72. m1_render_window->recalc_view();
  73. return i4_T;
  74. }
  75. //}}}
  76. return i4_F;
  77. }
  78. };
  79. m1_navigate_state_class navigate;
  80. m1_utility_state_class *m1_default_state = &navigate;
  81. li_object *m1_navigate(li_object *o, li_environment *env)
  82. //{{{
  83. {
  84. m1_render_window->set_state(&navigate);
  85. return 0;
  86. }
  87. //}}}
  88. li_automatic_add_function(m1_navigate, "navigate");
  89. //{{{ Emacs Locals
  90. // Local Variables:
  91. // folded-file: t
  92. // End:
  93. //}}}