Fix #111295: Add Missing Win32 Platform-Specific Window functions #111359

Merged
Harley Acheson merged 6 commits from Harley/blender:Win32WinFunctions into main 2023-08-25 22:10:02 +02:00
6 changed files with 42 additions and 2 deletions

View File

@ -256,7 +256,10 @@ extern GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle);
extern bool GHOST_GetFullScreen(GHOST_SystemHandle systemhandle);
/**
* Get the Window under the cursor.
* Get the Window under the cursor. Although coordinates of the mouse are supplied, platform-
* specific implementations are free to ignore these and query the mouse location themselves, due
* to them possibly being incorrect under certain conditions, for example when using multiple
* monitors that vary in scale and/or DPI.
* \param x: The x-coordinate of the cursor.
* \param y: The y-coordinate of the cursor.
* \return The window under the cursor or nullptr in none.

View File

@ -332,7 +332,10 @@ class GHOST_ISystem {
virtual void setAutoFocus(const bool auto_focus) = 0;
/**
* Get the Window under the cursor.
* Get the Window under the cursor. Although coordinates of the mouse are supplied, platform-
* specific implementations are free to ignore these and query the mouse location themselves, due
* to them possibly being incorrect under certain conditions, for example when using multiple
* monitors that vary in scale and/or DPI.
* \param x: The x-coordinate of the cursor.
* \param y: The y-coordinate of the cursor.
* \return The window under the cursor or nullptr if none.

View File

@ -473,6 +473,23 @@ GHOST_TSuccess GHOST_SystemWin32::getPixelAtCursor(float r_color[3]) const
return GHOST_kSuccess;
}
GHOST_IWindow *GHOST_SystemWin32::getWindowUnderCursor(int32_t /*x*/, int32_t /*y*/)
{
/* Get cursor position from the OS. Do not use the supplied positions as those
* could be incorrect, especially if using multiple windows of differing OS scale. */
POINT point;
if (!GetCursorPos(&point)) {
return nullptr;
}
HWND win = WindowFromPoint(point);
if (win == NULL) {
return nullptr;
}
return m_windowManager->getWindowAssociatedWithOSWindow((void *)win);
}
GHOST_TSuccess GHOST_SystemWin32::getModifierKeys(GHOST_ModifierKeys &keys) const
{
/* `GetAsyncKeyState` returns the current interrupt-level state of the hardware, which is needed

View File

@ -151,6 +151,12 @@ class GHOST_SystemWin32 : public GHOST_System {
*/
static GHOST_TSuccess disposeContextD3D(GHOST_ContextD3D *context);
/**
* Get the Window under the mouse cursor. Location obtained from the OS.
* \return The window under the cursor or nullptr if none.
*/
GHOST_IWindow *getWindowUnderCursor(int32_t /*x*/, int32_t /*y*/);
/***************************************************************************************
** Event management functionality
***************************************************************************************/

View File

@ -361,6 +361,11 @@ HWND GHOST_WindowWin32::getHWND() const
return m_hWnd;
}
void *GHOST_WindowWin32::getOSWindow() const
{
return (void *)m_hWnd;
}
void GHOST_WindowWin32::setTitle(const char *title)
{
wchar_t *title_16 = alloc_utf16_from_8((char *)title, 0);

View File

@ -107,6 +107,12 @@ class GHOST_WindowWin32 : public GHOST_Window {
*/
HWND getHWND() const;
/**
* Returns the handle of the window.
* \return The handle of the window.
*/
void *getOSWindow() const;
/**
* Sets the title displayed in the title bar.
* \param title: The title to display in the title bar.