ImGuiMenu.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2018 Jérémie Dumas <jeremie.dumas@ens-lyon.org>
  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_IMGUI_IMGUIMENU_H
  9. #define IGL_OPENGL_GLFW_IMGUI_IMGUIMENU_H
  10. ////////////////////////////////////////////////////////////////////////////////
  11. #include <igl/opengl/glfw/Viewer.h>
  12. #include <igl/opengl/glfw/ViewerPlugin.h>
  13. #include <igl/igl_inline.h>
  14. ////////////////////////////////////////////////////////////////////////////////
  15. // Forward declarations
  16. struct ImGuiContext;
  17. namespace igl
  18. {
  19. namespace opengl
  20. {
  21. namespace glfw
  22. {
  23. namespace imgui
  24. {
  25. class ImGuiMenu : public igl::opengl::glfw::ViewerPlugin
  26. {
  27. protected:
  28. // Hidpi scaling to be used for text rendering.
  29. float hidpi_scaling_;
  30. // Ratio between the framebuffer size and the window size.
  31. // May be different from the hipdi scaling!
  32. float pixel_ratio_;
  33. // ImGui Context
  34. ImGuiContext * context_ = nullptr;
  35. public:
  36. IGL_INLINE virtual void init(igl::opengl::glfw::Viewer *_viewer) override;
  37. IGL_INLINE virtual void reload_font(int font_size = 13);
  38. IGL_INLINE virtual void shutdown() override;
  39. IGL_INLINE virtual bool pre_draw() override;
  40. IGL_INLINE virtual bool post_draw() override;
  41. IGL_INLINE virtual void post_resize(int width, int height) override;
  42. // Mouse IO
  43. IGL_INLINE virtual bool mouse_down(int button, int modifier) override;
  44. IGL_INLINE virtual bool mouse_up(int button, int modifier) override;
  45. IGL_INLINE virtual bool mouse_move(int mouse_x, int mouse_y) override;
  46. IGL_INLINE virtual bool mouse_scroll(float delta_y) override;
  47. // Keyboard IO
  48. IGL_INLINE virtual bool key_pressed(unsigned int key, int modifiers) override;
  49. IGL_INLINE virtual bool key_down(int key, int modifiers) override;
  50. IGL_INLINE virtual bool key_up(int key, int modifiers) override;
  51. // Draw menu
  52. IGL_INLINE virtual void draw_menu();
  53. // Can be overwritten by `callback_draw_viewer_window`
  54. IGL_INLINE virtual void draw_viewer_window();
  55. // Can be overwritten by `callback_draw_viewer_menu`
  56. IGL_INLINE virtual void draw_viewer_menu();
  57. // Can be overwritten by `callback_draw_custom_window`
  58. IGL_INLINE virtual void draw_custom_window() { }
  59. // Easy-to-customize callbacks
  60. std::function<void(void)> callback_draw_viewer_window;
  61. std::function<void(void)> callback_draw_viewer_menu;
  62. std::function<void(void)> callback_draw_custom_window;
  63. IGL_INLINE void draw_labels_window();
  64. IGL_INLINE void draw_labels(const igl::opengl::ViewerData &data);
  65. IGL_INLINE void draw_text(Eigen::Vector3d pos, Eigen::Vector3d normal, const std::string &text);
  66. IGL_INLINE float pixel_ratio();
  67. IGL_INLINE float hidpi_scaling();
  68. float menu_scaling() { return hidpi_scaling_ / pixel_ratio_; }
  69. };
  70. } // end namespace
  71. } // end namespace
  72. } // end namespace
  73. } // end namespace
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "ImGuiMenu.cpp"
  76. #endif
  77. #endif // IGL_OPENGL_GLFW_IMGUI_IMGUIMENU_H