Skip to main content

Class SimpleImGuiScene

Simple class to wrap everything necessary to use ImGui inside a window. Currently this always creates a new window rather than take ownership of an existing one.

Internally this uses SDL and DirectX 11 or OpenGL 3.2. Rendering is tied to vsync.

Assembly: ImGuiScene.dll
View Source
Declaration
public class SimpleImGuiScene : IDisposable

Implements:
System.IDisposable

Properties

Window

The main application container window where we do all our rendering and input processing.

View Source
Declaration
public SimpleSDLWindow Window { get; }

Renderer

The renderer backend being used to render into this window.

View Source
Declaration
public IRenderer Renderer { get; }

ShouldQuit

Whether the user application has requested the system to terminate.

View Source
Declaration
public bool ShouldQuit { get; set; }

FramerateLimit

The method of framerate control used by the scene and renderer. The default behavior is ImGuiScene.FramerateLimit.LimitType.Vsync, which is greatly recommended unless you have a specific need to change it.

View Source
Declaration
public FramerateLimit FramerateLimit { get; set; }

ImGuiIniPath

View Source
Declaration
public string ImGuiIniPath { get; set; }

PauseWhenUnfocused

Whether rendering should be paused when the window is not active. Window events will still be processed. This should help reduce processing when the overlay is not the focus, but obviously cannot be used if you are rendering dynamic data.

View Source
Declaration
public bool PauseWhenUnfocused { get; set; }

OnSDLEvent

Delegate for providing user event handler methods that want to respond to SDL_Events. This is just a convenience wrapper around ImGuiScene.SimpleSDLWindow.OnSDLEvent.

View Source
Declaration
public SimpleSDLWindow.ProcessEventDelegate OnSDLEvent { get; set; }

Fields

OnBuildUI

User methods invoked every ImGui frame to construct custom UIs.

View Source
Declaration
public SimpleImGuiScene.BuildUIDelegate OnBuildUI

Methods

CreateOverlay(RendererBackend, SDL_Scancode, float[], bool)

Helper method to create a fullscreen transparent overlay that exits when pressing the specified key.

View Source
Declaration
public static SimpleImGuiScene CreateOverlay(RendererFactory.RendererBackend rendererBackend, SDL.SDL_Scancode closeOverlayKey = SDL_Scancode.SDL_SCANCODE_ESCAPE, float[] transparentColor = null, bool enableRenderDebugging = false)
Returns

ImGuiScene.SimpleImGuiScene

Parameters
TypeNameDescription
ImGuiScene.RendererFactory.RendererBackendrendererBackendWhich rendering backend to use.
SDL2.SDL.SDL_ScancodecloseOverlayKeyWhich SDL2.SDL.SDL_Scancode to listen for in order to exit the scene. Defaults to SDL2.SDL.SDL_Scancode.SDL_SCANCODE_ESCAPE.
System.Single[]transparentColorA float[4] representing the background window color that will be masked as transparent. Defaults to solid black.
System.BooleanenableRenderDebuggingWhether to enable debugging of the renderer internals. This will likely greatly impact performance and is not usually recommended.

LoadImage(string)

Loads an image from a file and creates the corresponding GPU texture.

View Source
Declaration
public TextureWrap LoadImage(string path)
Returns

ImGuiScene.TextureWrap: A ImGuiScene.TextureWrap associated with the loaded texture resource, containing a handle suitable for direct use in ImGui, or null on failure.

Parameters
TypeNameDescription
System.StringpathThe filepath to the image

LoadImage(byte[])

Loads an image from a byte array of image data and creates the corresponding texture resource.

View Source
Declaration
public TextureWrap LoadImage(byte[] imageBytes)
Returns

ImGuiScene.TextureWrap: A ImGuiScene.TextureWrap associated with the loaded texture resource, containing a handle suitable for direct use in ImGui, or null on failure.

Parameters
TypeNameDescription
System.Byte[]imageBytesThe raw image data

LoadImageRaw(byte[], int, int, int)

View Source
Declaration
public TextureWrap LoadImageRaw(byte[] imageData, int width, int height, int numChannels = 4)
Returns

ImGuiScene.TextureWrap

Parameters
TypeName
System.Byte[]imageData
System.Int32width
System.Int32height
System.Int32numChannels

Update()

Performs a single-frame update of ImGui and renders it to the window. This method does not check any quit conditions.

View Source
Declaration
public void Update()

Run()

Simple method to run the scene in a loop until the window is closed or the application requests an exit (via ImGuiScene.SimpleImGuiScene.ShouldQuit)

View Source
Declaration
public void Run()

Dispose(bool)

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeName
System.Booleandisposing

~SimpleImGuiScene()

View Source
Declaration
protected ~SimpleImGuiScene()

Dispose()

View Source
Declaration
public void Dispose()

Implements

  • System.IDisposable