SelectionWidget.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef IGL_OPENGL_GFLW_IMGUI_SELECTIONWIDGET_H
  2. #define IGL_OPENGL_GFLW_IMGUI_SELECTIONWIDGET_H
  3. #include "../../../igl_inline.h"
  4. #include "ImGuiWidget.h"
  5. #include <Eigen/Dense>
  6. #include <vector>
  7. #include <string>
  8. #include <functional>
  9. namespace igl{ namespace opengl{ namespace glfw{ namespace imgui{
  10. /// Widget for selecting a region of the screen
  11. class SelectionWidget: public ImGuiWidget
  12. {
  13. public:
  14. // customizable hotkeys
  15. /// Hot key to start marquee
  16. std::string MARQUEE_KEY = "Mm";
  17. // leave 'L' for show_lines in viewer
  18. /// Hot key to start lasso
  19. std::string LASSO_KEY = "l";
  20. /// Hot key to stop selection
  21. std::string OFF_KEY = "Vv";
  22. /// Selection modes
  23. enum Mode
  24. {
  25. OFF = 0,
  26. RECTANGULAR_MARQUEE = 1,
  27. ELLIPTICAL_MARQUEE = 2,
  28. POLYGONAL_LASSO = 3,
  29. LASSO = 4,
  30. NUM_MODES = 5
  31. } mode = RECTANGULAR_MARQUEE;
  32. bool is_down = false;
  33. bool has_moved_since_down = false;
  34. bool is_drawing = false;
  35. // min and max corners of 2D rectangular marquee
  36. Eigen::Matrix<float,2,2> M = Eigen::Matrix<float,2,2>::Zero();
  37. // list of points of 2D lasso marquee
  38. std::vector<Eigen::RowVector2f> L;
  39. // callback called when slection is completed (usually on mouse_up)
  40. std::function<void(void)> callback;
  41. // callback called after mode is changed
  42. std::function<void(Mode)> callback_post_mode_change;
  43. IGL_INLINE virtual void init(Viewer *_viewer, ImGuiPlugin *_plugin) override;
  44. IGL_INLINE virtual void draw() override;
  45. IGL_INLINE virtual bool mouse_down(int button, int modifier) override;
  46. IGL_INLINE virtual bool mouse_up(int button, int modifier) override;
  47. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) override;
  48. IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) override;
  49. IGL_INLINE void clear();
  50. // helpers
  51. IGL_INLINE static void circle(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
  52. IGL_INLINE static void rect(const Eigen::Matrix<float,2,2> & M, std::vector<Eigen::RowVector2f> & L);
  53. IGL_INLINE static Eigen::RowVector2f xy(const Viewer * v);
  54. public:
  55. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  56. };
  57. }}}}
  58. #ifndef IGL_STATIC_LIBRARY
  59. #include "SelectionWidget.cpp"
  60. #endif
  61. #endif