Skip to content

Commit

Permalink
Cleanup of gdi dependencies in MeterBar
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAzack9 committed Apr 1, 2018
1 parent af47440 commit 8831821
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
83 changes: 44 additions & 39 deletions Library/MeterBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#include "Rainmeter.h"
#include "../Common/Gfx/Canvas.h"

using namespace Gdiplus;

MeterBar::MeterBar(Skin* skin, const WCHAR* name) : Meter(skin, name),
m_Image(L"BarImage", nullptr, false, skin),
m_Color(Color::Green),
m_Color(D2D1::ColorF(D2D1::ColorF::Green)),
m_Orientation(VERTICAL),
m_Value(),
m_Border(),
Expand Down Expand Up @@ -67,7 +65,7 @@ void MeterBar::ReadOptions(ConfigParser& parser, const WCHAR* section)

Meter::ReadOptions(parser, section);

m_Color = parser.ReadColor(section, L"BarColor", Color::Green);
m_Color = Gfx::Util::ToColorF(parser.ReadColor(section, L"BarColor", Gdiplus::Color::Green));

m_ImageName = parser.ReadString(section, L"BarImage", L"");
if (!m_ImageName.empty())
Expand Down Expand Up @@ -122,13 +120,15 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;

Gdiplus::Rect meterRect = GetMeterRectPadding();
D2D1_RECT_F meterRect = Gfx::Util::ToRectF(GetMeterRectPadding());
FLOAT drawW = meterRect.right - meterRect.left;
FLOAT drawH = meterRect.bottom - meterRect.top;

Gfx::D2DBitmap* drawBitmap = m_Image.GetImage();

if (m_Orientation == VERTICAL)
{
int barSize = meterRect.Height - 2 * m_Border;
int barSize = (int)(drawH - 2 * m_Border);
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
Expand All @@ -139,46 +139,49 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (m_Border > 0)
{
Rect r2(meterRect.X, meterRect.Y, meterRect.Width, m_Border);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, 0, meterRect.Width, m_Border)));
r2.Y = meterRect.Y + size + m_Border;
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, meterRect.Height - m_Border, meterRect.Width, m_Border)));
D2D1_RECT_F r2 = meterRect;
r2.bottom = r2.top + m_Border;
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, 0, meterRect.right, (FLOAT)m_Border));
r2.top = meterRect.top + size + m_Border;
r2.bottom = r2.top + m_Border;
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, drawH - m_Border, drawW, (FLOAT)m_Border));
}

Rect r(meterRect.X, meterRect.Y + m_Border, meterRect.Width, size);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(0, m_Border, meterRect.Width, size)));
D2D1_RECT_F r = { meterRect.left, meterRect.top + m_Border, meterRect.right, meterRect.top + m_Border + size };
canvas.DrawBitmap(drawBitmap, r, D2D1::RectF(0, (FLOAT)m_Border, drawW, (FLOAT)(m_Border + size)));
}
else
{
if (m_Border > 0)
{
Rect r2(meterRect.X, meterRect.Y + meterRect.Height - size - 2 * m_Border, meterRect.Width, m_Border);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, 0, meterRect.Width, m_Border)));
r2.Y = meterRect.Y + meterRect.Height - m_Border;
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, meterRect.Height - m_Border, meterRect.Width, m_Border)));
D2D1_RECT_F r2 = { meterRect.left, meterRect.bottom - size - 2 * m_Border, meterRect.right, meterRect.bottom - size - m_Border};
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, 0, drawW, (FLOAT)m_Border));
r2.top = meterRect.bottom - m_Border;
r2.bottom = r2.top + m_Border;
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, drawH - m_Border, drawW, (FLOAT)m_Border));
}

Rect r(meterRect.X, meterRect.Y + meterRect.Height - size - m_Border, meterRect.Width, size);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(0, meterRect.Height - size - m_Border, meterRect.Width, size)));
D2D1_RECT_F r = { meterRect.left, meterRect.bottom - size - m_Border, meterRect.right, meterRect.bottom - m_Border};
canvas.DrawBitmap(drawBitmap, r, D2D1::RectF(0, drawH - size - m_Border, drawW, (FLOAT)size));
}
}
else
{
if (m_Flip)
{
Rect r(meterRect.X, meterRect.Y, meterRect.Width, size);
canvas.FillRectangle(Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(m_Color));
D2D1_RECT_F r = { meterRect.left, meterRect.top, meterRect.right, meterRect.top + size};
canvas.FillRectangle(r, m_Color);
}
else
{
Rect r(meterRect.X, meterRect.Y + meterRect.Height - size, meterRect.Width, size);
canvas.FillRectangle(Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(m_Color));
D2D1_RECT_F r = { meterRect.left, meterRect.bottom - size, meterRect.right, meterRect.bottom };
canvas.FillRectangle(r, m_Color);
}
}
}
else
{
int barSize = meterRect.Width - 2 * m_Border;
int barSize = (int)(drawW - 2 * m_Border);
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
Expand All @@ -189,40 +192,42 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (m_Border > 0)
{
Rect r2(meterRect.X + meterRect.Width - size - 2 * m_Border, meterRect.Y, m_Border, meterRect.Height);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, 0, m_Border, meterRect.Height)));
r2.X = meterRect.X + meterRect.Width - m_Border;
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(meterRect.Width - m_Border, 0, m_Border, meterRect.Height)));
D2D1_RECT_F r2 = { meterRect.right - size - 2 * m_Border, meterRect.top, meterRect.right - size - m_Border, meterRect.bottom };
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, 0, (FLOAT)m_Border, drawH));
r2.left = meterRect.right - m_Border;
r2.right = r2.left + m_Border;
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(drawW - m_Border, 0, drawW, drawH + m_Border));
}

Rect r(meterRect.X + meterRect.Width - size - m_Border, meterRect.Y, size, meterRect.Height);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(meterRect.Width - size - m_Border, 0, size, meterRect.Height)));
D2D1_RECT_F r = { meterRect.right - size - m_Border, meterRect.top, meterRect.right - m_Border, meterRect.bottom };
canvas.DrawBitmap(drawBitmap, r, D2D1::RectF(drawW - size - m_Border, 0, drawW - m_Border, drawH));
}
else
{
if (m_Border > 0)
{
Rect r2(meterRect.X, meterRect.Y, m_Border, meterRect.Height);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(0, 0, m_Border, meterRect.Height)));
r2.X = meterRect.X + size + m_Border;
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r2), Gfx::Util::ToRectF(Rect(meterRect.Width - m_Border, 0, m_Border, meterRect.Height)));
D2D1_RECT_F r2 = { meterRect.left, meterRect.top, meterRect.left + m_Border, meterRect.bottom };
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(0, 0, (FLOAT)m_Border, drawH));
r2.left = meterRect.left + size + m_Border;
r2.right = r2.left + m_Border;
canvas.DrawBitmap(drawBitmap, r2, D2D1::RectF(drawW - m_Border, 0, drawW, drawH));
}

Rect r(meterRect.X + m_Border, meterRect.Y, size, meterRect.Height);
canvas.DrawBitmap(drawBitmap, Gfx::Util::ToRectF(r), Gfx::Util::ToRectF(Rect(m_Border, 0, size, meterRect.Height)));
D2D1_RECT_F r = { meterRect.left + m_Border, meterRect.top, meterRect.left + m_Border + size, meterRect.bottom };
canvas.DrawBitmap(drawBitmap, r, D2D1::RectF((FLOAT)m_Border, 0, (FLOAT)(m_Border + size), drawH));
}
}
else
{
if (m_Flip)
{
Rect r(meterRect.X + meterRect.Width - size, meterRect.Y, size, meterRect.Height);
canvas.FillRectangle(Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(m_Color));
D2D1_RECT_F r = { meterRect.right - size, meterRect.top, meterRect.right, meterRect.bottom};
canvas.FillRectangle(r, m_Color);
}
else
{
Rect r(meterRect.X, meterRect.Y, size, meterRect.Height);
canvas.FillRectangle(Gfx::Util::ToRectF(r), Gfx::Util::ToColorF(m_Color));
D2D1_RECT_F r = { meterRect.left, meterRect.top, meterRect.left + size, meterRect.bottom };
canvas.FillRectangle(r, m_Color);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Library/MeterBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MeterBar : public Meter
GeneralImage m_Image;
std::wstring m_ImageName;

Gdiplus::Color m_Color;
D2D1_COLOR_F m_Color;
ORIENTATION m_Orientation; // Growth direction
double m_Value;
int m_Border;
Expand Down

0 comments on commit 8831821

Please sign in to comment.