ViewerPlugin.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. // TODO:
  9. // * create plugins/skeleton.h
  10. // * pass time in draw function
  11. // * remove Preview3D from comments
  12. // * clean comments
  13. #ifndef IGL_VIEWER_PLUGIN_H
  14. #define IGL_VIEWER_PLUGIN_H
  15. #include <string>
  16. #include <igl/igl_inline.h>
  17. #include <vector>
  18. namespace igl
  19. {
  20. // Abstract class for plugins
  21. // All plugins MUST have this class as their parent and may implement any/all
  22. // the callbacks marked `virtual` here.
  23. //
  24. // /////For an example of a basic plugins see plugins/skeleton.h
  25. //
  26. // Return value of callbacks: returning true to any of the callbacks tells
  27. // Viewer that the event has been handled and that it should not be passed to
  28. // other plugins or to other internal functions of Viewer
  29. // Forward declaration of the viewer
  30. class Viewer;
  31. class ViewerPlugin
  32. {
  33. public:
  34. IGL_INLINE ViewerPlugin()
  35. {plugin_name = "dummy";}
  36. virtual ~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(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. // This function is called when the scene is serialized
  57. IGL_INLINE virtual bool serialize(std::vector<char>& buffer) const
  58. {
  59. return false;
  60. }
  61. // This function is called when the scene is deserialized
  62. IGL_INLINE virtual bool deserialize(const std::vector<char>& buffer)
  63. {
  64. return false;
  65. }
  66. // Runs immediately after a new mesh has been loaded.
  67. IGL_INLINE virtual bool post_load()
  68. {
  69. return false;
  70. }
  71. // This function is called before the draw procedure of Preview3D
  72. IGL_INLINE virtual bool pre_draw()
  73. {
  74. return false;
  75. }
  76. // This function is called after the draw procedure of Preview3D
  77. IGL_INLINE virtual bool post_draw()
  78. {
  79. return false;
  80. }
  81. // This function is called when the mouse button is pressed
  82. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  83. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  84. IGL_INLINE virtual bool mouse_down(int button, int modifier)
  85. {
  86. return false;
  87. }
  88. // This function is called when the mouse button is released
  89. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  90. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  91. IGL_INLINE virtual bool mouse_up(int button, int modifier)
  92. {
  93. return false;
  94. }
  95. // This function is called every time the mouse is moved
  96. // - mouse_x and mouse_y are the new coordinates of the mouse pointer in screen coordinates
  97. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y)
  98. {
  99. return false;
  100. }
  101. // This function is called every time the scroll wheel is moved
  102. // Note: this callback is not working with every glut implementation
  103. IGL_INLINE virtual bool mouse_scroll(float delta_y)
  104. {
  105. return false;
  106. }
  107. // This function is called when a keyboard key is pressed
  108. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  109. IGL_INLINE virtual bool key_down(int key, int modifiers)
  110. {
  111. return false;
  112. }
  113. // This function is called when a keyboard key is release
  114. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  115. IGL_INLINE virtual bool key_up(int key, int modifiers)
  116. {
  117. return false;
  118. }
  119. std::string plugin_name;
  120. protected:
  121. // Pointer to the main Viewer class
  122. Viewer *viewer;
  123. };
  124. #ifdef ENABLE_SERIALIZATION
  125. namespace serialization
  126. {
  127. IGL_INLINE void serialize(const ViewerPlugin& obj,std::vector<char>& buffer)
  128. {
  129. obj.serialize(buffer);
  130. }
  131. IGL_INLINE void deserialize(ViewerPlugin& obj,const std::vector<char>& buffer)
  132. {
  133. obj.deserialize(buffer);
  134. }
  135. }
  136. #endif
  137. }
  138. #endif