UAV Simulator
Loading...
Searching...
No Matches
easy3d::ViewerImGui Class Reference

An Easy3D viewer with ImGui GUI support for custom rendering and input. More...

#include <viewer_imgui.h>

Inheritance diagram for easy3d::ViewerImGui:
Collaboration diagram for easy3d::ViewerImGui:

Public Member Functions

 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.
 
 ~ViewerImGui () override
 Destructor. Cleans up ImGui and OpenGL resources.
 

Protected Member Functions

void init () override
 Initializes ImGui and binds it to the OpenGL and GLFW context.
 
void pre_draw () override
 Called before rendering the scene.
 
void post_draw () override
 Called after rendering the scene.
 
void post_resize (int w, int h) override
 Handles window resize events.
 
bool callback_event_cursor_pos (double x, double y) override
 Handles mouse movement.
 
bool callback_event_mouse_button (int button, int action, int modifiers) override
 Handles mouse button events.
 
bool callback_event_keyboard (int key, int action, int modifiers) override
 Handles keyboard key events.
 
bool callback_event_character (unsigned int codepoint) override
 Handles character input events.
 
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.
 
void draw_menu_view ()
 Draws the "View" menu in the main menu bar.
 
float pixel_ratio ()
 Computes the pixel ratio between framebuffer and window size.
 
float widget_scaling ()
 Calculates the widget scaling factor.
 
void reload_font (int font_size=16)
 Reloads the ImGui font at a given font size.
 

Protected Attributes

float menu_height_
 Height of the menu bar, used for adjusting overlay positions.
 

Static Protected Attributes

static ImGuiContext * context_
 Global ImGui context shared across all viewer instances.
 

Detailed Description

An Easy3D viewer with ImGui GUI support for custom rendering and input.

This viewer integrates the Dear ImGui library into the Easy3D rendering pipeline, allowing the use of custom toolbars, overlays, and event handling in a platform-independent manner.

Constructor & Destructor Documentation

◆ ViewerImGui()

easy3d::ViewerImGui::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 
)
explicit

Constructor for ViewerImGui.

Initializes a viewer window with OpenGL and ImGui support.

Parameters
titleTitle of the application window.
samplesNumber of anti-aliasing samples.
gl_majorMajor version of OpenGL.
gl_minorMinor version of OpenGL.
full_screenLaunch in fullscreen mode.
resizableWindow resizable flag.
depth_bitsDepth buffer precision.
stencil_bitsStencil buffer precision.
widthInitial window width in pixels.
heightInitial window height in pixels.

◆ ~ViewerImGui()

easy3d::ViewerImGui::~ViewerImGui ( )
override

Destructor. Cleans up ImGui and OpenGL resources.

Member Function Documentation

◆ callback_event_character()

bool easy3d::ViewerImGui::callback_event_character ( unsigned int  codepoint)
overrideprotected

Handles character input events.

Returns
true if ImGui captures the input.

◆ callback_event_cursor_pos()

bool easy3d::ViewerImGui::callback_event_cursor_pos ( double  x,
double  y 
)
overrideprotected

Handles mouse movement.

Returns
true if ImGui captures the input.

◆ callback_event_keyboard()

bool easy3d::ViewerImGui::callback_event_keyboard ( int  key,
int  action,
int  modifiers 
)
overrideprotected

Handles keyboard key events.

Returns
true if ImGui captures the input.

◆ callback_event_mouse_button()

bool easy3d::ViewerImGui::callback_event_mouse_button ( int  button,
int  action,
int  modifiers 
)
overrideprotected

Handles mouse button events.

Returns
true if ImGui captures the input.

◆ callback_event_scroll()

bool easy3d::ViewerImGui::callback_event_scroll ( double  dx,
double  dy 
)
overrideprotected

Handles mouse scroll events.

Returns
true if ImGui captures the input.

◆ draw_menu_file()

void easy3d::ViewerImGui::draw_menu_file ( )
protected

Draws the "File" menu in the main menu bar.

◆ draw_menu_view()

void easy3d::ViewerImGui::draw_menu_view ( )
protected

Draws the "View" menu in the main menu bar.

◆ init()

void easy3d::ViewerImGui::init ( )
overrideprotected

Initializes ImGui and binds it to the OpenGL and GLFW context.

◆ pixel_ratio()

float easy3d::ViewerImGui::pixel_ratio ( )
protected

Computes the pixel ratio between framebuffer and window size.

Useful for supporting HiDPI displays.

Returns
Pixel ratio (usually 1.0 for standard DPI).

◆ post_draw()

void easy3d::ViewerImGui::post_draw ( )
overrideprotected

Called after rendering the scene.

Draws ImGui widgets, menus, and overlays (e.g., logo and FPS).

◆ post_resize()

void easy3d::ViewerImGui::post_resize ( int  w,
int  h 
)
overrideprotected

Handles window resize events.

Updates ImGui's display size.

Parameters
wNew window width.
hNew window height.

◆ pre_draw()

void easy3d::ViewerImGui::pre_draw ( )
overrideprotected

Called before rendering the scene.

Prepares a new ImGui frame.

◆ reload_font()

void easy3d::ViewerImGui::reload_font ( int  font_size = 16)
protected

Reloads the ImGui font at a given font size.

This clears the font atlas and applies new scaling.

Parameters
font_sizeDesired font size (default = 16).

◆ widget_scaling()

float easy3d::ViewerImGui::widget_scaling ( )
inlineprotected

Calculates the widget scaling factor.

This accounts for DPI scaling and pixel ratio.

Returns
Scaling factor for ImGui widgets.

Member Data Documentation

◆ context_

ImGuiContext* easy3d::ViewerImGui::context_
staticprotected

Global ImGui context shared across all viewer instances.

Can be overridden to support per-window contexts, but not typical.

◆ menu_height_

float easy3d::ViewerImGui::menu_height_
protected

Height of the menu bar, used for adjusting overlay positions.


The documentation for this class was generated from the following file: