ViewerPlugin.h 4.2 KB

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