drag_select.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "st_edit.hh"
  13. #include "app/app.hh"
  14. class m1_drag_select_class : public m1_utility_state_class
  15. {
  16. public:
  17. i4_float ax,ay;
  18. i4_float px,py;
  19. virtual i4_bool mouse_down()
  20. {
  21. ax = mouse_x();
  22. ay = mouse_y();
  23. return i4_F;
  24. }
  25. virtual i4_bool mouse_up()
  26. {
  27. g1_quad_object_class *obj = m1_info.obj;
  28. g1_vert_class *src_vert = obj->get_verts(m1_info.current_animation, m1_info.current_frame);
  29. r1_vert v;
  30. i4_float tmp;
  31. px = mouse_x();
  32. py = mouse_y();
  33. if (ax>px) { tmp=ax; ax=px; px=tmp; }
  34. if (ay>py) { tmp=ay; ay=py; py=tmp; }
  35. if (!i4_current_app->get_window_manager()->shift_pressed())
  36. li_call("select_none");
  37. for (int i=0; i<obj->num_quad; i++)
  38. {
  39. g1_quad_class *q = &obj->quad[i];
  40. i4_bool out=i4_F;
  41. for (int j=0; j<q->num_verts() && !out; j++)
  42. {
  43. m1_render_window->project_point(src_vert[q->vertex_ref[j]].v, v);
  44. if (v.px<ax || v.px>px || v.py<ay || v.py>py)
  45. out = i4_T;
  46. }
  47. if (!out)
  48. q->set_flags(g1_quad_class::SELECTED);
  49. }
  50. m1_render_window->restore_state();
  51. m1_render_window->request_redraw(i4_F);
  52. m1_st_edit->edit_poly_changed();
  53. return i4_T;
  54. }
  55. virtual i4_bool mouse_drag()
  56. {
  57. return i4_F;
  58. }
  59. };
  60. static m1_drag_select_class drag_select;
  61. li_object *m1_drag_select(li_object *o, li_environment *env)
  62. {
  63. if (m1_info.obj)
  64. m1_render_window->set_state(&drag_select);
  65. return 0;
  66. }
  67. li_automatic_add_function(m1_drag_select, "drag_select");