summaryrefslogtreecommitdiff
path: root/src/SFML/Window/Win32/WindowImplWin32.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Window/Win32/WindowImplWin32.cpp')
-rw-r--r--src/SFML/Window/Win32/WindowImplWin32.cpp56
1 files changed, 50 insertions, 6 deletions
diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp
index 8bf86ab..cc999f9 100644
--- a/src/SFML/Window/Win32/WindowImplWin32.cpp
+++ b/src/SFML/Window/Win32/WindowImplWin32.cpp
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org)
+// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
@@ -132,7 +132,9 @@ m_keyRepeatEnabled(true),
m_lastSize (0, 0),
m_resizing (false),
m_surrogate (0),
-m_mouseInside (false)
+m_mouseInside (false),
+m_fullscreen (false),
+m_cursorGrabbed (false)
{
// Set that this process is DPI aware and can handle DPI scaling
setProcessDpiAware();
@@ -156,7 +158,9 @@ m_keyRepeatEnabled(true),
m_lastSize (mode.width, mode.height),
m_resizing (false),
m_surrogate (0),
-m_mouseInside (false)
+m_mouseInside (false),
+m_fullscreen (style & Style::Fullscreen),
+m_cursorGrabbed (m_fullscreen)
{
// Set that this process is DPI aware and can handle DPI scaling
setProcessDpiAware();
@@ -187,8 +191,7 @@ m_mouseInside (false)
}
// In windowed mode, adjust width and height so that window will have the requested client area
- bool fullscreen = (style & Style::Fullscreen) != 0;
- if (!fullscreen)
+ if (!m_fullscreen)
{
RECT rectangle = {0, 0, width, height};
AdjustWindowRect(&rectangle, win32Style, false);
@@ -204,7 +207,7 @@ m_mouseInside (false)
setSize(Vector2u(mode.width, mode.height));
// Switch to fullscreen if requested
- if (fullscreen)
+ if (m_fullscreen)
switchToFullscreen(mode);
// Increment window count
@@ -277,6 +280,9 @@ Vector2i WindowImplWin32::getPosition() const
void WindowImplWin32::setPosition(const Vector2i& position)
{
SetWindowPos(m_handle, NULL, position.x, position.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+
+ if(m_cursorGrabbed)
+ grabCursor(true);
}
@@ -364,6 +370,14 @@ void WindowImplWin32::setMouseCursorVisible(bool visible)
////////////////////////////////////////////////////////////
+void WindowImplWin32::setMouseCursorGrabbed(bool grabbed)
+{
+ m_cursorGrabbed = grabbed;
+ grabCursor(m_cursorGrabbed);
+}
+
+
+////////////////////////////////////////////////////////////
void WindowImplWin32::setKeyRepeatEnabled(bool enabled)
{
m_keyRepeatEnabled = enabled;
@@ -486,6 +500,23 @@ void WindowImplWin32::setTracking(bool track)
////////////////////////////////////////////////////////////
+void WindowImplWin32::grabCursor(bool grabbed)
+{
+ if (grabbed)
+ {
+ RECT rect;
+ GetClientRect(m_handle, &rect);
+ MapWindowPoints(m_handle, NULL, reinterpret_cast<LPPOINT>(&rect), 2);
+ ClipCursor(&rect);
+ }
+ else
+ {
+ ClipCursor(NULL);
+ }
+}
+
+
+////////////////////////////////////////////////////////////
void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
// Don't process any message until window is created
@@ -536,6 +567,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
event.size.width = m_lastSize.x;
event.size.height = m_lastSize.y;
pushEvent(event);
+
+ // Restore/update cursor grabbing
+ grabCursor(m_cursorGrabbed);
}
break;
}
@@ -544,6 +578,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
case WM_ENTERSIZEMOVE:
{
m_resizing = true;
+ grabCursor(false);
break;
}
@@ -565,6 +600,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
event.size.height = m_lastSize.y;
pushEvent(event);
}
+
+ // Restore/update cursor grabbing
+ grabCursor(m_cursorGrabbed);
break;
}
@@ -582,6 +620,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
// Gain focus event
case WM_SETFOCUS:
{
+ // Restore cursor grabbing
+ grabCursor(m_cursorGrabbed);
+
Event event;
event.type = Event::GainedFocus;
pushEvent(event);
@@ -591,6 +632,9 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
// Lost focus event
case WM_KILLFOCUS:
{
+ // Ungrab the cursor
+ grabCursor(false);
+
Event event;
event.type = Event::LostFocus;
pushEvent(event);