diff --git a/platforms/windows/AppPlatform_windows.cpp b/platforms/windows/AppPlatform_windows.cpp index baa52e0..95777a8 100644 --- a/platforms/windows/AppPlatform_windows.cpp +++ b/platforms/windows/AppPlatform_windows.cpp @@ -244,8 +244,13 @@ void AppPlatform_windows::setMouseGrabbed(bool b) m_bGrabbedMouse = b; - if (!b) + if (m_bActuallyGrabbedMouse == (b && m_bIsFocused)) + return; + + if (!b || !m_bIsFocused) { + m_bActuallyGrabbedMouse = false; + //show the cursor ShowCursor(TRUE); @@ -256,6 +261,8 @@ void AppPlatform_windows::setMouseGrabbed(bool b) } else { + m_bActuallyGrabbedMouse = true; + //hide the cursor ShowCursor(FALSE); @@ -290,6 +297,12 @@ void AppPlatform_windows::clearDiff() m_MouseDiffX = m_MouseDiffY = 0; } +void AppPlatform_windows::updateFocused(bool focused) +{ + m_bIsFocused = focused; + setMouseGrabbed(m_bGrabbedMouse); +} + bool AppPlatform_windows::shiftPressed() { return m_bShiftPressed; diff --git a/platforms/windows/AppPlatform_windows.hpp b/platforms/windows/AppPlatform_windows.hpp index 10fafff..de55845 100644 --- a/platforms/windows/AppPlatform_windows.hpp +++ b/platforms/windows/AppPlatform_windows.hpp @@ -42,6 +42,7 @@ public: void setMouseGrabbed(bool b) override; void getMouseDiff(int& x, int& y) override; void clearDiff() override; + void updateFocused(bool focused) override; // Also add these to allow proper text input within the game. bool shiftPressed() override; @@ -56,7 +57,9 @@ private: std::vector m_UserInput; int m_UserInputStatus = -1; + bool m_bIsFocused = false; bool m_bGrabbedMouse = false; + bool m_bActuallyGrabbedMouse = false; bool m_bWasUnfocused = false; bool m_bShiftPressed = false; diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index 03fb5b1..2101f38 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -77,6 +77,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) default: return DefWindowProc(hWnd, iMsg, wParam, lParam); + case WM_SETFOCUS: + case WM_KILLFOCUS: + { + g_AppPlatform.updateFocused(iMsg == WM_SETFOCUS); + break; + } + case WM_LBUTTONUP: { if (g_LButtonDown) diff --git a/source/App/AppPlatform.cpp b/source/App/AppPlatform.cpp index d9303aa..ec10dc6 100644 --- a/source/App/AppPlatform.cpp +++ b/source/App/AppPlatform.cpp @@ -114,6 +114,10 @@ void AppPlatform::clearDiff() } +void AppPlatform::updateFocused(bool focused) +{ +} + bool AppPlatform::shiftPressed() { return false; diff --git a/source/App/AppPlatform.hpp b/source/App/AppPlatform.hpp index 05b51e4..30b8e26 100644 --- a/source/App/AppPlatform.hpp +++ b/source/App/AppPlatform.hpp @@ -47,6 +47,7 @@ public: virtual void setMouseGrabbed(bool b); virtual void getMouseDiff(int& x, int& y); virtual void clearDiff(); + virtual void updateFocused(bool focused); // Also add this to allow proper text input within the game. virtual bool shiftPressed(); #endif diff --git a/source/GUI/Screen/IngameBlockSelectionScreen.cpp b/source/GUI/Screen/IngameBlockSelectionScreen.cpp index 9ab97be..552ea2d 100644 --- a/source/GUI/Screen/IngameBlockSelectionScreen.cpp +++ b/source/GUI/Screen/IngameBlockSelectionScreen.cpp @@ -188,7 +188,7 @@ label_5: pInv->setSelectionSlotItemId(0, item); pInv->selectSlot(0); - // @TODO: SoundEngine + m_pMinecraft->m_pSoundEngine->play("random.click"); m_pMinecraft->setScreen(nullptr); }