From 699867941226c6f4bc4de59a9609e122bad4f4aa Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Sun, 2 Feb 2020 19:21:17 -0800 Subject: [PATCH] [ionGUI] Update platform implementation to catch up with GLFW improvements, including some GLFW 3.3 features - Resolve some issue with frame-buffer scale when windows minimized - Unsigned character codes, support for values outside of 0-0x10000 range - Show window without focusing from GLFW 3.3 - Monitor Working Area from GLFW 3.3 Resolves #51 --- Libraries/ionGUI/CGUIPlatform.cpp | 50 ++++++++++++-------------- Libraries/ionWindow/CWindow.cpp | 7 +--- Libraries/ionWindow/CWindowManager.cpp | 3 ++ Libraries/ionWindow/CWindowManager.h | 3 ++ 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/Libraries/ionGUI/CGUIPlatform.cpp b/Libraries/ionGUI/CGUIPlatform.cpp index e602202..f1bf516 100644 --- a/Libraries/ionGUI/CGUIPlatform.cpp +++ b/Libraries/ionGUI/CGUIPlatform.cpp @@ -46,17 +46,18 @@ namespace ion PrimaryWindow = window; ImGuiIO & io = ImGui::GetIO(); - io.KeyMap[ImGuiKey_Tab] = (int) EKey::Tab; - io.KeyMap[ImGuiKey_LeftArrow] = (int) EKey::Left; - io.KeyMap[ImGuiKey_RightArrow] = (int) EKey::Right; - io.KeyMap[ImGuiKey_UpArrow] = (int) EKey::Up; - io.KeyMap[ImGuiKey_DownArrow] = (int) EKey::Down; - io.KeyMap[ImGuiKey_Home] = (int) EKey::Home; - io.KeyMap[ImGuiKey_End] = (int) EKey::End; - io.KeyMap[ImGuiKey_Delete] = (int) EKey::Delete; - io.KeyMap[ImGuiKey_Backspace] = (int) EKey::Backspace; - io.KeyMap[ImGuiKey_Enter] = (int) EKey::Enter; - io.KeyMap[ImGuiKey_Escape] = (int) EKey::Escape; + io.KeyMap[ImGuiKey_Tab] = (int) EKey::Tab; + io.KeyMap[ImGuiKey_LeftArrow] = (int) EKey::Left; + io.KeyMap[ImGuiKey_RightArrow] = (int) EKey::Right; + io.KeyMap[ImGuiKey_UpArrow] = (int) EKey::Up; + io.KeyMap[ImGuiKey_DownArrow] = (int) EKey::Down; + io.KeyMap[ImGuiKey_Home] = (int) EKey::Home; + io.KeyMap[ImGuiKey_End] = (int) EKey::End; + io.KeyMap[ImGuiKey_Delete] = (int) EKey::Delete; + io.KeyMap[ImGuiKey_Backspace] = (int) EKey::Backspace; + io.KeyMap[ImGuiKey_Enter] = (int) EKey::Enter; + io.KeyMap[ImGuiKey_KeyPadEnter] = (int) EKey::KeyPadEnter; + io.KeyMap[ImGuiKey_Escape] = (int) EKey::Escape; io.KeyMap[ImGuiKey_A] = (int) EKey::A; io.KeyMap[ImGuiKey_C] = (int) EKey::C; io.KeyMap[ImGuiKey_V] = (int) EKey::V; @@ -120,7 +121,10 @@ namespace ion int const display_w = PrimaryWindow->GetFrameBufferSize().X; int const display_h = PrimaryWindow->GetFrameBufferSize().Y; io.DisplaySize = vec2f(PrimaryWindow->GetSize()); - io.DisplayFramebufferScale = vec2f(w > 0 ? ((float) display_w / w) : 0, h > 0 ? ((float) display_h / h) : 0); + if (w > 0 && h > 0) + { + io.DisplayFramebufferScale = vec2f((float)display_w / w, (float)display_h / h); + } // Setup time step double current_time = TimeManager->GetRunTime(); @@ -146,14 +150,6 @@ namespace ion io.KeysDown[(int) KeyboardEvent.Key] = KeyboardEvent.Pressed; - // Hack/workaround to make KP enter work like enter - // Will cause problems if regular Enter and KP Enter are pressed simultaneously - // Don't do that - if (KeyboardEvent.Key == EKey::KeyPadEnter) - { - io.KeysDown[(int) EKey::Enter] = KeyboardEvent.Pressed; - } - io.KeyCtrl = PrimaryWindow->IsKeyDown(EKey::LeftControl) || PrimaryWindow->IsKeyDown(EKey::RightControl); io.KeyShift = PrimaryWindow->IsKeyDown(EKey::LeftShift) || PrimaryWindow->IsKeyDown(EKey::RightShift); io.KeyAlt = PrimaryWindow->IsKeyDown(EKey::LeftAlt) || PrimaryWindow->IsKeyDown(EKey::RightAlt); @@ -188,11 +184,7 @@ namespace ion else if (InstanceOf(Event)) { SCharacterEvent CharacterEvent = As(Event); - - if (CharacterEvent.C > 0 && CharacterEvent.C < 0x10000) - { - io.AddInputCharacter(CharacterEvent.C); - } + io.AddInputCharacter(CharacterEvent.C); } else if (InstanceOf(Event)) { @@ -249,7 +241,7 @@ namespace ion // Update mouse position // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) - io.MousePos = ImVec2(-1, -1); + io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); for (auto window : windows) { if (window->IsFocused()) @@ -277,8 +269,10 @@ namespace ion for (SMonitorInfo const & info : windowManager->GetMonitors()) { ImGuiPlatformMonitor monitor; - monitor.MainPos = monitor.WorkPos = vec2f(info.Position); - monitor.MainSize = monitor.WorkSize = vec2f(info.Size); + monitor.MainPos = vec2f(info.Position); + monitor.MainSize = vec2f(info.Size); + monitor.WorkPos = vec2f(info.WorkPosition); + monitor.WorkSize = vec2f(info.WorkSize); platformIO.Monitors.push_back(monitor); } } diff --git a/Libraries/ionWindow/CWindow.cpp b/Libraries/ionWindow/CWindow.cpp index 9bab5d3..bd3c0b2 100644 --- a/Libraries/ionWindow/CWindow.cpp +++ b/Libraries/ionWindow/CWindow.cpp @@ -37,12 +37,7 @@ namespace ion void CWindow::Show() { - // GLFW hack: Hide icon from task bar - HWND hwnd = glfwGetWin32Window(WindowHandle); - - ::ShowWindow(hwnd, SW_SHOWNA); - - //glfwShowWindow(WindowHandle); + glfwShowWindow(WindowHandle); } void CWindow::SetTitle(std::string const & title) diff --git a/Libraries/ionWindow/CWindowManager.cpp b/Libraries/ionWindow/CWindowManager.cpp index 38fbfbf..de14f25 100644 --- a/Libraries/ionWindow/CWindowManager.cpp +++ b/Libraries/ionWindow/CWindowManager.cpp @@ -127,6 +127,7 @@ namespace ion glfwWindowHint(GLFW_VISIBLE, false); glfwWindowHint(GLFW_FOCUSED, false); glfwWindowHint(GLFW_DECORATED, ! noDecoration); + glfwWindowHint(GLFW_FOCUS_ON_SHOW, false); GLFWwindow * WindowHandle = glfwCreateWindow(size.X, size.Y, "No Title Yet", nullptr, nullptr); glfwSetWindowPos(WindowHandle, position.X, position.Y); @@ -195,6 +196,8 @@ namespace ion GLFWvidmode const * videoMode = glfwGetVideoMode(monitors[i]); info.Size = vec2i(videoMode->width, videoMode->height); + glfwGetMonitorWorkarea(monitors[i], &info.WorkPosition.X, &info.WorkPosition.Y, &info.WorkSize.X, &info.WorkSize.Y); + returnValue.push_back(info); } diff --git a/Libraries/ionWindow/CWindowManager.h b/Libraries/ionWindow/CWindowManager.h index 4c0f667..328f610 100644 --- a/Libraries/ionWindow/CWindowManager.h +++ b/Libraries/ionWindow/CWindowManager.h @@ -31,6 +31,9 @@ namespace ion { vec2i Position; vec2i Size; + + vec2i WorkPosition; + vec2i WorkSize; }; class CWindowManager : public Singleton, public IEventListener