mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
stable window resizing
Updated frame calculation and position anchoring in WM_SIZING for stability.
This commit is contained in:
parent
316053bd9b
commit
dcc2bf250c
1 changed files with 27 additions and 18 deletions
|
@ -287,15 +287,11 @@ namespace entry
|
||||||
|
|
||||||
case WM_SIZING:
|
case WM_SIZING:
|
||||||
{
|
{
|
||||||
RECT clientRect;
|
|
||||||
GetClientRect(_hwnd, &clientRect);
|
|
||||||
uint32_t width = clientRect.right-clientRect.left;
|
|
||||||
uint32_t height = clientRect.bottom-clientRect.top;
|
|
||||||
|
|
||||||
RECT& rect = *(RECT*)_lparam;
|
RECT& rect = *(RECT*)_lparam;
|
||||||
uint32_t frameWidth = rect.right-rect.left - width;
|
uint32_t width = rect.right - rect.left - m_frameWidth;
|
||||||
uint32_t frameHeight = rect.bottom-rect.top - height;
|
uint32_t height = rect.bottom - rect.top - m_frameHeight;
|
||||||
|
|
||||||
|
//Recalculate size according to aspect ratio
|
||||||
switch (_wparam)
|
switch (_wparam)
|
||||||
{
|
{
|
||||||
case WMSZ_LEFT:
|
case WMSZ_LEFT:
|
||||||
|
@ -309,6 +305,9 @@ namespace entry
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
unsigned int oldWidth = width;
|
||||||
|
unsigned int oldHeight = height;
|
||||||
|
|
||||||
float aspectRatio = m_aspectRatio;
|
float aspectRatio = m_aspectRatio;
|
||||||
height = bx::uint32_max(DEFAULT_HEIGHT/4, height);
|
height = bx::uint32_max(DEFAULT_HEIGHT/4, height);
|
||||||
width = uint32_t(float(height)*aspectRatio);
|
width = uint32_t(float(height)*aspectRatio);
|
||||||
|
@ -316,18 +315,22 @@ namespace entry
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect.right = rect.left + width + frameWidth;
|
//Recalculate position using different anchor points
|
||||||
rect.bottom = rect.top + height + frameHeight;
|
switch(_wparam)
|
||||||
|
{
|
||||||
SetWindowPos(_hwnd
|
case WMSZ_LEFT:
|
||||||
, HWND_TOP
|
case WMSZ_TOPLEFT:
|
||||||
, rect.left
|
case WMSZ_BOTTOMLEFT:
|
||||||
, rect.top
|
rect.left = rect.right - width - m_frameWidth;
|
||||||
, (rect.right-rect.left)
|
rect.bottom = rect.top + height + m_frameHeight;
|
||||||
, (rect.bottom-rect.top)
|
break;
|
||||||
, SWP_SHOWWINDOW
|
|
||||||
);
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
rect.right = rect.left + width + m_frameWidth;
|
||||||
|
rect.bottom = rect.top + height + m_frameHeight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_eventQueue.postSizeEvent(m_width, m_height);
|
m_eventQueue.postSizeEvent(m_width, m_height);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -468,7 +471,11 @@ namespace entry
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowLong(m_hwnd, GWL_STYLE, style);
|
SetWindowLong(m_hwnd, GWL_STYLE, style);
|
||||||
|
uint32_t prewidth = newrect.right - newrect.left;
|
||||||
|
uint32_t preheight = newrect.bottom - newrect.top;
|
||||||
AdjustWindowRect(&newrect, style, FALSE);
|
AdjustWindowRect(&newrect, style, FALSE);
|
||||||
|
m_frameWidth = (newrect.right - newrect.left) - prewidth;
|
||||||
|
m_frameHeight = (newrect.bottom - newrect.top) - preheight;
|
||||||
UpdateWindow(m_hwnd);
|
UpdateWindow(m_hwnd);
|
||||||
|
|
||||||
if (rect.left == -32000
|
if (rect.left == -32000
|
||||||
|
@ -573,6 +580,8 @@ namespace entry
|
||||||
uint32_t m_height;
|
uint32_t m_height;
|
||||||
uint32_t m_oldWidth;
|
uint32_t m_oldWidth;
|
||||||
uint32_t m_oldHeight;
|
uint32_t m_oldHeight;
|
||||||
|
uint32_t m_frameWidth;
|
||||||
|
uint32_t m_frameHeight;
|
||||||
float m_aspectRatio;
|
float m_aspectRatio;
|
||||||
|
|
||||||
int32_t m_mx;
|
int32_t m_mx;
|
||||||
|
|
Loading…
Reference in a new issue