mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 09:27:00 +00:00
Merge branch 'master' into viewport
# Conflicts: # docs/CHANGELOG.txt # examples/imgui_impl_win32.cpp # examples/imgui_impl_win32.h
This commit is contained in:
commit
9391a97fbf
@ -70,7 +70,17 @@ Other changes:
|
|||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
VERSION 1.67 (In Progress)
|
VERSION 1.68
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Other Changes:
|
||||||
|
- Examples: Win32: Using GetForegroundWindow() instead of GetActiveWindow() to be compatible with windows created
|
||||||
|
in a different thread. (#1951, #2087, #2156, #2232) [many people]
|
||||||
|
- Examples: Win32: Added support for XInput games (if ImGuiConfigFlags_NavEnableGamepad is enabled).
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
VERSION 1.67 (Released 2019-01-14)
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
Breaking Changes:
|
Breaking Changes:
|
||||||
|
@ -346,7 +346,7 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
ImGui_ImplGlfw_UpdateMousePosAndButtons();
|
ImGui_ImplGlfw_UpdateMousePosAndButtons();
|
||||||
ImGui_ImplGlfw_UpdateMouseCursor();
|
ImGui_ImplGlfw_UpdateMouseCursor();
|
||||||
|
|
||||||
// Gamepad navigation mapping [BETA]
|
// Gamepad navigation mapping
|
||||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad)
|
if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad)
|
||||||
{
|
{
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui)
|
// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui)
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE).
|
// [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE).
|
||||||
|
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features:
|
|
||||||
// [ ] Platform: Gamepad support (best leaving it to user application to fill io.NavInputs[] with gamepad inputs from their source of choice).
|
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_win32.h"
|
#include "imgui_impl_win32.h"
|
||||||
@ -15,11 +14,14 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#endif
|
#endif
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <XInput.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2019-01-15: Inputs: Using GetForegroundWindow() instead of GetActiveWindow() to be compatible with windows created in a different thread.
|
||||||
|
// 2019-01-15: Inputs: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
|
||||||
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
||||||
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
// 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
|
||||||
// 2018-06-10: Inputs: Fixed handling of mouse wheel messages to support fine position messages (typically sent by track-pads).
|
// 2018-06-10: Inputs: Fixed handling of mouse wheel messages to support fine position messages (typically sent by track-pads).
|
||||||
@ -41,6 +43,8 @@ static HWND g_hWnd = 0;
|
|||||||
static INT64 g_Time = 0;
|
static INT64 g_Time = 0;
|
||||||
static INT64 g_TicksPerSecond = 0;
|
static INT64 g_TicksPerSecond = 0;
|
||||||
static ImGuiMouseCursor g_LastMouseCursor = ImGuiMouseCursor_COUNT;
|
static ImGuiMouseCursor g_LastMouseCursor = ImGuiMouseCursor_COUNT;
|
||||||
|
static bool g_HasGamepad = false;
|
||||||
|
static bool g_WantUpdateHasGamepad = true;
|
||||||
static bool g_WantUpdateMonitors = true;
|
static bool g_WantUpdateMonitors = true;
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward Declarations
|
||||||
@ -158,7 +162,7 @@ static void ImGui_ImplWin32_UpdateMousePos()
|
|||||||
POINT mouse_screen_pos;
|
POINT mouse_screen_pos;
|
||||||
if (!::GetCursorPos(&mouse_screen_pos))
|
if (!::GetCursorPos(&mouse_screen_pos))
|
||||||
return;
|
return;
|
||||||
if (HWND focused_hwnd = ::GetActiveWindow())
|
if (HWND focused_hwnd = ::GetForegroundWindow())
|
||||||
{
|
{
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
@ -192,6 +196,57 @@ static void ImGui_ImplWin32_UpdateMousePos()
|
|||||||
io.MouseHoveredViewport = viewport->ID;
|
io.MouseHoveredViewport = viewport->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma comment(lib, "xinput")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Gamepad navigation mapping
|
||||||
|
void ImGui_ImplWin32_UpdateGameControllers()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
||||||
|
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Calling XInputGetState() every frame on disconnected gamepads is unfortunately too slow.
|
||||||
|
// Instead we refresh gamepad availability by calling XInputGetCapabilities() _only_ after receiving WM_DEVICECHANGE.
|
||||||
|
if (g_WantUpdateHasGamepad)
|
||||||
|
{
|
||||||
|
XINPUT_CAPABILITIES caps;
|
||||||
|
g_HasGamepad = (XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &caps) == ERROR_SUCCESS);
|
||||||
|
g_WantUpdateHasGamepad = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
XINPUT_STATE xinput_state;
|
||||||
|
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||||
|
if (g_HasGamepad && XInputGetState(0, &xinput_state) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
const XINPUT_GAMEPAD& gamepad = xinput_state.Gamepad;
|
||||||
|
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||||
|
|
||||||
|
#define MAP_BUTTON(NAV_NO, BUTTON_ENUM) { io.NavInputs[NAV_NO] = (gamepad.wButtons & BUTTON_ENUM) ? 1.0f : 0.0f; }
|
||||||
|
#define MAP_ANALOG(NAV_NO, VALUE, V0, V1) { float vn = (float)(VALUE - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
|
||||||
|
MAP_BUTTON(ImGuiNavInput_Activate, XINPUT_GAMEPAD_A); // Cross / A
|
||||||
|
MAP_BUTTON(ImGuiNavInput_Cancel, XINPUT_GAMEPAD_B); // Circle / B
|
||||||
|
MAP_BUTTON(ImGuiNavInput_Menu, XINPUT_GAMEPAD_X); // Square / X
|
||||||
|
MAP_BUTTON(ImGuiNavInput_Input, XINPUT_GAMEPAD_Y); // Triangle / Y
|
||||||
|
MAP_BUTTON(ImGuiNavInput_DpadLeft, XINPUT_GAMEPAD_DPAD_LEFT); // D-Pad Left
|
||||||
|
MAP_BUTTON(ImGuiNavInput_DpadRight, XINPUT_GAMEPAD_DPAD_RIGHT); // D-Pad Right
|
||||||
|
MAP_BUTTON(ImGuiNavInput_DpadUp, XINPUT_GAMEPAD_DPAD_UP); // D-Pad Up
|
||||||
|
MAP_BUTTON(ImGuiNavInput_DpadDown, XINPUT_GAMEPAD_DPAD_DOWN); // D-Pad Down
|
||||||
|
MAP_BUTTON(ImGuiNavInput_FocusPrev, XINPUT_GAMEPAD_LEFT_SHOULDER); // L1 / LB
|
||||||
|
MAP_BUTTON(ImGuiNavInput_FocusNext, XINPUT_GAMEPAD_RIGHT_SHOULDER); // R1 / RB
|
||||||
|
MAP_BUTTON(ImGuiNavInput_TweakSlow, XINPUT_GAMEPAD_LEFT_SHOULDER); // L1 / LB
|
||||||
|
MAP_BUTTON(ImGuiNavInput_TweakFast, XINPUT_GAMEPAD_RIGHT_SHOULDER); // R1 / RB
|
||||||
|
MAP_ANALOG(ImGuiNavInput_LStickLeft, gamepad.sThumbLX, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32768);
|
||||||
|
MAP_ANALOG(ImGuiNavInput_LStickRight, gamepad.sThumbLX, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767);
|
||||||
|
MAP_ANALOG(ImGuiNavInput_LStickUp, gamepad.sThumbLY, +XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, +32767);
|
||||||
|
MAP_ANALOG(ImGuiNavInput_LStickDown, gamepad.sThumbLY, -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE, -32767);
|
||||||
|
#undef MAP_BUTTON
|
||||||
|
#undef MAP_ANALOG
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImGui_ImplWin32_NewFrame()
|
void ImGui_ImplWin32_NewFrame()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
@ -227,12 +282,18 @@ void ImGui_ImplWin32_NewFrame()
|
|||||||
g_LastMouseCursor = mouse_cursor;
|
g_LastMouseCursor = mouse_cursor;
|
||||||
ImGui_ImplWin32_UpdateMouseCursor();
|
ImGui_ImplWin32_UpdateMouseCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update game controllers (if available)
|
||||||
|
ImGui_ImplWin32_UpdateGameControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
|
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
|
||||||
#ifndef WM_MOUSEHWHEEL
|
#ifndef WM_MOUSEHWHEEL
|
||||||
#define WM_MOUSEHWHEEL 0x020E
|
#define WM_MOUSEHWHEEL 0x020E
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef DBT_DEVNODES_CHANGED
|
||||||
|
#define DBT_DEVNODES_CHANGED 0x0007
|
||||||
|
#endif
|
||||||
|
|
||||||
// Process Win32 mouse/keyboard inputs.
|
// Process Win32 mouse/keyboard inputs.
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
@ -300,6 +361,10 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
|
|||||||
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor())
|
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor())
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
case WM_DEVICECHANGE:
|
||||||
|
if ((UINT)wParam == DBT_DEVNODES_CHANGED)
|
||||||
|
g_WantUpdateHasGamepad = true;
|
||||||
|
return 0;
|
||||||
case WM_DISPLAYCHANGE:
|
case WM_DISPLAYCHANGE:
|
||||||
g_WantUpdateMonitors = true;
|
g_WantUpdateMonitors = true;
|
||||||
return 0;
|
return 0;
|
||||||
@ -574,7 +639,7 @@ static bool ImGui_ImplWin32_GetWindowFocus(ImGuiViewport* viewport)
|
|||||||
{
|
{
|
||||||
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
|
||||||
IM_ASSERT(data->Hwnd != 0);
|
IM_ASSERT(data->Hwnd != 0);
|
||||||
return ::GetActiveWindow() == data->Hwnd;
|
return ::GetForegroundWindow() == data->Hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ImGui_ImplWin32_GetWindowMinimized(ImGuiViewport* viewport)
|
static bool ImGui_ImplWin32_GetWindowMinimized(ImGuiViewport* viewport)
|
||||||
|
@ -5,9 +5,8 @@
|
|||||||
// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui)
|
// [X] Platform: Clipboard support (for Win32 this is actually part of core imgui)
|
||||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||||
// [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE).
|
// [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE).
|
||||||
|
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||||
// Missing features:
|
|
||||||
// [ ] Platform: Gamepad support (best leaving it to user application to fill io.NavInputs[] with gamepad inputs from their source of choice).
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (main code and documentation)
|
// (main code and documentation)
|
||||||
|
|
||||||
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
|
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
|
||||||
|
6
imgui.h
6
imgui.h
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (headers)
|
// (headers)
|
||||||
|
|
||||||
// See imgui.cpp file for documentation.
|
// See imgui.cpp file for documentation.
|
||||||
@ -46,8 +46,8 @@ Index of this file:
|
|||||||
|
|
||||||
// Version
|
// Version
|
||||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY00 then bounced up to XYY01 when release tagging happens)
|
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY00 then bounced up to XYY01 when release tagging happens)
|
||||||
#define IMGUI_VERSION "1.67"
|
#define IMGUI_VERSION "1.68 WIP"
|
||||||
#define IMGUI_VERSION_NUM 16603
|
#define IMGUI_VERSION_NUM 16800
|
||||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert))
|
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert))
|
||||||
#define IMGUI_HAS_VIEWPORT 1 // Viewport WIP branch
|
#define IMGUI_HAS_VIEWPORT 1 // Viewport WIP branch
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (demo code)
|
// (demo code)
|
||||||
|
|
||||||
// Message to the person tempted to delete this file when integrating Dear ImGui into their code base:
|
// Message to the person tempted to delete this file when integrating Dear ImGui into their code base:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (drawing and font code)
|
// (drawing and font code)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (internal structures/api)
|
// (internal structures/api)
|
||||||
|
|
||||||
// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
|
// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// dear imgui, v1.67
|
// dear imgui, v1.68 WIP
|
||||||
// (widgets code)
|
// (widgets code)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user