ViewerPlugin.h 4.5 KB

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