ViewerPlugin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 may implement any/all
  20. // the callbacks marked `virtual` here.
  21. //
  22. // /////For an example of a basic plugins see plugins/skeleton.h
  23. //
  24. // Return value of callbacks: returning true to any of the callbacks tells
  25. // Viewer that the event has been handled and that it should not be passed to
  26. // other plugins or to other internal functions of Viewer
  27. // Forward declaration of the viewer
  28. class Viewer;
  29. class ViewerPlugin
  30. #ifdef ENABLE_XML_SERIALIZATION
  31. : public ::igl::XMLSerialization
  32. #endif
  33. {
  34. public:
  35. IGL_INLINE ViewerPlugin()
  36. #ifdef ENABLE_XML_SERIALIZATION
  37. : XMLSerialization("dummy")
  38. #endif
  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. // Runs immediately after a new mesh had been loaded.
  61. IGL_INLINE virtual bool post_load()
  62. {
  63. return false;
  64. }
  65. // This function is called before the draw procedure of Preview3D
  66. IGL_INLINE virtual bool pre_draw()
  67. {
  68. return false;
  69. }
  70. // This function is called after the draw procedure of Preview3D
  71. IGL_INLINE virtual bool post_draw()
  72. {
  73. return false;
  74. }
  75. // This function is called when the mouse button is pressed
  76. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  77. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  78. IGL_INLINE virtual bool mouse_down(int button, int modifier)
  79. {
  80. return false;
  81. }
  82. // This function is called when the mouse button is released
  83. // - button can be GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON
  84. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  85. IGL_INLINE virtual bool mouse_up(int button, int modifier)
  86. {
  87. return false;
  88. }
  89. // This function is called every time the mouse is moved
  90. // - mouse_x and mouse_y are the new coordinates of the mouse pointer in screen coordinates
  91. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y)
  92. {
  93. return false;
  94. }
  95. // This function is called every time the scroll wheel is moved
  96. // Note: this callback is not working with every glut implementation
  97. IGL_INLINE virtual bool mouse_scroll(float delta_y)
  98. {
  99. return false;
  100. }
  101. // This function is called when a keyboard key is pressed
  102. // - modifiers is a bitfield that might one or more of the following bits Preview3D::NO_KEY, Preview3D::SHIFT, Preview3D::CTRL, Preview3D::ALT;
  103. IGL_INLINE virtual bool key_down(unsigned char key, int modifiers)
  104. {
  105. return false;
  106. }
  107. // This function is called when a keyboard key is release
  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_up(unsigned char key, int modifiers)
  110. {
  111. return false;
  112. }
  113. std::string plugin_name;
  114. protected:
  115. // Pointer to the main Viewer class
  116. Viewer *viewer;
  117. };
  118. }
  119. #endif