From 24b4d2ff1dce0d878beca9883d7c5dc33bc4d848 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 30 Dec 2021 00:37:38 -0700 Subject: [PATCH] Skin background/Meter: Properly fix Bevel offset to draw more like GDI+ --- Library/Meter.cpp | 43 ++++++++++++++++++++++++------------------- Library/Meter.h | 2 +- Library/Skin.cpp | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Library/Meter.cpp b/Library/Meter.cpp index cda32c75a..31e414200 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -842,8 +842,12 @@ bool Meter::Draw(Gfx::Canvas& canvas) // The bevel is drawn outside the meter const FLOAT x = (FLOAT)GetX(); const FLOAT y = (FLOAT)GetY(); - const D2D1_RECT_F rect = D2D1::RectF(x - 2.0f, y - 2.0f, x + (FLOAT)m_W + 2.0f, y + (FLOAT)m_H + 2.0f); - DrawBevel(canvas, rect, lightColor, darkColor); + const D2D1_RECT_F rect = D2D1::RectF( + x - 2.0f, + y - 2.0f, + x + (FLOAT)m_W + 2.0f, + y + (FLOAT)m_H + 2.0f); + DrawBevel(canvas, rect, lightColor, darkColor, m_AntiAlias); } return true; @@ -852,23 +856,24 @@ bool Meter::Draw(Gfx::Canvas& canvas) /* ** Draws a bevel inside the given area */ -void Meter::DrawBevel(Gfx::Canvas& canvas, const D2D1_RECT_F& rect, const D2D1_COLOR_F& light, const D2D1_COLOR_F& dark) +void Meter::DrawBevel(Gfx::Canvas& canvas, const D2D1_RECT_F& rect, const D2D1_COLOR_F& light, const D2D1_COLOR_F& dark, const bool offsetMode) { + // Simulate GDI+ "PixelOffsetModeHalf" offset mode + const FLOAT offset = offsetMode ? 0.0f : 0.5f; + const FLOAT w = 1.0f; - const FLOAT l = rect.left + w; - const FLOAT r = rect.right - w; - const FLOAT t = rect.top + w; - const FLOAT b = rect.bottom - w; - - // GDI+ offset for innermost lines - const FLOAT o = 0.155f; - - canvas.DrawLine(light, l, t, l, b, w); - canvas.DrawLine(light, l, t, r, t, w); - canvas.DrawLine(light, l + w - o, t + w, l + w - o, b - w, w - (2 * o)); - canvas.DrawLine(light, l + w, t + w - o, r - w, t + w - o, w - (2 * o)); - canvas.DrawLine(dark, l, b, r, b, w); - canvas.DrawLine(dark, r, t, r, b, w); - canvas.DrawLine(dark, l + w, b - w, r - w, b - w, w); - canvas.DrawLine(dark, r - w, t + w, r - w, b - w, w); + const FLOAT l = rect.left + offset; + const FLOAT t = rect.top + offset; + const FLOAT r = rect.right; + const FLOAT b = rect.bottom; + + canvas.DrawLine(light, l, t, l, b, w); + canvas.DrawLine(light, l, t, r, t, w); + canvas.DrawLine(light, l + w, t, l + w, b - w, w); + canvas.DrawLine(light, l, t + w, r - w, t + w, w); + + canvas.DrawLine(dark, l, b, r, b, w); + canvas.DrawLine(dark, r, t, r, b, w); + canvas.DrawLine(dark, l + w, b - w, r - w, b - w, w); + canvas.DrawLine(dark, r - w, t + w, r - w, b - w, w); } diff --git a/Library/Meter.h b/Library/Meter.h index 0ee327f25..3d58512d3 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -92,7 +92,7 @@ class __declspec(novtable) Meter : public Section static Meter* Create(const WCHAR* meter, Skin* skin, const WCHAR* name); - static void DrawBevel(Gfx::Canvas& canvas, const D2D1_RECT_F& rect, const D2D1_COLOR_F& light, const D2D1_COLOR_F& dark); + static void DrawBevel(Gfx::Canvas& canvas, const D2D1_RECT_F& rect, const D2D1_COLOR_F& light, const D2D1_COLOR_F& dark, const bool offsetMode); protected: diff --git a/Library/Skin.cpp b/Library/Skin.cpp index 74b00052f..c8c626b91 100644 --- a/Library/Skin.cpp +++ b/Library/Skin.cpp @@ -2898,7 +2898,7 @@ void Skin::Redraw() std::swap(lightColor, darkColor); } - Meter::DrawBevel(m_Canvas, r, lightColor, darkColor); + Meter::DrawBevel(m_Canvas, r, lightColor, darkColor, false); } }