mirror of
https://github.com/glfw/glfw.git
synced 2026-09-18 22:55:46 +00:00
Add glfwGetWindowOpacity and glfwSetWindowOpacity
This adds support for setting the opacity of the whole window, including any decorations. Fixes #1089.
This commit is contained in:
@@ -1591,6 +1591,39 @@ void _glfwPlatformSetWindowFloating(_GLFWwindow* window, GLFWbool enabled)
|
||||
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
|
||||
}
|
||||
|
||||
float _glfwPlatformGetWindowOpacity(_GLFWwindow* window)
|
||||
{
|
||||
BYTE alpha;
|
||||
DWORD flags;
|
||||
|
||||
if ((GetWindowLongW(window->win32.handle, GWL_EXSTYLE) & WS_EX_LAYERED) &&
|
||||
GetLayeredWindowAttributes(window->win32.handle, NULL, &alpha, &flags))
|
||||
{
|
||||
if (flags & LWA_ALPHA)
|
||||
return alpha / 255.f;
|
||||
}
|
||||
|
||||
return 1.f;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity)
|
||||
{
|
||||
if (opacity < 1.f)
|
||||
{
|
||||
const BYTE alpha = (BYTE) (255 * opacity);
|
||||
DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
||||
style |= WS_EX_LAYERED;
|
||||
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style);
|
||||
SetLayeredWindowAttributes(window->win32.handle, 0, alpha, LWA_ALPHA);
|
||||
}
|
||||
else
|
||||
{
|
||||
DWORD style = GetWindowLongW(window->win32.handle, GWL_EXSTYLE);
|
||||
style &= ~WS_EX_LAYERED;
|
||||
SetWindowLongW(window->win32.handle, GWL_EXSTYLE, style);
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformPollEvents(void)
|
||||
{
|
||||
MSG msg;
|
||||
|
||||
Reference in New Issue
Block a user