Skip to content

Commit

Permalink
String meter/Inline shadow: Treat the shadow drawing surface as the s…
Browse files Browse the repository at this point in the history
…ize of the meter itself instead of using the underlying bitmap of the skin's bounds (in case SkinWidth/Height is truncating the drawing of the meter)
  • Loading branch information
brianferguson committed Sep 1, 2022
1 parent dffa597 commit 102d1fd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
4 changes: 3 additions & 1 deletion Common/Gfx/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ void Canvas::DrawTextW(const std::wstring& srcStr, const TextFormat& format, con
formatD2D.ApplyInlineColoring(m_Target.Get(), &drawPosition);

// Draw any 'shadow' effects
formatD2D.ApplyInlineShadow(m_Target.Get(), solidBrush.Get(), strLen, drawPosition);
const D2D1_RECT_F drawRect = D2D1::RectF(
drawPosition.x, drawPosition.y, rect.right - rect.left, rect.bottom - rect.top);
formatD2D.ApplyInlineShadow(m_Target.Get(), solidBrush.Get(), strLen, drawRect);
}

if (formatD2D.m_Trimming)
Expand Down
6 changes: 4 additions & 2 deletions Common/Gfx/TextFormatD2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,17 +1188,19 @@ void TextFormatD2D::ApplyInlineCase(std::wstring& str)
}

void TextFormatD2D::ApplyInlineShadow(ID2D1DeviceContext* target, ID2D1SolidColorBrush* solidBrush,
const UINT32 strLen, const D2D1_POINT_2F& drawPosition)
const UINT32 strLen, const D2D1_RECT_F& drawRect)
{
for (const auto& fmt : m_TextInlineFormat)
{
if (fmt->GetType() == Gfx::InlineType::Shadow)
{
auto option = dynamic_cast<TextInlineFormat_Shadow*>(fmt.get());
option->ApplyInlineFormat(target, m_TextLayout.Get(), solidBrush, strLen, drawPosition);
option->ApplyInlineFormat(target, m_TextLayout.Get(), solidBrush, strLen, drawRect);

// We need to reset the color options after the shadow effect because the shadow effect
// can turn some characters invisible.
D2D1_POINT_2F drawPosition = D2D1::Point2F(drawRect.left, drawRect.top);

ResetInlineColoring(solidBrush, strLen);
ResetGradientPosition(&drawPosition);
ApplyInlineColoring(target, &drawPosition);
Expand Down
2 changes: 1 addition & 1 deletion Common/Gfx/TextFormatD2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TextFormatD2D : public TextFormat
void ApplyInlineColoring(ID2D1DeviceContext* target, const D2D1_POINT_2F* point);
void ApplyInlineCase(std::wstring& str);
void ApplyInlineShadow(ID2D1DeviceContext* target, ID2D1SolidColorBrush* solidBrush,
const UINT32 strLen, const D2D1_POINT_2F& drawPosition);
const UINT32 strLen, const D2D1_RECT_F& drawRect);
void ResetGradientPosition(const D2D1_POINT_2F* point);
void ResetInlineColoring(ID2D1SolidColorBrush* solidColor, const UINT32 strLen);

Expand Down
28 changes: 14 additions & 14 deletions Common/Gfx/TextInlineFormat/TextInlineFormatShadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ TextInlineFormat_Shadow::~TextInlineFormat_Shadow()
}

void TextInlineFormat_Shadow::ApplyInlineFormat(ID2D1DeviceContext* target, IDWriteTextLayout* layout,
ID2D1SolidColorBrush* solidBrush, const UINT32& strLen, const D2D1_POINT_2F& drawPosition)
ID2D1SolidColorBrush* solidBrush, const UINT32& strLen, const D2D1_RECT_F& drawRect)
{
if (!target || !layout) return;

Expand Down Expand Up @@ -70,20 +70,18 @@ void TextInlineFormat_Shadow::ApplyInlineFormat(ID2D1DeviceContext* target, IDWr
}
}

const D2D1_POINT_2F drawPosition = D2D1::Point2F(drawRect.left, drawRect.top);
const D2D1_SIZE_F drawSize = D2D1::SizeF(drawRect.right, drawRect.bottom);

// Reset the shadow bitmap if the drawing position or size of target has changed.
if (m_BitmapTarget)
if (m_BitmapTarget && (
drawRect.left != m_PreviousPosition.left ||
drawRect.top != m_PreviousPosition.top ||
drawRect.right != m_PreviousPosition.right ||
drawRect.bottom != m_PreviousPosition.bottom))
{
const auto tSize = target->GetSize();
const D2D1_RECT_F position = D2D1::RectF(drawPosition.x, drawPosition.y, tSize.width, tSize.height);

if (position.left != m_PreviousPosition.left ||
position.top != m_PreviousPosition.top ||
position.right != m_PreviousPosition.right ||
position.bottom != m_PreviousPosition.bottom)
{
m_BitmapTarget.Reset();
m_PreviousPosition = position;
}
m_BitmapTarget.Reset();
m_PreviousPosition = drawRect;
}

m_Bitmap.Reset();
Expand All @@ -92,10 +90,12 @@ void TextInlineFormat_Shadow::ApplyInlineFormat(ID2D1DeviceContext* target, IDWr
{
m_BitmapTarget.Reset();

hr = target->CreateCompatibleRenderTarget(m_BitmapTarget.GetAddressOf());
hr = target->CreateCompatibleRenderTarget(drawSize, m_BitmapTarget.GetAddressOf());
if (FAILED(hr)) return;
}



// Draw onto memory bitmap target
// Note: Hardware acceleration seems to keep the bitmap render target in memory
// even though it is cleared, so manually "Clear" with a transparent color.
Expand Down
2 changes: 1 addition & 1 deletion Common/Gfx/TextInlineFormat/TextInlineFormatShadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TextInlineFormat_Shadow final : public TextInlineFormat

virtual void ApplyInlineFormat(IDWriteTextLayout* layout) override { }
void ApplyInlineFormat(ID2D1DeviceContext* target, IDWriteTextLayout* layout,
ID2D1SolidColorBrush* solidBrush, const UINT32& strLen, const D2D1_POINT_2F& drawPosition);
ID2D1SolidColorBrush* solidBrush, const UINT32& strLen, const D2D1_RECT_F& drawRect);

bool CompareAndUpdateProperties(const std::wstring& pattern, const FLOAT& blur,
const D2D1_POINT_2F& offset, const D2D1_COLOR_F& color);
Expand Down

0 comments on commit 102d1fd

Please sign in to comment.