Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]窗口化缩放 #1071

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/Magpie.Core/CursorDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ bool CursorDrawer::Initialize(DeviceResources& deviceResources, ID3D11Texture2D*
_deviceResources = &deviceResources;
_backBuffer = backBuffer;

const RECT& scalingWndRect = ScalingWindow::Get().WndRect();
const RECT& destRect = ScalingWindow::Get().Renderer().DestRect();

_viewportRect = {
destRect.left - scalingWndRect.left,
destRect.top - scalingWndRect.top,
destRect.right - scalingWndRect.left,
destRect.bottom - scalingWndRect.top
};

ID3D11Device* d3dDevice = deviceResources.GetD3DDevice();

HRESULT hr = d3dDevice->CreateVertexShader(
Expand Down Expand Up @@ -115,6 +105,7 @@ void CursorDrawer::Draw() noexcept {
return;
}

const bool isSrcFocused = ScalingWindow::Get().IsSrcFocused();
const POINT cursorPos = cursorManager.CursorPos();

const ScalingOptions& options = ScalingWindow::Get().Options();
Expand All @@ -138,18 +129,27 @@ void CursorDrawer::Draw() noexcept {
.bottom = cursorRect.top + cursorSize.cy
};

if (cursorRect.left >= _viewportRect.right ||
cursorRect.top >= _viewportRect.bottom ||
cursorRect.right <= _viewportRect.left ||
cursorRect.bottom <= _viewportRect.top
const RECT& swapChainRect = ScalingWindow::Get().SwapChainRect();
const RECT& destRect = ScalingWindow::Get().Renderer().DestRect();

const RECT viewportRect{
isSrcFocused ? destRect.left - swapChainRect.left : 0,
isSrcFocused ? destRect.top - swapChainRect.top : 0,
(isSrcFocused ? destRect.right : swapChainRect.right) - swapChainRect.left,
(isSrcFocused ? destRect.bottom : swapChainRect.bottom) - swapChainRect.top
};

if (cursorRect.left >= viewportRect.right ||
cursorRect.top >= viewportRect.bottom ||
cursorRect.right <= viewportRect.left ||
cursorRect.bottom <= viewportRect.top
) {
// 光标在窗口外,不应发生这种情况
return;
}

const SIZE viewportSize = Win32Helper::GetSizeOfRect(_viewportRect);
float left = (cursorRect.left - _viewportRect.left) / (float)viewportSize.cx * 2 - 1.0f;
float top = 1.0f - (cursorRect.top - _viewportRect.top) / (float)viewportSize.cy * 2;
const SIZE viewportSize = Win32Helper::GetSizeOfRect(viewportRect);
float left = (cursorRect.left - viewportRect.left) / (float)viewportSize.cx * 2 - 1.0f;
float top = 1.0f - (cursorRect.top - viewportRect.top) / (float)viewportSize.cy * 2;
float right = left + cursorSize.cx / (float)viewportSize.cx * 2;
float bottom = top - cursorSize.cy / (float)viewportSize.cy * 2;

Expand Down Expand Up @@ -186,8 +186,8 @@ void CursorDrawer::Draw() noexcept {
// 配置渲染视口
{
D3D11_VIEWPORT vp{
(float)_viewportRect.left,
(float)_viewportRect.top,
(float)viewportRect.left,
(float)viewportRect.top,
(float)viewportSize.cx,
(float)viewportSize.cy,
0.0f,
Expand Down Expand Up @@ -255,11 +255,11 @@ void CursorDrawer::Draw() noexcept {
}

D3D11_BOX srcBox{
(UINT)std::max(cursorRect.left, _viewportRect.left),
(UINT)std::max(cursorRect.top, _viewportRect.top),
(UINT)std::max(cursorRect.left, viewportRect.left),
(UINT)std::max(cursorRect.top, viewportRect.top),
0,
(UINT)std::min(cursorRect.right, _viewportRect.right),
(UINT)std::min(cursorRect.bottom, _viewportRect.bottom),
(UINT)std::min(cursorRect.right, viewportRect.right),
(UINT)std::min(cursorRect.bottom, viewportRect.bottom),
1
};
d3dDC->CopySubresourceRegion(
Expand Down
2 changes: 0 additions & 2 deletions src/Magpie.Core/CursorDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class CursorDrawer {
DeviceResources* _deviceResources = nullptr;
ID3D11Texture2D* _backBuffer = nullptr;

RECT _viewportRect{};

phmap::flat_hash_map<HCURSOR, _CursorInfo> _cursorInfos;

winrt::com_ptr<ID3D11VertexShader> _simpleVS;
Expand Down
Loading