ViewerPlugin.h 4.1 KB

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