ImGuiPlugin.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2022 Alec Jacobson <[email protected]>
  4. // Copyright (C) 2018 Jérémie Dumas <[email protected]>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public License
  7. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  8. // obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef IGL_OPENGL_GLFW_IMGUI_IMGUIPLUGIN_H
  10. #define IGL_OPENGL_GLFW_IMGUI_IMGUIPLUGIN_H
  11. #include "../Viewer.h"
  12. #include "../ViewerPlugin.h"
  13. #include "../../../igl_inline.h"
  14. #include "ImGuiWidget.h"
  15. // Forward declarations
  16. struct ImGuiContext;
  17. namespace igl
  18. {
  19. namespace opengl
  20. {
  21. namespace glfw
  22. {
  23. namespace imgui
  24. {
  25. // Forward declaration of child widget abstract type
  26. class ImGuiWidget;
  27. /// Plugin for the viewer to enable imgui widgets
  28. class ImGuiPlugin : public igl::opengl::glfw::ViewerPlugin
  29. {
  30. protected:
  31. // Hidpi scaling to be used for text rendering.
  32. float hidpi_scaling_;
  33. // Ratio between the framebuffer size and the window size.
  34. // May be different from the hipdi scaling!
  35. float pixel_ratio_;
  36. // ImGui Context
  37. ImGuiContext * context_ = nullptr;
  38. public:
  39. // List of registered widgets
  40. std::vector<ImGuiWidget*> widgets;
  41. public:
  42. IGL_INLINE virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
  43. IGL_INLINE void init_widgets();
  44. IGL_INLINE virtual void reload_font(int font_size = 13);
  45. IGL_INLINE virtual void shutdown() override;
  46. IGL_INLINE virtual bool pre_draw() override;
  47. IGL_INLINE virtual bool post_draw() override;
  48. IGL_INLINE virtual void post_resize(int width, int height) override;
  49. IGL_INLINE virtual bool mouse_down(int button, int modifier) override;
  50. IGL_INLINE virtual bool mouse_up(int button, int modifier) override;
  51. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) override;
  52. IGL_INLINE virtual bool mouse_scroll(float delta_y) override;
  53. // Keyboard IO
  54. IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) override;
  55. IGL_INLINE virtual bool key_down(int key, int modifiers) override;
  56. IGL_INLINE virtual bool key_up(int key, int modifiers) override;
  57. IGL_INLINE void draw_text(
  58. const Eigen::Vector3d pos,
  59. const Eigen::Vector3d normal,
  60. const std::string &text,
  61. const Eigen::Vector4f color = Eigen::Vector4f(0,0,0.04,1)); // old default color
  62. IGL_INLINE float pixel_ratio();
  63. IGL_INLINE float hidpi_scaling();
  64. };
  65. }
  66. }
  67. }
  68. }
  69. #ifndef IGL_STATIC_LIBRARY
  70. # include "ImGuiPlugin.cpp"
  71. #endif
  72. #endif