Skip to content

Commit

Permalink
[ionGUI] Update platform implementation to catch up with GLFW improve…
Browse files Browse the repository at this point in the history
…ments, 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
  • Loading branch information
iondune committed Feb 3, 2020
1 parent 32e17b7 commit 6998679
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
50 changes: 22 additions & 28 deletions Libraries/ionGUI/CGUIPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -188,11 +184,7 @@ namespace ion
else if (InstanceOf<SCharacterEvent>(Event))
{
SCharacterEvent CharacterEvent = As<SCharacterEvent>(Event);

if (CharacterEvent.C > 0 && CharacterEvent.C < 0x10000)
{
io.AddInputCharacter(CharacterEvent.C);
}
io.AddInputCharacter(CharacterEvent.C);
}
else if (InstanceOf<SWindowClosedEvent>(Event))
{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}
}
Expand Down
7 changes: 1 addition & 6 deletions Libraries/ionWindow/CWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Libraries/ionWindow/CWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions Libraries/ionWindow/CWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace ion
{
vec2i Position;
vec2i Size;

vec2i WorkPosition;
vec2i WorkSize;
};

class CWindowManager : public Singleton<CWindowManager>, public IEventListener
Expand Down

0 comments on commit 6998679

Please sign in to comment.