Skip to content

Commit

Permalink
Meter Rotator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAzack9 committed Feb 2, 2018
1 parent 1e6a415 commit 36fba2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
39 changes: 13 additions & 26 deletions Library/MeterRotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ using namespace Gdiplus;

MeterRotator::MeterRotator(Skin* skin, const WCHAR* name) : Meter(skin, name),
m_Image(L"ImageName", nullptr, false, skin),
m_NeedsReload(false),
m_OffsetX(),
m_OffsetY(),
m_StartAngle(),
Expand All @@ -44,7 +43,7 @@ void MeterRotator::Initialize()
// Load the bitmaps if defined
if (!m_ImageName.empty())
{
m_Image.LoadImage(m_ImageName, m_NeedsReload);
m_Image.LoadImage(m_ImageName);
}
else if (m_Image.IsLoaded())
{
Expand All @@ -69,10 +68,6 @@ void MeterRotator::ReadOptions(ConfigParser& parser, const WCHAR* section)
// Read tinting options
m_Image.ReadOptions(parser, section);
}
else
{
m_Image.ClearOptionFlags();
}

m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0);
m_OffsetY = parser.ReadFloat(section, L"OffsetY", 0.0);
Expand All @@ -84,13 +79,7 @@ void MeterRotator::ReadOptions(ConfigParser& parser, const WCHAR* section)

if (m_Initialized)
{
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);

if (m_NeedsReload ||
m_Image.IsOptionsChanged())
{
Initialize(); // Reload the image
}
Initialize(); // Reload the image
}
}

Expand Down Expand Up @@ -127,8 +116,6 @@ bool MeterRotator::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;

Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();

if (m_Image.IsLoaded())
{
// Calculate the center for rotation
Expand All @@ -142,22 +129,22 @@ bool MeterRotator::Draw(Gfx::Canvas& canvas)
REAL angle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value + m_StartAngle));

// TODO: convert to Canvas: canvas.RotateTransform(angle, cx, cy, (REAL)-m_OffsetX, (REAL)-m_OffsetY);
graphics.TranslateTransform(cx, cy);
graphics.RotateTransform(angle);
graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY);
// NOTE: canvas.RotateTransform does not work at all
Gdiplus::Matrix matrix;
matrix.Translate(cx, cy);
matrix.Rotate(angle);
matrix.Translate((REAL)-m_OffsetX, (REAL)-m_OffsetY);
canvas.SetTransform(matrix);

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

UINT width = drawBitmap->GetWidth();
UINT height = drawBitmap->GetHeight();
INT width = (INT)drawBitmap->GetWidth();
INT height = (INT)drawBitmap->GetHeight();

// Blit the image
graphics.DrawImage(drawBitmap, 0, 0, width, height);
canvas.DrawBitmap(drawBitmap, { 0, 0, width,height }, { 0,0,width,height });

graphics.ResetTransform();
canvas.ResetTransform();
}

canvas.EndGdiplusContext();

return true;
}
5 changes: 2 additions & 3 deletions Library/MeterRotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define __METERROTATOR_H__

#include "Meter.h"
#include "TintedImage.h"
#include "GeneralImage.h"

class MeterRotator : public Meter
{
Expand All @@ -30,9 +30,8 @@ class MeterRotator : public Meter
virtual void ReadOptions(ConfigParser& parser, const WCHAR* section);

private:
TintedImage m_Image;
GeneralImage m_Image;
std::wstring m_ImageName;
bool m_NeedsReload;

double m_OffsetX;
double m_OffsetY;
Expand Down

0 comments on commit 36fba2a

Please sign in to comment.