All Projects → theluc4s → easy-dear-imgui

theluc4s / easy-dear-imgui

Licence: MIT license
Easy 'Dear ImGui' is written in a single header and makes use of directx9 to implement 'Dear ImGui' and render a window with less than 10 lines of code.

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to easy-dear-imgui

ImFrame
dear imgui + glfw framework
Stars: ✭ 86 (+473.33%)
Mutual labels:  dear-imgui
Imhex
🔍 A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.
Stars: ✭ 11,744 (+78193.33%)
Mutual labels:  dear-imgui
SdfFontDesigner
Offline font tuning/bitmap generation via shaders
Stars: ✭ 56 (+273.33%)
Mutual labels:  dear-imgui
awesome-dear-imgui
A collection of awesome dear imgui bindings, extensions and resources
Stars: ✭ 439 (+2826.67%)
Mutual labels:  dear-imgui
Rootex
An advanced C++ 3D game engine powering an in-production game yet to be announced
Stars: ✭ 161 (+973.33%)
Mutual labels:  dear-imgui
RCCpp DX11 Example
Runtime Compiled C++ example based on the Dear ImGui DirectX11 Example
Stars: ✭ 35 (+133.33%)
Mutual labels:  dear-imgui
imgui-java
JNI based binding for Dear ImGui
Stars: ✭ 270 (+1700%)
Mutual labels:  dear-imgui
sdl-imgui-example
An example of using Dear ImGui with SDL
Stars: ✭ 18 (+20%)
Mutual labels:  dear-imgui
vengi
Home of a voxel game engine and its tools (like a voxel editor)
Stars: ✭ 800 (+5233.33%)
Mutual labels:  dear-imgui
RCCpp-DearImGui-GLFW-example
Add Runtime Compiled C++ to the Dear ImGui example using the GLFW and OpenGL backend - with power saving
Stars: ✭ 61 (+306.67%)
Mutual labels:  dear-imgui
ImStudio
Real-time GUI layout designer for Dear ImGui
Stars: ✭ 285 (+1800%)
Mutual labels:  dear-imgui
odin-imgui
Odin binding for Dear ImGui
Stars: ✭ 37 (+146.67%)
Mutual labels:  dear-imgui

Easy Dear ImGui

Design goals

There are several variants for implementing Dear ImGui using C++. Each project has its implementation. My class has the following goals:

Single-header integration:

The class was built in a single header and is not linked to dependencies.

Don't fail:

If the window cannot be built or some state of the context of the imgui cannot be defined, it is safe to call the functions in the loop, nothing will be drawn and no exception will be thrown.

Assuming Visual Studio, a call to OutputDebugStringA through a log macro and you can directly view the line, function and reason for the failure.

Examples

Get the latest ImGui release and download my release.

The imgui files need to be in a 'dear_imgui' folder and the easy_dear_imgui.hpp outside that folder.

Visual Studio 2019

main.cpp

int __stdcall WinMain(
	_In_ HINSTANCE,
	_In_opt_ HINSTANCE,
	_In_ LPSTR,
	_In_ int
)
{
	// Use the easy_di namespace
	//
	easy_di::window window
	{
		"My Window",                                                  // Window name
		"my_window",                                                  // Class window name
		{ 0, 0 },                                                     // Start position window
		{ 1280, 720 },                                                // Start size window
		SW_SHOW,                                                      // Window show state       ( default parameter = SW_SHOW )
		CS_CLASSDC,                                                   // Window class style      ( default parameter = CS_CLASSDC )
		WS_OVERLAPPEDWINDOW,                                          // Window style            ( default parameter = WS_OVERLAPPEDWINDOW )
		// A wrapper for adding an icon has been added (add the icon to your project's resource and use your ID)
		//
		easy_di::utils::icon( 0 /*RESOURCE ICON ID*/, { 128, 128 } ), // Icon                    ( default parameter = nullptr )
		easy_di::utils::icon( 0 /*RESOURCE ICON ID*/, { 16, 16 } ),   // Small icon              ( default parameter = nullptr )
		true                                                          // Vertical sincronization ( default parameter = true )
	};

	// If process_message() returns false, the message was equal to WM_QUIT or CreateWindowExA failed and returned a nullptr handle.
	//
	while ( window.process_message() )
	{
		if ( window.imgui_start_frame() )
		{
			ImGui::ShowDemoWindow();

			window.imgui_end_frame();
		}

		window.set_background_color();
	}
}

Screenshot

Custom window procedure template

If you want to use a custom window procedure, use the template below and write your own.

LRESULT __stdcall custom_wnd_procedure( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param )
{
	if ( ImGui_ImplWin32_WndProcHandler( hwnd, msg, w_param, l_param ) )
		return true;

	switch ( msg )
	{
	case WM_DESTROY:
		PostQuitMessage( 0 );
		return 0;
	case WM_CLOSE:
		DestroyWindow( hwnd );
		return 0;
	case WM_SIZE:
		if ( easy_di::dx::g_ptr_d3d_device && ( w_param != SIZE_MINIMIZED ) )
		{
			easy_di::dx::g_d3d_pp.BackBufferWidth  = easy_di::low_order < unsigned short, LPARAM >( l_param );
			easy_di::dx::g_d3d_pp.BackBufferHeight = easy_di::high_order< unsigned short, LPARAM >( l_param );
			easy_di::dx::reset_device();
		}
		return 0;
	default:
		break;
	}

	return DefWindowProcA( hwnd, msg, w_param, l_param );
}

Then just define g_cwnd_proc before creating the object.

// before create the object
//
easy_di::dx::g_cwnd_proc = custom_wnd_procedure;

// create the object
//
easy_di::window window
{
	"My Window",                                                  // Window name
	"my_window",                                                  // Class window name
	{ 0, 0 },                                                     // Start position window
	{ 1280, 720 },                                                // Start size window
	SW_SHOW,                                                      // Window show state       ( default parameter = SW_SHOW )
	CS_CLASSDC,                                                   // Window class style      ( default parameter = CS_CLASSDC )
	WS_OVERLAPPEDWINDOW,                                          // Window style            ( default parameter = WS_OVERLAPPEDWINDOW )
	easy_di::utils::icon( 0 /*RESOURCE ICON ID*/, { 128, 128 } ), // Icon                    ( default parameter = nullptr )
	easy_di::utils::icon( 0 /*RESOURCE ICON ID*/, { 16, 16 } ),   // Small icon              ( default parameter = nullptr )
	true                                                          // Vertical sincronization ( default parameter = true )
};

User functions

The following functions are available:

Function name Description
bool process_message() Process the message queue and message
bool imgui_start_frame() Creates a dear imgui frame.
bool imgui_end_frame() Ends a dear imgui frame.
void set_background_color(int,int,int) Define a new background color
bool get_vsync_state() const Returns the state of vertical synchronization.
MSG& get_msg() Returns a reference to m_msg

Special thanks

Thanks to @Darkratos and @Nomade040 by test and point me improvements.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].