ViewerPlugin.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef IGL_VIEWER_PLUGIN_H
  2. #define IGL_VIEWER_PLUGIN_H
  3. #include <igl/igl_inline.h>
  4. #ifdef ENABLE_XML_SERIALIZATION
  5. #include <igl/xml/XMLSerializer.h>
  6. #include <igl/xml/XMLSerialization.h>
  7. #endif
  8. namespace igl
  9. {
  10. // Abstract class for plugins
  11. // All plugins MUST have this class as their parent and implement all the callbacks
  12. // For an example of a basic plugins see plugins/skeleton.h
  13. //
  14. // Return value of callbacks: returning true to any of the callbacks tells Preview3D that the event has been
  15. // handled and that it should not be passed to other plugins or to other internal functions of Preview3D
  16. // Forward declaration of the viewer
  17. class Viewer;
  18. class ViewerPlugin
  19. #ifdef ENABLE_XML_SERIALIZATION
  20. : public ::igl::XMLSerialization
  21. #endif
  22. {
  23. public:
  24. IGL_INLINE ViewerPlugin()
  25. #ifdef ENABLE_XML_SERIALIZATION
  26. : XMLSerialization("dummy")
  27. #endif
  28. {plugin_name = "dummy";};
  29. ~ViewerPlugin(){};
  30. // This function is called when the viewer is initialized (no mesh will be loaded at this stage)
  31. IGL_INLINE virtual void init(igl::Viewer *_viewer)
  32. {
  33. viewer = _viewer;
  34. }
  35. // This function is called before shutdown
  36. IGL_INLINE virtual void shutdown()
  37. {
  38. }
  39. // This function is called before a mesh is loaded
  40. IGL_INLINE virtual bool load(std::string filename)
  41. {
  42. return false;
  43. }
  44. // This function is called before a mesh is saved
  45. IGL_INLINE virtual bool save(std::string filename)
  46. {
  47. return false;
  48. }
  49. // Runs immediately after a new mesh had been loaded.
  50. IGL_INLINE virtual bool post_load()
  51. {
  52. return false;
  53. }
  54. // This function is called before the draw procedure of Preview3D
  55. IGL_INLINE virtual bool pre_draw()
  56. {
  57. return false;
  58. }
  59. // This function is called after the draw procedure of Preview3D
  60. IGL_INLINE virtual bool post_draw()
  61. {
  62. return false;
  63. }
  64. // This function is called when the mouse button is pressed
  65. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  66. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  67. IGL_INLINE virtual bool mouse_down(int button, int modifier)
  68. {
  69. return false;
  70. }
  71. // This function is called when the mouse button is released
  72. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  73. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  74. IGL_INLINE virtual bool mouse_up(int button, int modifier)
  75. {
  76. return false;
  77. }
  78. // This function is called every time the mouse is moved
  79. // - mouse_x and mouse_y are the new coordinates of the mouse pointer in screen coordinates
  80. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y)
  81. {
  82. return false;
  83. }
  84. // This function is called every time the scroll wheel is moved
  85. // Note: this callback is not working with every glut implementation
  86. IGL_INLINE virtual bool mouse_scroll(float delta_y)
  87. {
  88. return false;
  89. }
  90. // This function is called when a keyboard key is pressed
  91. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  92. IGL_INLINE virtual bool key_down(unsigned char key, int modifiers)
  93. {
  94. return false;
  95. }
  96. // This function is called when a keyboard key is release
  97. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  98. IGL_INLINE virtual bool key_up(unsigned char key, int modifiers)
  99. {
  100. return false;
  101. }
  102. std::string plugin_name;
  103. protected:
  104. // Pointer to the main Preview3D class
  105. Viewer *viewer;
  106. public:
  107. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  108. };
  109. }
  110. #endif