Skip to content

Commit

Permalink
Stop using D2D size/point for CursorRenderer
Browse files Browse the repository at this point in the history
refs #507 - Clean up use of D2D1_{RECT,SIZE}_* except at D2D boundaries
  • Loading branch information
fredemmott committed Mar 9, 2024
1 parent ff106c5 commit 6d95df8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/app/app-common/CursorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ CursorRenderer::~CursorRenderer() = default;

void CursorRenderer::Render(
ID2D1RenderTarget* ctx,
const D2D1_POINT_2F& point,
const D2D1_SIZE_F& scaleTo) {
const auto cursorRadius = scaleTo.height / CursorRadiusDivisor;
const auto cursorStroke = scaleTo.height / CursorStrokeDivisor;
const PixelPoint& point,
const PixelSize& scaleTo) {
const auto cursorRadius = scaleTo.Height<float>() / CursorRadiusDivisor;
const auto cursorStroke = scaleTo.Height<float>() / CursorStrokeDivisor;

auto elipse = D2D1::Ellipse(point, cursorRadius, cursorRadius);
ctx->DrawEllipse(elipse, mOuterBrush.get(), cursorStroke * 2);
Expand Down
6 changes: 3 additions & 3 deletions src/app/app-common/KneeboardView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,10 @@ void KneeboardView::RenderWithChrome(
auto d2d = rt->d2d();
mCursorRenderer->Render(
d2d,
{
Geometry2D::Point<float>(
(mCursorCanvasPoint->x * size.mWidth) + rect.Left(),
(mCursorCanvasPoint->y * size.mHeight) + rect.Top(),
},
(mCursorCanvasPoint->y * size.mHeight) + rect.Top())
.Rounded<uint32_t>(),
size);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/app-common/include/OpenKneeboard/CursorRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
#pragma once

#include <OpenKneeboard/Pixels.h>

#include <OpenKneeboard/audited_ptr.h>

#include <shims/winrt/base.h>
Expand All @@ -36,8 +38,8 @@ class CursorRenderer final {

void Render(
ID2D1RenderTarget* ctx,
const D2D1_POINT_2F& point,
const D2D1_SIZE_F& scaleTo);
const PixelPoint& point,
const PixelSize& scaleTo);

private:
winrt::com_ptr<ID2D1SolidColorBrush> mInnerBrush;
Expand Down
13 changes: 7 additions & 6 deletions src/app/app-winui3/TabPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,15 @@ void TabPage::PaintNow() noexcept {
TraceLoggingValue(tab->GetPageCount(), "PageCount"));
return;
}
auto point = *maybePoint;
point.x *= metrics.mRenderSize.Width();
point.y *= metrics.mRenderSize.Height();
point.x += metrics.mRenderRect.Left();
point.y += metrics.mRenderRect.Top();
Geometry2D::Point<float> point {maybePoint->x, maybePoint->y};
point.mX *= metrics.mRenderSize.Width();
point.mY *= metrics.mRenderSize.Height();
point.mX += metrics.mRenderRect.Left();
point.mY += metrics.mRenderRect.Top();
{
auto d2d = mRenderTarget->d2d();
mCursorRenderer->Render(d2d, point, metrics.mRenderSize);
mCursorRenderer->Render(
d2d, point.Rounded<uint32_t>(), metrics.mRenderSize);
}
TraceLoggingWriteStop(
activity,
Expand Down

0 comments on commit 6d95df8

Please sign in to comment.