Start working on de-duping some of this work

This commit is contained in:
Mike Griese 2019-07-10 07:00:12 -05:00
parent 5fd41919e9
commit ac44b6b392
2 changed files with 106 additions and 66 deletions

View file

@ -85,31 +85,37 @@ void NonClientIslandWindow::OnSize(const UINT width, const UINT height)
return;
}
const auto scale = GetCurrentDpiScale();
const auto dpi = ::GetDpiForWindow(_window.get());
// const auto scale = GetCurrentDpiScale();
// const auto dpi = ::GetDpiForWindow(_window.get());
const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi);
const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi);
// const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi);
// const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi);
// If we're maximized, we don't want to use the frame as our margins,
// instead we want to use the margins from the maximization. If we included
// the left&right sides of the frame in this calculation while maximized,
// you' have a few pixels of the window border on the sides while maximized,
// which most apps do not have.
const auto bordersWidth = _isMaximized ?
(_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) :
(dragX * 2);
const auto bordersHeight = _isMaximized ?
(_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) :
(dragY * 2);
// // If we're maximized, we don't want to use the frame as our margins,
// // instead we want to use the margins from the maximization. If we included
// // the left&right sides of the frame in this calculation while maximized,
// // you' have a few pixels of the window border on the sides while maximized,
// // which most apps do not have.
// const auto bordersWidth = _isMaximized ?
// (_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) :
// (dragX * 2);
// const auto bordersHeight = _isMaximized ?
// (_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) :
// (dragY * 2);
const auto windowsWidth = width - bordersWidth;
const auto windowsHeight = height - bordersHeight;
const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX;
const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY;
// const auto windowsWidth = width - bordersWidth;
// const auto windowsHeight = height - bordersHeight;
// const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX;
// const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY;
_UpdateInternalMetrics();
const auto windowsWidth = RECT_WIDTH(&_clientArea);
const auto windowsHeight = RECT_HEIGHT(&_clientArea);
if (_rootGrid)
{
const auto scale = GetCurrentDpiScale();
winrt::Windows::Foundation::Size size{ (windowsWidth / scale) + 0.5f, (windowsHeight / scale) + 0.5f };
_rootGrid.Height(size.Height);
_rootGrid.Width(size.Width);
@ -118,7 +124,7 @@ void NonClientIslandWindow::OnSize(const UINT width, const UINT height)
_rootGrid.Arrange(finalRect);
}
winrt::check_bool(SetWindowPos(_interopWindowHandle, HWND_TOP, xPos, yPos, windowsWidth, windowsHeight, SWP_SHOWWINDOW));
winrt::check_bool(SetWindowPos(_interopWindowHandle, HWND_TOP, _clientArea.left, _clientArea.top, windowsWidth, windowsHeight, SWP_SHOWWINDOW));
}
// Method Description:
@ -136,37 +142,10 @@ void NonClientIslandWindow::_UpdateDragRegion()
{
if (_dragBar)
{
// TODO:GH#1897 This is largely duplicated from OnSize, and we should do
// better than that.
const auto windowRect = GetWindowRect();
const auto width = windowRect.right - windowRect.left;
const auto height = windowRect.bottom - windowRect.top;
const auto scale = GetCurrentDpiScale();
const auto dpi = ::GetDpiForWindow(_window.get());
const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi);
const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi);
// If we're maximized, we don't want to use the frame as our margins,
// instead we want to use the margins from the maximization. If we included
// the left&right sides of the frame in this calculation while maximized,
// you' have a few pixels of the window border on the sides while maximized,
// which most apps do not have.
const auto bordersWidth = _isMaximized ?
(_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) :
(dragX * 2);
const auto bordersHeight = _isMaximized ?
(_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) :
(dragY * 2);
const auto windowsWidth = width - bordersWidth;
const auto windowsHeight = height - bordersHeight;
const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX;
const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY;
const auto dragBarRect = GetDragAreaRect();
const auto nonClientHeight = dragBarRect.bottom - dragBarRect.top;
const auto windowsWidth = RECT_WIDTH(&_clientArea);
const auto windowsHeight = RECT_HEIGHT(&_clientArea);
auto nonClientRegion = wil::unique_hrgn(CreateRectRgn(0, 0, 0, 0));
auto nonClientLeftRegion = wil::unique_hrgn(CreateRectRgn(0, 0, dragBarRect.left, nonClientHeight));
@ -180,6 +159,49 @@ void NonClientIslandWindow::_UpdateDragRegion()
}
}
void NonClientIslandWindow::_UpdateInternalMetrics()
{
// TODO:GH#1897 This is largely duplicated from OnSize, and we should do
// better than that.
_windowRect = GetWindowRect();
const auto width = _windowRect.right - _windowRect.left;
const auto height = _windowRect.bottom - _windowRect.top;
// const auto scale = GetCurrentDpiScale();
const auto dpi = _currentDpi; // ::GetDpiForWindow(_window.get());
const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi);
const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi);
_dragSize = { dragX, dragY };
// If we're maximized, we don't want to use the frame as our margins,
// instead we want to use the margins from the maximization. If we included
// the left&right sides of the frame in this calculation while maximized,
// you' have a few pixels of the window border on the sides while maximized,
// which most apps do not have.
const auto bordersWidth = _isMaximized ?
(_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) :
(dragX * 2);
const auto bordersHeight = _isMaximized ?
(_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) :
(dragY * 2);
_borderSize = { bordersWidth, bordersHeight };
const auto windowsWidth = width - bordersWidth;
const auto windowsHeight = height - bordersHeight;
const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX;
const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY;
// TODO
// Wait this isn't the client area. This is just the area inside the
// borders. (which yea is all our client area but still)
// I think I want to keep this structure, but maybe rename it
_clientArea.left = xPos;
_clientArea.top = yPos;
_clientArea.right = xPos + windowsWidth;
_clientArea.bottom = yPos + windowsHeight;
}
// Method Description:
// Hit test the frame for resizing and moving.
// Method Description:
@ -450,11 +472,12 @@ RECT NonClientIslandWindow::GetMaxWindowRectInPixels(const RECT* const prcSugges
{
return 0;
}
PAINTSTRUCT ps{ 0 };
const auto hdc = wil::BeginPaint(_window.get(), &ps);
if (hdc.get())
{
// Todo this shit can get pulled too
const auto scale = GetCurrentDpiScale();
const auto dpi = ::GetDpiForWindow(_window.get());
// Get the dimensions of the drag borders for the sides of the window.
@ -472,10 +495,19 @@ RECT NonClientIslandWindow::GetMaxWindowRectInPixels(const RECT* const prcSugges
// Fill in the area between the non-client content and the caption buttons.
RECT dragBarRect = GetDragAreaRect();
dragBarRect.left += xPos;
dragBarRect.right += xPos;
dragBarRect.bottom += yPos;
dragBarRect.top += yPos;
// dragBarRect.left += xPos;
// dragBarRect.right += xPos;
// dragBarRect.bottom += yPos;
// dragBarRect.top += yPos;
// This would paint the _entire_ window area, but I think we want to
// be more precise about it (in case we want different titlebar and
// border colors)
dragBarRect.left = 0;
dragBarRect.top = 0;
dragBarRect.right = RECT_WIDTH(&_windowRect);
dragBarRect.bottom = RECT_HEIGHT(&_windowRect);
::FillRect(hdc.get(), &dragBarRect, _backgroundBrush.get());
RECT windowRect = {};
@ -483,21 +515,21 @@ RECT NonClientIslandWindow::GetMaxWindowRectInPixels(const RECT* const prcSugges
const auto cx = windowRect.right - windowRect.left;
const auto cy = windowRect.bottom - windowRect.top;
// Draw the top window border
RECT clientRect = { 0, 0, cx, yPos };
::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// // Draw the top window border
// RECT clientRect = { 0, 0, cx, yPos };
// ::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// Draw the left window border
clientRect = { 0, 0, xPos, cy };
::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// // Draw the left window border
// clientRect = { 0, 0, xPos, cy };
// ::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// Draw the bottom window border
clientRect = { 0, cy - yPos, cx, cy };
::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// // Draw the bottom window border
// clientRect = { 0, cy - yPos, cx, cy };
// ::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// Draw the right window border
clientRect = { cx - xPos, 0, cx, cy };
::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
// // Draw the right window border
// clientRect = { cx - xPos, 0, cx, cy };
// ::FillRect(hdc.get(), &clientRect, _backgroundBrush.get());
}
return 0;

View file

@ -46,6 +46,13 @@ private:
bool _isMaximized;
winrt::Windows::UI::Xaml::Controls::Border _dragBar{ nullptr };
// TODO: These should be Viewport's
RECT _windowRect{ 0 };
SIZE _dragSize{ 0 };
SIZE _borderSize{ 0 };
RECT _clientArea{ 0 };
// RECT _titlebarArea{ 0 };
RECT GetDragAreaRect() const noexcept;
[[nodiscard]] LRESULT HitTestNCA(POINT ptMouse) const noexcept;
@ -55,6 +62,7 @@ private:
void _HandleActivateWindow();
bool _HandleWindowPosChanging(WINDOWPOS* const windowPos);
void _UpdateDragRegion();
void _UpdateInternalMetrics();
void OnDragBarSizeChanged(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::SizeChangedEventArgs eventArgs);