ImGuiMenu.h 3.1 KB

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