@ -20,12 +20,6 @@
# include <d3d12.h>
# include <d3d12.h>
# include <d3dcompiler.h>
# include <d3dcompiler.h>
// Win32 data
static HWND g_hWnd = 0 ;
static INT64 g_Time = 0 ;
static INT64 g_TicksPerSecond = 0 ;
static ImGuiMouseCursor g_LastMouseCursor = ImGuiMouseCursor_Count_ ;
// DirectX data
// DirectX data
static ID3D12Device * g_pd3dDevice = NULL ;
static ID3D12Device * g_pd3dDevice = NULL ;
static ID3D12GraphicsCommandList * g_pd3dCommandList = NULL ;
static ID3D12GraphicsCommandList * g_pd3dCommandList = NULL ;
@ -221,110 +215,6 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data)
}
}
}
}
static void ImGui_ImplWin32_UpdateMouseCursor ( )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGuiMouseCursor imgui_cursor = io . MouseDrawCursor ? ImGuiMouseCursor_None : ImGui : : GetMouseCursor ( ) ;
if ( imgui_cursor = = ImGuiMouseCursor_None )
{
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
: : SetCursor ( NULL ) ;
}
else
{
// Hardware cursor type
LPTSTR win32_cursor = IDC_ARROW ;
switch ( imgui_cursor )
{
case ImGuiMouseCursor_Arrow : win32_cursor = IDC_ARROW ; break ;
case ImGuiMouseCursor_TextInput : win32_cursor = IDC_IBEAM ; break ;
case ImGuiMouseCursor_ResizeAll : win32_cursor = IDC_SIZEALL ; break ;
case ImGuiMouseCursor_ResizeEW : win32_cursor = IDC_SIZEWE ; break ;
case ImGuiMouseCursor_ResizeNS : win32_cursor = IDC_SIZENS ; break ;
case ImGuiMouseCursor_ResizeNESW : win32_cursor = IDC_SIZENESW ; break ;
case ImGuiMouseCursor_ResizeNWSE : win32_cursor = IDC_SIZENWSE ; break ;
}
: : SetCursor ( : : LoadCursor ( NULL , win32_cursor ) ) ;
}
}
// Process Win32 mouse/keyboard inputs.
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag.
IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler ( HWND hwnd , UINT msg , WPARAM wParam , LPARAM lParam )
{
if ( ImGui : : GetCurrentContext ( ) = = NULL )
return 0 ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
switch ( msg )
{
case WM_LBUTTONDOWN : case WM_LBUTTONDBLCLK :
case WM_RBUTTONDOWN : case WM_RBUTTONDBLCLK :
case WM_MBUTTONDOWN : case WM_MBUTTONDBLCLK :
{
int button = 0 ;
if ( msg = = WM_LBUTTONDOWN | | msg = = WM_LBUTTONDBLCLK ) button = 0 ;
if ( msg = = WM_RBUTTONDOWN | | msg = = WM_RBUTTONDBLCLK ) button = 1 ;
if ( msg = = WM_MBUTTONDOWN | | msg = = WM_MBUTTONDBLCLK ) button = 2 ;
if ( ! ImGui : : IsAnyMouseDown ( ) & & : : GetCapture ( ) = = NULL )
: : SetCapture ( hwnd ) ;
io . MouseDown [ button ] = true ;
return 0 ;
}
case WM_LBUTTONUP :
case WM_RBUTTONUP :
case WM_MBUTTONUP :
{
int button = 0 ;
if ( msg = = WM_LBUTTONUP ) button = 0 ;
if ( msg = = WM_RBUTTONUP ) button = 1 ;
if ( msg = = WM_MBUTTONUP ) button = 2 ;
io . MouseDown [ button ] = false ;
if ( ! ImGui : : IsAnyMouseDown ( ) & & : : GetCapture ( ) = = hwnd )
: : ReleaseCapture ( ) ;
return 0 ;
}
case WM_MOUSEWHEEL :
io . MouseWheel + = GET_WHEEL_DELTA_WPARAM ( wParam ) > 0 ? + 1.0f : - 1.0f ;
return 0 ;
case WM_MOUSEHWHEEL :
io . MouseWheelH + = GET_WHEEL_DELTA_WPARAM ( wParam ) > 0 ? + 1.0f : - 1.0f ;
return 0 ;
case WM_MOUSEMOVE :
io . MousePos . x = ( signed short ) ( lParam ) ;
io . MousePos . y = ( signed short ) ( lParam > > 16 ) ;
return 0 ;
case WM_KEYDOWN :
case WM_SYSKEYDOWN :
if ( wParam < 256 )
io . KeysDown [ wParam ] = 1 ;
return 0 ;
case WM_KEYUP :
case WM_SYSKEYUP :
if ( wParam < 256 )
io . KeysDown [ wParam ] = 0 ;
return 0 ;
case WM_CHAR :
// You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if ( wParam > 0 & & wParam < 0x10000 )
io . AddInputCharacter ( ( unsigned short ) wParam ) ;
return 0 ;
case WM_SETCURSOR :
if ( LOWORD ( lParam ) = = HTCLIENT )
{
ImGui_ImplWin32_UpdateMouseCursor ( ) ;
return 1 ;
}
return 0 ;
}
return 0 ;
}
static void ImGui_ImplDX12_CreateFontsTexture ( )
static void ImGui_ImplDX12_CreateFontsTexture ( )
{
{
// Build texture atlas
// Build texture atlas
@ -690,13 +580,9 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
}
}
}
}
bool ImGui_ImplDX12_Init ( void * hwnd , int num_frames_in_flight ,
bool ImGui_ImplDX12_Init ( ID3D12Device * device , int num_frames_in_flight , DXGI_FORMAT rtv_format ,
ID3D12Device * device ,
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle , D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle )
DXGI_FORMAT rtv_format ,
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle ,
D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle )
{
{
g_hWnd = ( HWND ) hwnd ;
g_pd3dDevice = device ;
g_pd3dDevice = device ;
g_RTVFormat = rtv_format ;
g_RTVFormat = rtv_format ;
g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle ;
g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle ;
@ -713,36 +599,6 @@ bool ImGui_ImplDX12_Init(void* hwnd, int num_frames_in_flight,
g_pFrameResources [ i ] . IndexBufferSize = 10000 ;
g_pFrameResources [ i ] . IndexBufferSize = 10000 ;
}
}
if ( ! QueryPerformanceFrequency ( ( LARGE_INTEGER * ) & g_TicksPerSecond ) )
return false ;
if ( ! QueryPerformanceCounter ( ( LARGE_INTEGER * ) & g_Time ) )
return false ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
io . KeyMap [ ImGuiKey_Tab ] = VK_TAB ; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime.
io . KeyMap [ ImGuiKey_LeftArrow ] = VK_LEFT ;
io . KeyMap [ ImGuiKey_RightArrow ] = VK_RIGHT ;
io . KeyMap [ ImGuiKey_UpArrow ] = VK_UP ;
io . KeyMap [ ImGuiKey_DownArrow ] = VK_DOWN ;
io . KeyMap [ ImGuiKey_PageUp ] = VK_PRIOR ;
io . KeyMap [ ImGuiKey_PageDown ] = VK_NEXT ;
io . KeyMap [ ImGuiKey_Home ] = VK_HOME ;
io . KeyMap [ ImGuiKey_End ] = VK_END ;
io . KeyMap [ ImGuiKey_Insert ] = VK_INSERT ;
io . KeyMap [ ImGuiKey_Delete ] = VK_DELETE ;
io . KeyMap [ ImGuiKey_Backspace ] = VK_BACK ;
io . KeyMap [ ImGuiKey_Space ] = VK_SPACE ;
io . KeyMap [ ImGuiKey_Enter ] = VK_RETURN ;
io . KeyMap [ ImGuiKey_Escape ] = VK_ESCAPE ;
io . KeyMap [ ImGuiKey_A ] = ' A ' ;
io . KeyMap [ ImGuiKey_C ] = ' C ' ;
io . KeyMap [ ImGuiKey_V ] = ' V ' ;
io . KeyMap [ ImGuiKey_X ] = ' X ' ;
io . KeyMap [ ImGuiKey_Y ] = ' Y ' ;
io . KeyMap [ ImGuiKey_Z ] = ' Z ' ;
io . ImeWindowHandle = g_hWnd ;
return true ;
return true ;
}
}
@ -751,7 +607,6 @@ void ImGui_ImplDX12_Shutdown()
ImGui_ImplDX12_InvalidateDeviceObjects ( ) ;
ImGui_ImplDX12_InvalidateDeviceObjects ( ) ;
delete [ ] g_pFrameResources ;
delete [ ] g_pFrameResources ;
g_pd3dDevice = NULL ;
g_pd3dDevice = NULL ;
g_hWnd = ( HWND ) 0 ;
g_pd3dCommandList = NULL ;
g_pd3dCommandList = NULL ;
g_hFontSrvCpuDescHandle . ptr = 0 ;
g_hFontSrvCpuDescHandle . ptr = 0 ;
g_hFontSrvGpuDescHandle . ptr = 0 ;
g_hFontSrvGpuDescHandle . ptr = 0 ;
@ -766,46 +621,4 @@ void ImGui_ImplDX12_NewFrame(ID3D12GraphicsCommandList* command_list)
ImGui_ImplDX12_CreateDeviceObjects ( ) ;
ImGui_ImplDX12_CreateDeviceObjects ( ) ;
g_pd3dCommandList = command_list ;
g_pd3dCommandList = command_list ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
// Setup display size (every frame to accommodate for window resizing)
RECT rect ;
GetClientRect ( g_hWnd , & rect ) ;
io . DisplaySize = ImVec2 ( ( float ) ( rect . right - rect . left ) , ( float ) ( rect . bottom - rect . top ) ) ;
// Setup time step
INT64 current_time ;
QueryPerformanceCounter ( ( LARGE_INTEGER * ) & current_time ) ;
io . DeltaTime = ( float ) ( current_time - g_Time ) / g_TicksPerSecond ;
g_Time = current_time ;
// Read keyboard modifiers inputs
io . KeyCtrl = ( GetKeyState ( VK_CONTROL ) & 0x8000 ) ! = 0 ;
io . KeyShift = ( GetKeyState ( VK_SHIFT ) & 0x8000 ) ! = 0 ;
io . KeyAlt = ( GetKeyState ( VK_MENU ) & 0x8000 ) ! = 0 ;
io . KeySuper = false ;
// io.KeysDown : filled by WM_KEYDOWN/WM_KEYUP events
// io.MousePos : filled by WM_MOUSEMOVE events
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events
// Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
if ( io . WantMoveMouse )
{
POINT pos = { ( int ) io . MousePos . x , ( int ) io . MousePos . y } ;
ClientToScreen ( g_hWnd , & pos ) ;
SetCursorPos ( pos . x , pos . y ) ;
}
// Update OS mouse cursor with the cursor requested by imgui
ImGuiMouseCursor mouse_cursor = io . MouseDrawCursor ? ImGuiMouseCursor_None : ImGui : : GetMouseCursor ( ) ;
if ( g_LastMouseCursor ! = mouse_cursor )
{
g_LastMouseCursor = mouse_cursor ;
ImGui_ImplWin32_UpdateMouseCursor ( ) ;
}
// Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application.
ImGui : : NewFrame ( ) ;
}
}