mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Letter box for frameless window mode.
This commit is contained in:
parent
956d12e5a8
commit
5383961058
3 changed files with 77 additions and 12 deletions
86
src/bgfx_p.h
86
src/bgfx_p.h
|
@ -2382,6 +2382,17 @@ namespace bgfx
|
||||||
HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
|
HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
|
||||||
|
|
||||||
WNDCLASSEX wnd;
|
WNDCLASSEX wnd;
|
||||||
|
memset(&wnd, 0, sizeof(wnd) );
|
||||||
|
wnd.cbSize = sizeof(wnd);
|
||||||
|
wnd.lpfnWndProc = DefWindowProc;
|
||||||
|
wnd.hInstance = instance;
|
||||||
|
wnd.hIcon = LoadIcon(instance, IDI_APPLICATION);
|
||||||
|
wnd.hCursor = LoadCursor(instance, IDC_ARROW);
|
||||||
|
wnd.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||||
|
wnd.lpszClassName = "bgfx_letterbox";
|
||||||
|
wnd.hIconSm = LoadIcon(instance, IDI_APPLICATION);
|
||||||
|
RegisterClassExA(&wnd);
|
||||||
|
|
||||||
memset(&wnd, 0, sizeof(wnd) );
|
memset(&wnd, 0, sizeof(wnd) );
|
||||||
wnd.cbSize = sizeof(wnd);
|
wnd.cbSize = sizeof(wnd);
|
||||||
wnd.style = CS_HREDRAW | CS_VREDRAW;
|
wnd.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
@ -2390,9 +2401,22 @@ namespace bgfx
|
||||||
wnd.hIcon = LoadIcon(instance, IDI_APPLICATION);
|
wnd.hIcon = LoadIcon(instance, IDI_APPLICATION);
|
||||||
wnd.hCursor = LoadCursor(instance, IDC_ARROW);
|
wnd.hCursor = LoadCursor(instance, IDC_ARROW);
|
||||||
wnd.lpszClassName = "bgfx";
|
wnd.lpszClassName = "bgfx";
|
||||||
wnd.hIconSm = LoadIcon(instance, IDI_APPLICATION);
|
wnd.hIconSm = LoadIcon(instance, IDI_APPLICATION);
|
||||||
RegisterClassExA(&wnd);
|
RegisterClassExA(&wnd);
|
||||||
|
|
||||||
|
HWND hwnd = CreateWindowA("bgfx_letterbox"
|
||||||
|
, "BGFX"
|
||||||
|
, WS_POPUP|WS_SYSMENU
|
||||||
|
, -32000
|
||||||
|
, -32000
|
||||||
|
, 0
|
||||||
|
, 0
|
||||||
|
, NULL
|
||||||
|
, NULL
|
||||||
|
, instance
|
||||||
|
, 0
|
||||||
|
);
|
||||||
|
|
||||||
g_bgfxHwnd = CreateWindowA("bgfx"
|
g_bgfxHwnd = CreateWindowA("bgfx"
|
||||||
, "BGFX"
|
, "BGFX"
|
||||||
, WS_OVERLAPPEDWINDOW|WS_VISIBLE
|
, WS_OVERLAPPEDWINDOW|WS_VISIBLE
|
||||||
|
@ -2400,9 +2424,9 @@ namespace bgfx
|
||||||
, 0
|
, 0
|
||||||
, BGFX_DEFAULT_WIDTH
|
, BGFX_DEFAULT_WIDTH
|
||||||
, BGFX_DEFAULT_HEIGHT
|
, BGFX_DEFAULT_HEIGHT
|
||||||
, 0
|
, hwnd
|
||||||
, 0
|
, NULL
|
||||||
, 0
|
, instance
|
||||||
, 0
|
, 0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2486,6 +2510,8 @@ namespace bgfx
|
||||||
|
|
||||||
void adjust(uint32_t _width, uint32_t _height, bool _windowFrame)
|
void adjust(uint32_t _width, uint32_t _height, bool _windowFrame)
|
||||||
{
|
{
|
||||||
|
m_aspectRatio = float(_width)/float(_height);
|
||||||
|
|
||||||
ShowWindow(g_bgfxHwnd, SW_SHOWNORMAL);
|
ShowWindow(g_bgfxHwnd, SW_SHOWNORMAL);
|
||||||
RECT rect;
|
RECT rect;
|
||||||
RECT newrect = {0, 0, (LONG)_width, (LONG)_height};
|
RECT newrect = {0, 0, (LONG)_width, (LONG)_height};
|
||||||
|
@ -2528,19 +2554,59 @@ namespace bgfx
|
||||||
rect.top = 0;
|
rect.top = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t left = rect.left;
|
||||||
|
int32_t top = rect.top;
|
||||||
|
int32_t width = (newrect.right-newrect.left);
|
||||||
|
int32_t height = (newrect.bottom-newrect.top);
|
||||||
|
|
||||||
|
if (!_windowFrame)
|
||||||
|
{
|
||||||
|
float aspectRatio = 1.0f/m_aspectRatio;
|
||||||
|
width = bx::uint32_max(BGFX_DEFAULT_WIDTH/4, width);
|
||||||
|
height = uint32_t(float(width)*aspectRatio);
|
||||||
|
|
||||||
|
left = newrect.left+(newrect.right-newrect.left-width)/2;
|
||||||
|
top = newrect.top+(newrect.bottom-newrect.top-height)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND parent = GetWindow(g_bgfxHwnd, GW_OWNER);
|
||||||
|
if (NULL != parent)
|
||||||
|
{
|
||||||
|
if (_windowFrame)
|
||||||
|
{
|
||||||
|
SetWindowPos(parent
|
||||||
|
, HWND_TOP
|
||||||
|
, -32000
|
||||||
|
, -32000
|
||||||
|
, 0
|
||||||
|
, 0
|
||||||
|
, SWP_SHOWWINDOW
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetWindowPos(parent
|
||||||
|
, HWND_TOP
|
||||||
|
, newrect.left
|
||||||
|
, newrect.top
|
||||||
|
, newrect.right-newrect.left
|
||||||
|
, newrect.bottom-newrect.top
|
||||||
|
, SWP_SHOWWINDOW
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SetWindowPos(g_bgfxHwnd
|
SetWindowPos(g_bgfxHwnd
|
||||||
, HWND_TOP
|
, HWND_TOP
|
||||||
, rect.left
|
, left
|
||||||
, rect.top
|
, top
|
||||||
, (newrect.right-newrect.left)
|
, width
|
||||||
, (newrect.bottom-newrect.top)
|
, height
|
||||||
, SWP_SHOWWINDOW
|
, SWP_SHOWWINDOW
|
||||||
);
|
);
|
||||||
|
|
||||||
ShowWindow(g_bgfxHwnd, SW_RESTORE);
|
ShowWindow(g_bgfxHwnd, SW_RESTORE);
|
||||||
|
|
||||||
m_aspectRatio = float(_width)/float(_height);
|
|
||||||
|
|
||||||
m_frame = _windowFrame;
|
m_frame = _windowFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1206,6 +1206,7 @@ namespace bgfx
|
||||||
|
|
||||||
width >>= 1;
|
width >>= 1;
|
||||||
height >>= 1;
|
height >>= 1;
|
||||||
|
depth >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,7 @@ namespace bgfx
|
||||||
m_textVideoMem.clear();
|
m_textVideoMem.clear();
|
||||||
|
|
||||||
m_resolution = _resolution;
|
m_resolution = _resolution;
|
||||||
#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX
|
|
||||||
setRenderContextSize(_resolution.m_width, _resolution.m_height);
|
setRenderContextSize(_resolution.m_width, _resolution.m_height);
|
||||||
#endif // BX_PLATFORM_
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue