#include <imguiservice.h>
Public Member Functions | |
IMGuiService (ServiceConfiguration *configuration) | |
void | draw () |
void | selectWindow (nap::ResourcePtr< RenderWindow > window) |
ImGuiContext * | getContext (nap::ResourcePtr< RenderWindow > window) |
ImGuiContext * | findContext (int windowID) |
float | getScale () const |
float | getScale (const ImGuiContext *context) const |
const gui::ColorPalette & | getPalette () const |
ImGuiContext * | processInputEvent (const InputEvent &event) |
bool | isCapturingKeyboard (ImGuiContext *context) |
bool | isCapturingMouse (ImGuiContext *context) |
ImTextureID | getTextureHandle (const nap::Texture2D &texture) const |
nap::Icon & | getIcon (std::string &&name) |
bool | loadIcon (const std::string &name, const nap::Module &module, utility::ErrorState &error) |
![]() | |
UNPREFIXED_MODULE_NAME_INPUTCASE | Service (ServiceConfiguration *configuration) |
Service (ServiceConfiguration *configuration) | |
virtual | ~Service () |
Core & | getCore () |
const Core & | getCore () const |
std::string | getTypeName () const |
const Module & | getModule () const |
Service (Service &)=delete | |
Service & | operator= (const Service &)=delete |
Service (Service &&)=delete | |
Service & | operator= (Service &&)=delete |
Protected Member Functions | |
virtual bool | init (utility::ErrorState &error) override |
virtual void | getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override |
virtual void | update (double deltaTime) override |
virtual void | postUpdate (double deltaTime) override |
virtual void | preShutdown () override |
virtual void | shutdown () override |
virtual void | registerObjectCreators (rtti::Factory &factory) override |
![]() | |
virtual void | created () |
virtual void | preUpdate (double deltaTime) |
virtual void | preResourcesLoaded () |
virtual void | postResourcesLoaded () |
template<typename SERVICE_CONFIG > | |
SERVICE_CONFIG * | getConfiguration () |
template<typename SERVICE_CONFIG > | |
const SERVICE_CONFIG * | getConfiguration () const |
std::string | getIniFilePath () const |
std::string | getIniFilePath (const std::string &appendix) const |
This service manages the global ImGui state. Call draw() inside a window render pass to draw the GUI to screen. Call selectWindow() to select the window subsequent ImGUI calls apply to. Explicit window selection is only necessary when there is more than 1 window.
Only call selectWindow() on application update, not when rendering the GUI to screen. The service automatically creates a new GUI frame before application update.
IMGuiService | ( | ServiceConfiguration * | configuration | ) |
Default constructor
void draw | ( | ) |
Draws the GUI elements for the currently active window to screen.
ImGuiContext* findContext | ( | int | windowID | ) |
Returns the ImGUI context associated with the given window id.
windowID | the render window id |
ImGuiContext* getContext | ( | nap::ResourcePtr< RenderWindow > | window | ) |
Returns the ImGUI context associated with the given window.
window | the render window |
|
overrideprotectedvirtual |
nap::Icon& getIcon | ( | std::string && | name | ) |
Returns an icon with the given name and extension. Note that the icon must exist. Only ask for icons with their names explicitly declared in code, for example: 'icon::save'
name | the name, including extension, of the icon to load |
const gui::ColorPalette& getPalette | ( | ) | const |
Returns the GUI color palette.
float getScale | ( | ) | const |
Returns the scaling factor of the current active context. The scaling factor is calculated using the display DPI (if high DPI rendering is enabled) and the global GUI scale.
float getScale | ( | const ImGuiContext * | context | ) | const |
Returns the scaling factor for the given context. The scaling factor is calculated using the display DPI (if high DPI rendering is enabled) and the global GUI scale.
context | the ImGUI context |
ImTextureID getTextureHandle | ( | const nap::Texture2D & | texture | ) | const |
Returns a texture handle that can be used to display a Vulkan texture inside ImGUI. Alternatively, use the ImGUI::Image(nap::Texture2D&, ...) utility function, to immediately display a texture instead. Internally the handles are cached, it is therefore fine to call this function every frame. Keep in mind that a handle (descriptor set) is created for every unique texture.
|
overrideprotectedvirtual |
Initializes the IMGui library. This will also create all associated gui devices objects Note that a GUI can only be associated with the primary window (for now).
error | contains the error message if the lib could not be initialized correctly |
Reimplemented from Service.
bool isCapturingKeyboard | ( | ImGuiContext * | context | ) |
bool isCapturingMouse | ( | ImGuiContext * | context | ) |
bool loadIcon | ( | const std::string & | name, |
const nap::Module & | module, | ||
utility::ErrorState & | error | ||
) |
Create and add an icon to the default set of icons. The system looks for the icon in the data search paths of the module. On success call getIcon() to retrieve and draw the icon.
Call this function on initialization of your service and make sure your icon names are unique. Duplicates are not allowed!
name | the name of the icon, including extension |
module | the module that points to the icon |
error | contains the error message if the load operations fails |
|
overrideprotectedvirtual |
Ends frame operation for all contexts.
Reimplemented from Service.
|
overrideprotectedvirtual |
Saves all gui .ini files
Reimplemented from Service.
ImGuiContext* processInputEvent | ( | const InputEvent & | event | ) |
Forwards window input events to the GUI, called from GUIAppEventHandler.
|
overrideprotectedvirtual |
Registers all gui object creation objects
Reimplemented from Service.
void selectWindow | ( | nap::ResourcePtr< RenderWindow > | window | ) |
Select the window all subsequent ImGUI calls apply to. Explicit selection is only necessary when there is more than 1 window. Only call selectWindow() on application update, not when rendering the GUI to screen.
window | the window to select |
|
overrideprotectedvirtual |
Deletes all GUI related resources
Reimplemented from Service.
|
overrideprotectedvirtual |
Allows IMGUI to draw a new frame. This is called automatically by core in the app loop
deltaTime | the time in seconds between ticks |
Reimplemented from Service.