Skip to content

Commit

Permalink
Skin background/Meter: Properly fix Bevel offset to draw more like GDI+
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Dec 30, 2021
1 parent 0de2af8 commit 24b4d2f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
43 changes: 24 additions & 19 deletions Library/Meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion Library/Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion Library/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 24b4d2f

Please sign in to comment.