ViewerPlugin.h 5.1 KB

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