ViewerPlugin.h 4.0 KB

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