mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-22 15:46:35 +00:00
Examples: DirectX11: Extracted imgui_impl_dx11.* instead imgui_impl_dx11 and imgui_impl_win32
This commit is contained in:
parent
90dffb5a06
commit
19540479d4
@ -143,13 +143,15 @@
|
|||||||
<ClInclude Include="..\..\imconfig.h" />
|
<ClInclude Include="..\..\imconfig.h" />
|
||||||
<ClInclude Include="..\..\imgui.h" />
|
<ClInclude Include="..\..\imgui.h" />
|
||||||
<ClInclude Include="..\..\imgui_internal.h" />
|
<ClInclude Include="..\..\imgui_internal.h" />
|
||||||
<ClInclude Include="imgui_impl_dx11.h" />
|
<ClInclude Include="..\imgui_impl_dx11.h" />
|
||||||
|
<ClInclude Include="..\imgui_impl_win32.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp" />
|
<ClCompile Include="..\..\imgui.cpp" />
|
||||||
<ClCompile Include="..\..\imgui_demo.cpp" />
|
<ClCompile Include="..\..\imgui_demo.cpp" />
|
||||||
<ClCompile Include="..\..\imgui_draw.cpp" />
|
<ClCompile Include="..\..\imgui_draw.cpp" />
|
||||||
<ClCompile Include="imgui_impl_dx11.cpp" />
|
<ClCompile Include="..\imgui_impl_dx11.cpp" />
|
||||||
|
<ClCompile Include="..\imgui_impl_win32.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -15,12 +15,15 @@
|
|||||||
<ClInclude Include="..\..\imgui.h">
|
<ClInclude Include="..\..\imgui.h">
|
||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="imgui_impl_dx11.h">
|
|
||||||
<Filter>sources</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\imgui_internal.h">
|
<ClInclude Include="..\..\imgui_internal.h">
|
||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\imgui_impl_win32.h">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\imgui_impl_dx11.h">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\imgui.cpp">
|
<ClCompile Include="..\..\imgui.cpp">
|
||||||
@ -29,15 +32,18 @@
|
|||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>sources</Filter>
|
<Filter>sources</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="imgui_impl_dx11.cpp">
|
|
||||||
<Filter>sources</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\imgui_demo.cpp">
|
<ClCompile Include="..\..\imgui_demo.cpp">
|
||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\imgui_draw.cpp">
|
<ClCompile Include="..\..\imgui_draw.cpp">
|
||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\imgui_impl_win32.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\imgui_impl_dx11.cpp">
|
||||||
|
<Filter>sources</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\README.txt" />
|
<None Include="..\README.txt" />
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_dx11.h"
|
#include "../imgui_impl_win32.h"
|
||||||
|
#include "../imgui_impl_dx11.h"
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
@ -125,7 +126,8 @@ int main(int, char**)
|
|||||||
// Setup ImGui binding
|
// Setup ImGui binding
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
|
ImGui_ImplWin32_Init(hwnd);
|
||||||
|
ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
|
||||||
//io.NavFlags |= ImGuiNavFlags_EnableKeyboard; // Enable Keyboard Controls
|
//io.NavFlags |= ImGuiNavFlags_EnableKeyboard; // Enable Keyboard Controls
|
||||||
|
|
||||||
// Setup style
|
// Setup style
|
||||||
@ -167,6 +169,7 @@ int main(int, char**)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ImGui_ImplDX11_NewFrame();
|
ImGui_ImplDX11_NewFrame();
|
||||||
|
ImGui_ImplWin32_NewFrame();
|
||||||
|
|
||||||
// 1. Show a simple window.
|
// 1. Show a simple window.
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
|
||||||
@ -216,6 +219,7 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui_ImplDX11_Shutdown();
|
ImGui_ImplDX11_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
CleanupDeviceD3D();
|
||||||
|
@ -31,11 +31,6 @@
|
|||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
|
||||||
// Data
|
|
||||||
static INT64 g_Time = 0;
|
|
||||||
static INT64 g_TicksPerSecond = 0;
|
|
||||||
|
|
||||||
static HWND g_hWnd = 0;
|
|
||||||
static ID3D11Device* g_pd3dDevice = NULL;
|
static ID3D11Device* g_pd3dDevice = NULL;
|
||||||
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
|
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
|
||||||
static ID3D11Buffer* g_pVB = NULL;
|
static ID3D11Buffer* g_pVB = NULL;
|
||||||
@ -247,76 +242,6 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||||||
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ImGui_ImplDX11_CreateFontsTexture()
|
static void ImGui_ImplDX11_CreateFontsTexture()
|
||||||
{
|
{
|
||||||
// Build texture atlas
|
// Build texture atlas
|
||||||
@ -538,42 +463,10 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
|
|||||||
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
|
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context)
|
bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context)
|
||||||
{
|
{
|
||||||
g_hWnd = (HWND)hwnd;
|
|
||||||
g_pd3dDevice = device;
|
g_pd3dDevice = device;
|
||||||
g_pd3dDeviceContext = device_context;
|
g_pd3dDeviceContext = device_context;
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,49 +475,10 @@ void ImGui_ImplDX11_Shutdown()
|
|||||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
g_pd3dDevice = NULL;
|
g_pd3dDevice = NULL;
|
||||||
g_pd3dDeviceContext = NULL;
|
g_pd3dDeviceContext = NULL;
|
||||||
g_hWnd = (HWND)0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX11_NewFrame()
|
void ImGui_ImplDX11_NewFrame()
|
||||||
{
|
{
|
||||||
if (!g_pFontSampler)
|
if (!g_pFontSampler)
|
||||||
ImGui_ImplDX11_CreateDeviceObjects();
|
ImGui_ImplDX11_CreateDeviceObjects();
|
||||||
|
|
||||||
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 *)¤t_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hide OS mouse cursor if ImGui is drawing it
|
|
||||||
if (io.MouseDrawCursor)
|
|
||||||
SetCursor(NULL);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
@ -11,7 +11,7 @@
|
|||||||
struct ID3D11Device;
|
struct ID3D11Device;
|
||||||
struct ID3D11DeviceContext;
|
struct ID3D11DeviceContext;
|
||||||
|
|
||||||
IMGUI_API bool ImGui_ImplDX11_Init(void* hwnd, ID3D11Device* device, ID3D11DeviceContext* device_context);
|
IMGUI_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context);
|
||||||
IMGUI_API void ImGui_ImplDX11_Shutdown();
|
IMGUI_API void ImGui_ImplDX11_Shutdown();
|
||||||
IMGUI_API void ImGui_ImplDX11_NewFrame();
|
IMGUI_API void ImGui_ImplDX11_NewFrame();
|
||||||
IMGUI_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
|
IMGUI_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
|
||||||
@ -19,10 +19,3 @@ IMGUI_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data);
|
|||||||
// Use if you want to reset your rendering device without losing ImGui state.
|
// Use if you want to reset your rendering device without losing ImGui state.
|
||||||
IMGUI_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
IMGUI_API void ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||||
IMGUI_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
IMGUI_API bool ImGui_ImplDX11_CreateDeviceObjects();
|
||||||
|
|
||||||
// Handler for Win32 messages, update mouse/keyboard data.
|
|
||||||
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
|
|
||||||
// Commented out to avoid dragging dependencies on <windows.h> types. You can copy the extern declaration in your code.
|
|
||||||
/*
|
|
||||||
IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
||||||
*/
|
|
161
examples/imgui_impl_win32.cpp
Normal file
161
examples/imgui_impl_win32.cpp
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_win32.h"
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static HWND g_hWnd = 0;
|
||||||
|
static INT64 g_Time = 0;
|
||||||
|
static INT64 g_TicksPerSecond = 0;
|
||||||
|
|
||||||
|
// Functions
|
||||||
|
bool ImGui_ImplWin32_Init(void* hwnd)
|
||||||
|
{
|
||||||
|
if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_TicksPerSecond))
|
||||||
|
return false;
|
||||||
|
if (!QueryPerformanceCounter((LARGE_INTEGER *)&g_Time))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
g_hWnd = (HWND)hwnd;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplWin32_Shutdown()
|
||||||
|
{
|
||||||
|
g_hWnd = (HWND)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGui_ImplWin32_NewFrame()
|
||||||
|
{
|
||||||
|
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 *)¤t_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
|
if (io.MouseDrawCursor)
|
||||||
|
SetCursor(NULL);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
11
examples/imgui_impl_win32.h
Normal file
11
examples/imgui_impl_win32.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
IMGUI_API bool ImGui_ImplWin32_Init(void* hwnd);
|
||||||
|
IMGUI_API void ImGui_ImplWin32_Shutdown();
|
||||||
|
IMGUI_API void ImGui_ImplWin32_NewFrame();
|
||||||
|
|
||||||
|
// Handler for Win32 messages, update mouse/keyboard data.
|
||||||
|
// You may or not need this for your implementation, but it can serve as reference for handling inputs.
|
||||||
|
// Commented out to avoid dragging dependencies on <windows.h> types. You can copy the extern declaration in your code.
|
||||||
|
/*
|
||||||
|
IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
*/
|
Loading…
Reference in New Issue
Block a user