mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Viewport: Reorganized viewport enable flags. Both user + platform + renderer need to enable a flag. (#1542)
This commit is contained in:
parent
52c78820aa
commit
9dcc07422e
@ -115,7 +115,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
|
@ -118,7 +118,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
|
@ -289,7 +289,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
|
@ -479,7 +479,8 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
g_pd3dDevice = device;
|
||||
g_pFactory = pFactory;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_RendererHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplDX10_InitPlatformInterface();
|
||||
return true;
|
||||
}
|
||||
|
@ -487,7 +487,8 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
|
||||
g_pd3dDevice = device;
|
||||
g_pd3dDeviceContext = device_context;
|
||||
g_pFactory = pFactory;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_RendererHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplDX11_InitPlatformInterface();
|
||||
return true;
|
||||
}
|
||||
|
@ -605,7 +605,8 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
||||
}
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_RendererHasViewports; // FIXME-VIEWPORT: Actually unfinshed..
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplDX12_InitPlatformInterface();
|
||||
|
||||
return true;
|
||||
|
@ -153,7 +153,8 @@ bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks)
|
||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
main_viewport->PlatformHandle = (void*)g_Window;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_PlatformHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplGlfw_InitPlatformInterface();
|
||||
|
||||
g_ClientApi = GlfwClientApi_OpenGL;
|
||||
|
@ -45,7 +45,10 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
|
||||
strcpy(g_GlslVersion, glsl_version);
|
||||
strcat(g_GlslVersion, "\n");
|
||||
|
||||
ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_RendererHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplOpenGL3_InitPlatformInterface();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -149,8 +149,11 @@ bool ImGui_ImplSDL2_Init(SDL_Window* window, void* sdl_gl_context)
|
||||
// Our mouse update function expect PlatformHandle to be filled for the main viewport
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
main_viewport->PlatformHandle = (void*)window;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
#if SDL_VERSION_ATLEAST(2,0,4)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_PlatformHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplSDL2_InitPlatformInterface(window, sdl_gl_context);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -172,7 +175,6 @@ static void ImGui_ImplSDL2_UpdateMouse()
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
io.MousePosViewport = 0;
|
||||
io.MouseHoveredViewport = 0;
|
||||
io.ConfigFlags &= ~ImGuiConfigFlags_PlatformHasMouseHoveredViewport; // FIXME-VIEWPORT: We can't get this info properly with SDL, capture is messing up with SDL_WINDOW_MOUSE_FOCUS report and we'd need to handle _NoInputs
|
||||
|
||||
int mx, my;
|
||||
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
|
||||
|
@ -703,7 +703,8 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplVulkan_CreateDeviceObjects();
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_RendererHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplVulkan_InitPlatformInterface();
|
||||
|
||||
return true;
|
||||
|
@ -71,7 +71,8 @@ bool ImGui_ImplWin32_Init(void* hwnd)
|
||||
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
|
||||
main_viewport->PlatformHandle = (void*)g_hWnd;
|
||||
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
io.ConfigFlags |= ImGuiConfigFlags_PlatformHasViewports;
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
ImGui_ImplWin32_InitPlatformInterface();
|
||||
|
||||
return true;
|
||||
|
@ -35,7 +35,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
|
@ -37,7 +37,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplSDL2_Init(window, gl_context);
|
||||
|
@ -344,7 +344,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||
|
@ -353,7 +353,7 @@ int main(int, char**)
|
||||
// Setup ImGui binding
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_MultiViewports;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_EnableViewports;
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||
|
32
imgui.cpp
32
imgui.cpp
@ -3246,7 +3246,7 @@ static void ImGui::UpdateMovingWindowDropViewport(ImGuiWindow* window)
|
||||
// On release we either drop window over an existing viewport or create a new one
|
||||
// (We convert position from one viewport space to another, which is unnecessary at the moment but allows us to have viewport overlapping in term of imgui position)
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports))
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports))
|
||||
return;
|
||||
|
||||
ImRect mouse_viewport_rect = g.MouseViewport->GetRect();
|
||||
@ -3386,11 +3386,11 @@ static void ImGui::UpdateViewports()
|
||||
ImGuiViewport* main_viewport = g.Viewports[0];
|
||||
IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID);
|
||||
ImVec2 main_viewport_os_desktop_pos = ImVec2(0.0f, 0.0f);
|
||||
if ((g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports))
|
||||
if ((g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports))
|
||||
main_viewport_os_desktop_pos = g.IO.PlatformInterface.GetWindowPos(main_viewport);
|
||||
Viewport(IMGUI_VIEWPORT_DEFAULT_ID, ImGuiViewportFlags_MainViewport, main_viewport_os_desktop_pos, g.IO.DisplaySize);
|
||||
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports))
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports))
|
||||
{
|
||||
g.MouseViewport = g.MouseLastViewport = main_viewport;
|
||||
return;
|
||||
@ -3541,15 +3541,23 @@ void ImGui::NewFrame()
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard)
|
||||
IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation.");
|
||||
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
{
|
||||
if ((g.IO.ConfigFlags & ImGuiConfigFlags_PlatformHasViewports) && (g.IO.ConfigFlags & ImGuiConfigFlags_RendererHasViewports))
|
||||
{
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
||||
IM_ASSERT(g.IO.RenderDrawListsFn == NULL); // Call ImGui::Render() then pass ImGui::GetDrawData() yourself to your render function!
|
||||
#endif
|
||||
IM_ASSERT(g.IO.PlatformInterface.CreateViewport != NULL);
|
||||
IM_ASSERT(g.IO.PlatformInterface.DestroyViewport != NULL);
|
||||
//IM_ASSERT(g.IO.PlatformInterface.RenderViewport != NULL || g.IO.RendererInterface.RenderViewport != NULL); // Missing rendering function
|
||||
IM_ASSERT(g.Viewports[0]->PlatformUserData != NULL); // Platform init function didn't setup main viewport
|
||||
IM_ASSERT(g.IO.PlatformInterface.CreateViewport != NULL);
|
||||
IM_ASSERT(g.IO.PlatformInterface.DestroyViewport != NULL);
|
||||
//IM_ASSERT(g.IO.PlatformInterface.RenderViewport != NULL || g.IO.RendererInterface.RenderViewport != NULL); // Missing rendering function
|
||||
IM_ASSERT(g.Viewports[0]->PlatformUserData != NULL); // Platform init function didn't setup main viewport
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable feature, our back-ends do not support it
|
||||
g.IO.ConfigFlags &= ~ImGuiConfigFlags_EnableViewports;
|
||||
}
|
||||
}
|
||||
|
||||
// Load settings on first frame
|
||||
@ -4354,7 +4362,7 @@ void ImGui::EndFrame()
|
||||
|
||||
g.FrameCountEnded = g.FrameCount;
|
||||
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
UpdatePlatformWindows();
|
||||
}
|
||||
|
||||
@ -4418,7 +4426,7 @@ void ImGui::Render()
|
||||
void ImGui::RenderAdditionalViewports()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports)
|
||||
if (g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports)
|
||||
RenderPlatformWindows();
|
||||
}
|
||||
|
||||
@ -5908,7 +5916,7 @@ static void ImGui::UpdateWindowViewport(ImGuiWindow* window, bool window_pos_set
|
||||
|
||||
// Restore main viewport if multi viewports are not supported by the back-end
|
||||
ImGuiViewport* main_viewport = g.Viewports[0];
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_MultiViewports))
|
||||
if (!(g.IO.ConfigFlags & ImGuiConfigFlags_EnableViewports))
|
||||
{
|
||||
window->Viewport = main_viewport;
|
||||
window->ViewportId = main_viewport->ID;
|
||||
|
16
imgui.h
16
imgui.h
@ -772,18 +772,20 @@ enum ImGuiNavInput_
|
||||
enum ImGuiConfigFlags_
|
||||
{
|
||||
// Navigation
|
||||
ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.KeyDown[].
|
||||
ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Master gamepad navigation enable flag. This is mostly to instruct your imgui back-end to fill io.NavInputs[].
|
||||
ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.KeyDown[].
|
||||
ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Gamepad navigation enable flag. This is mostly to instruct your imgui back-end to fill io.NavInputs[].
|
||||
ImGuiConfigFlags_NavMoveMouse = 1 << 2, // Request navigation to allow moving the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is awkward. Will update io.MousePos and set io.WantMoveMouse=true. If enabled you MUST honor io.WantMoveMouse requests in your binding, otherwise ImGui will react as if the mouse is jumping around back and forth.
|
||||
ImGuiConfigFlags_NavNoCaptureKeyboard = 1 << 3, // Do not set the io.WantCaptureKeyboard flag with io.NavActive is set.
|
||||
|
||||
// [BETA] Viewports
|
||||
ImGuiConfigFlags_MultiViewports = 1 << 4, // User enable multiple viewports (require io.PlatformInterface + io.RendererInterface)
|
||||
ImGuiConfigFlags_PlatformHasMouseHoveredViewport = 1 << 5, // Back-end knows how to set io.MouseHoveredViewport to the viewport directly under the mouse _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag and _REGARDLESS_ of whether another viewport is focused and may have mouse capture. This info is not easy to provide correctly with most high-level engines.
|
||||
ImGuiConfigFlags_PlatformHasWantMoveMouseSupport = 1 << 6, // Back-end honors io.WantMoveMouse request by updating the OS mouse cursor position (currently only used by ImGuiConfigFlags_NavMoveMouse feature, will be useful for widgets teleporting/wrapping the cursor)
|
||||
ImGuiConfigFlags_PlatformHasWindowAlpha = 1 << 7, // Back-end can have transparent windows
|
||||
ImGuiConfigFlags_EnableViewports = 1 << 4, // Viewport enable flags (require both ImGuiConfigFlags_PlatformHasViewports + ImGuiConfigFlags_RendererHasViewports set by the respective back-ends)
|
||||
ImGuiConfigFlags_PlatformHasViewports = 1 << 5, // Back-end Platform supports multiple viewports
|
||||
ImGuiConfigFlags_PlatformHasMouseHoveredViewport = 1 << 6, // Back-end Platform supports setting io.MouseHoveredViewport to the viewport directly under the mouse _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag and _REGARDLESS_ of whether another viewport is focused and may be capturing the mouse. This information is _NOT EASY_ to provide correctly with most high-level engines. Don't see this without studying how the examples/ back-end handle it.
|
||||
ImGuiConfigFlags_PlatformHasWantMoveMouseSupport = 1 << 7, // Back-end Platform supports io.WantMoveMouse request by updating the OS mouse cursor position (currently only used by ImGuiConfigFlags_NavMoveMouse feature, will be useful for widgets teleporting/wrapping the cursor)
|
||||
ImGuiConfigFlags_PlatformHasWindowAlpha = 1 << 8, // Back-end Platform supports transparent windows
|
||||
ImGuiConfigFlags_RendererHasViewports = 1 << 9, // Back-end Renderer supports multiple viewports
|
||||
|
||||
// Platform Info (strictly for the user/application)
|
||||
// Platform Info (free of use, for user/application convenience)
|
||||
ImGuiConfigFlags_IsSRGB = 1 << 10, // Back-end is SRGB-aware (Storage flag to allow your back-end to communicate to shared widgets. Not used by core ImGui)
|
||||
ImGuiConfigFlags_IsTouchScreen = 1 << 11, // Back-end is using a touch screen instead of a mouse (Storage flag to allow your back-end to communicate to shared widgets. Not used by core ImGui)
|
||||
ImGuiConfigFlags_IsOnScreenKeyboard = 1 << 12 // Back-end uses an on-screen keyboard when io.WantTextInput is set.
|
||||
|
Loading…
Reference in New Issue
Block a user