UAV Simulator
Loading...
Searching...
No Matches
viewer_imgui.h
Go to the documentation of this file.
1/********************************************************************
2 * @file viewer_imgui.h
3 * @brief ViewerImGui class header based on the Easy3D ImGui example.
4 *
5 * This class extends Easy3D's Viewer to include an ImGui-based GUI
6 * system for rendering widgets, menus, and overlays in an OpenGL
7 * context. It integrates ImGui input handling and layout management.
8 ********************************************************************/
9
10#ifndef EASY3D_TUTORIAL_VIEWER_IMGUI_H
11#define EASY3D_TUTORIAL_VIEWER_IMGUI_H
12
13
14#include <easy3d/viewer/viewer.h>
15
16
17
18// Forward declaration to avoid including full ImGui headers in this file
19struct ImGuiContext;
20
21
22namespace easy3d
23{
32 class ViewerImGui : public Viewer
33 {
34 public:
51 explicit ViewerImGui(
52 const std::string& title = "Easy3D ViewerImGui",
53 int samples = 4,
54 int gl_major = 3, // must >= 3
55 int gl_minor = 2, // must >= 2
56 bool full_screen = false,
57 bool resizable = true,
58 int depth_bits = 24,
59 int stencil_bits = 8,
60 int width = 800,
61 int height = 600
62 );
66 ~ViewerImGui() override;
67
68 protected:
69
73 void init() override;
74
80 void pre_draw() override;
81
87 void post_draw() override;
96 void post_resize(int w, int h) override;
102 bool callback_event_cursor_pos(double x, double y) override;
108 bool callback_event_mouse_button(int button, int action, int modifiers) override;
114 bool callback_event_keyboard(int key, int action, int modifiers) override;
120 bool callback_event_character(unsigned int codepoint) override;
126 bool callback_event_scroll(double dx, double dy) override;
135
136 protected:
144 float pixel_ratio();
152 float widget_scaling() { return dpi_scaling() / pixel_ratio(); }
153
161 void reload_font(int font_size = 16);
162
163 protected:
169 static ImGuiContext * context_;
174 };
175
176}
177
178#endif // EASY3D_TUTORIAL_VIEWER_IMGUI_H
An Easy3D viewer with ImGui GUI support for custom rendering and input.
Definition viewer_imgui.h:33
void init() override
Initializes ImGui and binds it to the OpenGL and GLFW context.
bool callback_event_character(unsigned int codepoint) override
Handles character input events.
float widget_scaling()
Calculates the widget scaling factor.
Definition viewer_imgui.h:152
void pre_draw() override
Called before rendering the scene.
float pixel_ratio()
Computes the pixel ratio between framebuffer and window size.
void post_resize(int w, int h) override
Handles window resize events.
static ImGuiContext * context_
Global ImGui context shared across all viewer instances.
Definition viewer_imgui.h:169
bool callback_event_cursor_pos(double x, double y) override
Handles mouse movement.
ViewerImGui(const std::string &title="Easy3D ViewerImGui", int samples=4, int gl_major=3, int gl_minor=2, bool full_screen=false, bool resizable=true, int depth_bits=24, int stencil_bits=8, int width=800, int height=600)
Constructor for ViewerImGui.
bool callback_event_scroll(double dx, double dy) override
Handles mouse scroll events.
void draw_menu_file()
Draws the "File" menu in the main menu bar.
bool callback_event_keyboard(int key, int action, int modifiers) override
Handles keyboard key events.
void post_draw() override
Called after rendering the scene.
void reload_font(int font_size=16)
Reloads the ImGui font at a given font size.
void draw_menu_view()
Draws the "View" menu in the main menu bar.
float menu_height_
Height of the menu bar, used for adjusting overlay positions.
Definition viewer_imgui.h:173
~ViewerImGui() override
Destructor. Cleans up ImGui and OpenGL resources.
bool callback_event_mouse_button(int button, int action, int modifiers) override
Handles mouse button events.
Namespace for Easy3D rendering and geometry types.