SLProject 4.0.000
SLGLImGui Class Reference

ImGui Interface class for forwarding all events to the ImGui Handlers. More...

#include <SLGLImGui.h>

Inheritance diagram for SLGLImGui:
[legend]

Public Member Functions

 SLGLImGui (cbOnImGuiBuild buildCB, cbOnImGuiLoadConfig loadConfigCB, cbOnImGuiSaveConfig saveConfigCB, int dpi, SLstring fontDir)
 
 ~SLGLImGui () override
 
void init (const string &configPath) override
 Initializes OpenGL handles to zero and sets the ImGui key map. More...
 
void onInitNewFrame (SLScene *s, SLSceneView *sv) override
 Inits a new frame for the ImGui system. More...
 
void onResize (SLint scrW, SLint scrH) override
 Callback if window got resized. More...
 
void onPaint (const SLRecti &viewport) override
 Callback for main rendering for the ImGui GUI system. More...
 
void onMouseDown (SLMouseButton button, SLint x, SLint y) override
 Callback on mouse button down event. More...
 
void onMouseUp (SLMouseButton button, SLint x, SLint y) override
 Callback on mouse button up event. More...
 
void onMouseMove (SLint xPos, SLint yPos) override
 Updates the mouse cursor position. More...
 
void onMouseWheel (SLfloat yoffset) override
 Callback for the mouse scroll movement. More...
 
void onKeyPress (SLKey key, SLKey mod) override
 Callback on key press event. More...
 
void onKeyRelease (SLKey key, SLKey mod) override
 Callback on key release event. More...
 
void onCharInput (SLuint c) override
 Callback on character input. More...
 
void onClose () override
 Callback on closing the application. More...
 
void renderExtraFrame (SLScene *s, SLSceneView *sv, SLint mouseX, SLint mouseY) override
 Renders an extra frame with the current mouse position. More...
 
bool doNotDispatchKeyboard () override
 inform if user keyboard input was consumed by the ui More...
 
bool doNotDispatchMouse () override
 inform if user mouse input was consumed by the ui More...
 
void loadFonts (SLfloat fontPropDots, SLfloat fontFixedDots, SLstring fontDir)
 Loads the proportional and fixed size font depending on the passed DPI. More...
 
void drawMouseCursor (bool doDraw) override
 Turns on or off the mouse cursor drawing. More...
 
- Public Member Functions inherited from SLUiInterface
virtual ~SLUiInterface ()
 
virtual void init (const string &configPath)
 initialization (called by SLSceneView init) More...
 
virtual void onResize (SLint scrW, SLint scrH)
 inform the ui about scene view size change More...
 
virtual void onClose ()
 shutdown ui More...
 
virtual void onInitNewFrame (SLScene *s, SLSceneView *sv)
 prepare the ui for a new rendering, e.g. update visual ui representation (called by SLSceneView onPaint) More...
 
virtual void onPaint (const SLRecti &viewport)
 ui render call (called by SLSceneView draw2DGL) More...
 
virtual void renderExtraFrame (SLScene *s, SLSceneView *sv, SLint mouseX, SLint mouseY)
 
virtual void onMouseDown (SLMouseButton button, SLint x, SLint y)
 forward user input to ui More...
 
virtual void onMouseUp (SLMouseButton button, SLint x, SLint y)
 forward user input to ui More...
 
virtual void onMouseMove (SLint xPos, SLint yPos)
 forward user input to ui More...
 
virtual void onMouseWheel (SLfloat yoffset)
 forward user input to ui More...
 
virtual void onKeyPress (SLKey key, SLKey mod)
 forward user input to ui More...
 
virtual void onKeyRelease (SLKey key, SLKey mod)
 forward user input to ui More...
 
virtual void onCharInput (SLuint c)
 forward user input to ui More...
 
virtual bool doNotDispatchKeyboard ()
 inform if user keyboard input was consumed by the ui More...
 
virtual bool doNotDispatchMouse ()
 inform if user mouse input was consumed by the ui More...
 
virtual void drawMouseCursor (bool doDraw)
 Turns on or off the mouse cursor drawing. More...
 

Static Public Attributes

static SLfloat fontPropDots = 16.0f
 Default font size of proportional font. More...
 
static SLfloat fontFixedDots = 13.0f
 Default font size of fixed size font. More...
 

Private Member Functions

void deleteOpenGLObjects ()
 Deletes all OpenGL objects for drawing the imGui. More...
 
void createOpenGLObjects ()
 Creates all OpenGL objects for drawing the imGui. More...
 
void printCompileErrors (SLint shaderHandle, const SLchar *src)
 Prints the compile errors in case of a GLSL compile failure. More...
 

Private Attributes

cbOnImGuiBuild _build = nullptr
 
cbOnImGuiSaveConfig _saveConfig = nullptr
 
SLfloat _timeSec
 Time in seconds. More...
 
SLVec2f _mousePosPX
 Mouse cursor position. More...
 
SLfloat _mouseWheel
 Mouse wheel position. More...
 
SLbool _mousePressed [3]
 Mouse button press state. More...
 
SLuint _fontTexture
 OpenGL texture id for font. More...
 
SLint _progHandle
 OpenGL handle for shader program. More...
 
SLint _vertHandle
 OpenGL handle for vertex shader. More...
 
SLint _fragHandle
 OpenGL handle for fragment shader. More...
 
SLint _attribLocTex
 OpenGL attribute location for texture. More...
 
SLint _attribLocProjMtx
 OpenGL attribute location for ??? More...
 
SLint _attribLocPosition
 OpenGL attribute location for vertex pos. More...
 
SLint _attribLocUV
 OpenGL attribute location for texture coords. More...
 
SLint _attribLocColor
 OpenGL attribute location for color. More...
 
SLuint _vboHandle
 OpenGL handle for vertex buffer object. More...
 
SLuint _vaoHandle
 OpenGL vertex array object handle. More...
 
SLuint _elementsHandle
 OpenGL handle for vertex indexes. More...
 
SLfloat _fontPropDots
 Active font size of proportional font. More...
 
SLfloat _fontFixedDots
 Active font size of fixed size font. More...
 
SLstring _fontDir
 
SLstring _configPath
 

Detailed Description

ImGui Interface class for forwarding all events to the ImGui Handlers.

ImGui is a super easy GUI library for the rendering of a UI with OpenGL. For more information see: https://github.com/ocornut/imgui

This class provides only the interface into ImGui. In the event handlers of SLSceneView the according callback in ImGui is called.
There is no UI drawn with this class. It must be defined in another class that provides the build function. For the Demo apps this is done in the class SLDemoGui and the build function is passed e.g. in glfwMain function of the app-Demo-SLProject project.

The full call stack for rendering one frame is:

  • The top-level onPaint of the app (Win, Linux, MacOS, Android or iOS)
    • slUpdateAndPaint: C-Interface function of SLProject
      • SLSceneView::onPaint: Main onPaint function of a sceneview
        • SLGLImGui::onInitNewFrame: Initializes a new GUI frame
          • ImGui::NewFrame()
          • SLGLImGui::build: The UI build function
        • ... normal scene rendering of SLProject
        • SLSceneView::draw2DGL:
          • ImGui::Render
            • SLGLImGui::onPaint(ImGui::GetDrawData())
            • SLDemoGui::buildDemoGui: Builds the full UI

Constructor & Destructor Documentation

◆ SLGLImGui()

SLGLImGui::SLGLImGui ( cbOnImGuiBuild  buildCB,
cbOnImGuiLoadConfig  loadConfigCB,
cbOnImGuiSaveConfig  saveConfigCB,
int  dpi,
SLstring  fontDir 
)

◆ ~SLGLImGui()

SLGLImGui::~SLGLImGui ( )
override

Member Function Documentation

◆ createOpenGLObjects()

void SLGLImGui::createOpenGLObjects ( )
private

Creates all OpenGL objects for drawing the imGui.

◆ deleteOpenGLObjects()

void SLGLImGui::deleteOpenGLObjects ( )
private

Deletes all OpenGL objects for drawing the imGui.

◆ doNotDispatchKeyboard()

bool SLGLImGui::doNotDispatchKeyboard ( )
inlineoverridevirtual

inform if user keyboard input was consumed by the ui

Reimplemented from SLUiInterface.

◆ doNotDispatchMouse()

bool SLGLImGui::doNotDispatchMouse ( )
inlineoverridevirtual

inform if user mouse input was consumed by the ui

(e.g. the ui was hit by a mouse click. In this case the user input would not be forwarded to 3D scene graph)

Reimplemented from SLUiInterface.

◆ drawMouseCursor()

void SLGLImGui::drawMouseCursor ( bool  doDraw)
inlineoverridevirtual

Turns on or off the mouse cursor drawing.

Reimplemented from SLUiInterface.

◆ init()

void SLGLImGui::init ( const string &  configPath)
overridevirtual

Initializes OpenGL handles to zero and sets the ImGui key map.

Reimplemented from SLUiInterface.

◆ loadFonts()

void SLGLImGui::loadFonts ( SLfloat  fontPropDots,
SLfloat  fontFixedDots,
SLstring  fontDir 
)

Loads the proportional and fixed size font depending on the passed DPI.

◆ onCharInput()

void SLGLImGui::onCharInput ( SLuint  c)
overridevirtual

Callback on character input.

Reimplemented from SLUiInterface.

◆ onClose()

void SLGLImGui::onClose ( )
overridevirtual

Callback on closing the application.

Reimplemented from SLUiInterface.

◆ onInitNewFrame()

void SLGLImGui::onInitNewFrame ( SLScene s,
SLSceneView sv 
)
overridevirtual

Inits a new frame for the ImGui system.

Reimplemented from SLUiInterface.

◆ onKeyPress()

void SLGLImGui::onKeyPress ( SLKey  key,
SLKey  mod 
)
overridevirtual

Callback on key press event.

Reimplemented from SLUiInterface.

◆ onKeyRelease()

void SLGLImGui::onKeyRelease ( SLKey  key,
SLKey  mod 
)
overridevirtual

Callback on key release event.

Reimplemented from SLUiInterface.

◆ onMouseDown()

void SLGLImGui::onMouseDown ( SLMouseButton  button,
SLint  x,
SLint  y 
)
overridevirtual

Callback on mouse button down event.

Reimplemented from SLUiInterface.

◆ onMouseMove()

void SLGLImGui::onMouseMove ( SLint  xPos,
SLint  yPos 
)
overridevirtual

Updates the mouse cursor position.

Reimplemented from SLUiInterface.

◆ onMouseUp()

void SLGLImGui::onMouseUp ( SLMouseButton  button,
SLint  x,
SLint  y 
)
overridevirtual

Callback on mouse button up event.

Reimplemented from SLUiInterface.

◆ onMouseWheel()

void SLGLImGui::onMouseWheel ( SLfloat  yoffset)
overridevirtual

Callback for the mouse scroll movement.

Reimplemented from SLUiInterface.

◆ onPaint()

void SLGLImGui::onPaint ( const SLRecti viewport)
overridevirtual

Callback for main rendering for the ImGui GUI system.

Reimplemented from SLUiInterface.

◆ onResize()

void SLGLImGui::onResize ( SLint  scrW,
SLint  scrH 
)
overridevirtual

Callback if window got resized.

Reimplemented from SLUiInterface.

◆ printCompileErrors()

void SLGLImGui::printCompileErrors ( SLint  shaderHandle,
const SLchar src 
)
private

Prints the compile errors in case of a GLSL compile failure.

◆ renderExtraFrame()

void SLGLImGui::renderExtraFrame ( SLScene s,
SLSceneView sv,
SLint  mouseX,
SLint  mouseY 
)
overridevirtual

Renders an extra frame with the current mouse position.

Reimplemented from SLUiInterface.

Member Data Documentation

◆ _attribLocColor

SLint SLGLImGui::_attribLocColor
private

OpenGL attribute location for color.

◆ _attribLocPosition

SLint SLGLImGui::_attribLocPosition
private

OpenGL attribute location for vertex pos.

◆ _attribLocProjMtx

SLint SLGLImGui::_attribLocProjMtx
private

OpenGL attribute location for ???

◆ _attribLocTex

SLint SLGLImGui::_attribLocTex
private

OpenGL attribute location for texture.

◆ _attribLocUV

SLint SLGLImGui::_attribLocUV
private

OpenGL attribute location for texture coords.

◆ _build

cbOnImGuiBuild SLGLImGui::_build = nullptr
private

◆ _configPath

SLstring SLGLImGui::_configPath
private

◆ _elementsHandle

SLuint SLGLImGui::_elementsHandle
private

OpenGL handle for vertex indexes.

◆ _fontDir

SLstring SLGLImGui::_fontDir
private

◆ _fontFixedDots

SLfloat SLGLImGui::_fontFixedDots
private

Active font size of fixed size font.

◆ _fontPropDots

SLfloat SLGLImGui::_fontPropDots
private

Active font size of proportional font.

◆ _fontTexture

SLuint SLGLImGui::_fontTexture
private

OpenGL texture id for font.

◆ _fragHandle

SLint SLGLImGui::_fragHandle
private

OpenGL handle for fragment shader.

◆ _mousePosPX

SLVec2f SLGLImGui::_mousePosPX
private

Mouse cursor position.

◆ _mousePressed

SLbool SLGLImGui::_mousePressed[3]
private

Mouse button press state.

◆ _mouseWheel

SLfloat SLGLImGui::_mouseWheel
private

Mouse wheel position.

◆ _progHandle

SLint SLGLImGui::_progHandle
private

OpenGL handle for shader program.

◆ _saveConfig

cbOnImGuiSaveConfig SLGLImGui::_saveConfig = nullptr
private

◆ _timeSec

SLfloat SLGLImGui::_timeSec
private

Time in seconds.

◆ _vaoHandle

SLuint SLGLImGui::_vaoHandle
private

OpenGL vertex array object handle.

◆ _vboHandle

SLuint SLGLImGui::_vboHandle
private

OpenGL handle for vertex buffer object.

◆ _vertHandle

SLint SLGLImGui::_vertHandle
private

OpenGL handle for vertex shader.

◆ fontFixedDots

SLfloat SLGLImGui::fontFixedDots = 13.0f
static

Default font size of fixed size font.

◆ fontPropDots

SLfloat SLGLImGui::fontPropDots = 16.0f
static

Default font size of proportional font.


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