ViewerPlugin.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <[email protected]>
  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_inline.h"
  17. #include <vector>
  18. namespace igl
  19. {
  20. namespace opengl
  21. {
  22. namespace glfw
  23. {
  24. // Forward declaration of the viewer
  25. class Viewer;
  26. /// Abstract class for plugins
  27. /// All plugins MUST have this class as their parent and may implement any/all
  28. /// the callbacks marked `virtual` here.
  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. class ViewerPlugin
  34. {
  35. public:
  36. IGL_INLINE ViewerPlugin() {plugin_name = "dummy";}
  37. virtual ~ViewerPlugin(){}
  38. /// This function is called when the viewer is initialized (no mesh will be loaded at this stage)
  39. IGL_INLINE virtual void init(Viewer *_viewer) { viewer = _viewer; }
  40. /// This function is called before shutdown
  41. IGL_INLINE virtual void shutdown() { }
  42. /// This function is called before a mesh is loaded
  43. IGL_INLINE virtual bool load(std::string /*filename*/) { return false; }
  44. /// This function is called before a mesh is saved
  45. IGL_INLINE virtual bool save(std::string /*filename*/) { return false; }
  46. /// This function is called when the scene is serialized
  47. IGL_INLINE virtual bool serialize(std::vector<char>& /*buffer*/) const
  48. { return false; }
  49. /// This function is called when the scene is deserialized
  50. IGL_INLINE virtual bool deserialize(const std::vector<char>& /*buffer*/)
  51. { return false; }
  52. /// Runs immediately after a new mesh has been loaded.
  53. IGL_INLINE virtual bool post_load() { return false; }
  54. /// This function is called before the draw procedure of Viewer
  55. IGL_INLINE virtual bool pre_draw() { return false; }
  56. /// This function is called after the draw procedure of Viewer
  57. IGL_INLINE virtual bool post_draw() { return false; }
  58. /// This function is called after the window has been resized
  59. IGL_INLINE virtual void post_resize(int /*w*/, int /*h*/) { }
  60. IGL_INLINE virtual bool mouse_down(int /*button*/, int /*modifier*/)
  61. { return false; }
  62. IGL_INLINE virtual bool mouse_up(int /*button*/, int /*modifier*/)
  63. { return false; }
  64. IGL_INLINE virtual bool mouse_move(int /*mouse_x*/, int /*mouse_y*/)
  65. { return false; }
  66. IGL_INLINE virtual bool mouse_scroll(float /*delta_y*/)
  67. { return false; }
  68. IGL_INLINE virtual bool key_pressed(unsigned int /*key*/, int /*modifiers*/)
  69. { return false; }
  70. IGL_INLINE virtual bool key_down(int /*key*/, int /*modifiers*/)
  71. { return false; }
  72. IGL_INLINE virtual bool key_up(int /*key*/, int /*modifiers*/)
  73. { return false; }
  74. std::string plugin_name;
  75. protected:
  76. // Pointer to the main Viewer class
  77. Viewer *viewer;
  78. };
  79. namespace serialization
  80. {
  81. inline void serialize(const ViewerPlugin& obj,std::vector<char>& buffer)
  82. {
  83. obj.serialize(buffer);
  84. }
  85. inline void deserialize(ViewerPlugin& obj,const std::vector<char>& buffer)
  86. {
  87. obj.deserialize(buffer);
  88. }
  89. }
  90. }
  91. }
  92. }
  93. #endif