Gfx: Added support for TransformationMatrix and Angle (for String meters)

This commit is contained in:
Brian Ferguson 2013-04-05 02:35:20 -06:00
parent add778cfea
commit 59b3dea21c
7 changed files with 67 additions and 15 deletions

View File

@ -57,11 +57,9 @@ public:
virtual bool IsTransparentPixel(int x, int y) = 0; virtual bool IsTransparentPixel(int x, int y) = 0;
// TODO: Implement proper solution. virtual void SetTransform(const Gdiplus::Matrix& matrix) = 0;
virtual void SetTransform(const Gdiplus::Matrix& matrix) {} virtual void ResetTransform() = 0;
virtual void ResetTransform() {} virtual void RotateTransform(float angle, float x, float y, float dx, float dy) = 0;
virtual void RotateTransform(float angle) {}
virtual void TranslateTransform(float dx, float dy) {}
virtual void SetAntiAliasing(bool enable) = 0; virtual void SetAntiAliasing(bool enable) = 0;
virtual void SetTextAntiAliasing(bool enable) = 0; virtual void SetTextAntiAliasing(bool enable) = 0;

View File

@ -179,6 +179,10 @@ bool CanvasD2D::BeginTargetDraw()
SetTextAntiAliasing(m_TextAntiAliasing); SetTextAntiAliasing(m_TextAntiAliasing);
m_Target->BeginDraw(); m_Target->BeginDraw();
// Apply any transforms that occurred before creation of m_Target
m_Target->SetTransform(GetCurrentTransform());
return true; return true;
} }
@ -235,6 +239,54 @@ bool CanvasD2D::IsTransparentPixel(int x, int y)
return transparent; return transparent;
} }
D2D1::Matrix3x2F CanvasD2D::GetCurrentTransform()
{
D2D1::Matrix3x2F dMatrix = D2D1::Matrix3x2F::Identity();
Gdiplus::Matrix gMatrix;
if (Gdiplus::Ok == m_GdipGraphics->GetTransform(&gMatrix))
{
float m[6];
gMatrix.GetElements(m);
dMatrix = D2D1::Matrix3x2F(m[0], m[1], m[2], m[3], m[4], m[5]);
}
return dMatrix;
}
void CanvasD2D::SetTransform(const Gdiplus::Matrix& matrix)
{
m_GdipGraphics->SetTransform(&matrix);
if (m_Target)
{
m_Target->SetTransform(GetCurrentTransform());
}
}
void CanvasD2D::ResetTransform()
{
m_GdipGraphics->ResetTransform();
if (m_Target)
{
m_Target->SetTransform(D2D1::Matrix3x2F::Identity());
}
}
void CanvasD2D::RotateTransform(float angle, float x, float y, float dx, float dy)
{
m_GdipGraphics->TranslateTransform(x, y);
m_GdipGraphics->RotateTransform(angle);
m_GdipGraphics->TranslateTransform(dx, dy);
if (m_Target)
{
m_Target->SetTransform(GetCurrentTransform());
}
}
void CanvasD2D::SetAntiAliasing(bool enable) void CanvasD2D::SetAntiAliasing(bool enable)
{ {
// TODO: Set m_Target aliasing? // TODO: Set m_Target aliasing?

View File

@ -53,6 +53,10 @@ public:
virtual bool IsTransparentPixel(int x, int y) override; virtual bool IsTransparentPixel(int x, int y) override;
virtual void SetTransform(const Gdiplus::Matrix& matrix) override;
virtual void ResetTransform() override;
virtual void RotateTransform(float angle, float x, float y, float dx, float dy) override;
virtual void SetAntiAliasing(bool enable) override; virtual void SetAntiAliasing(bool enable) override;
virtual void SetTextAntiAliasing(bool enable) override; virtual void SetTextAntiAliasing(bool enable) override;
@ -79,6 +83,9 @@ private:
bool BeginTargetDraw(); bool BeginTargetDraw();
void EndTargetDraw(); void EndTargetDraw();
// Retrieves current GDI+ transform (if any) and converts to a D2D Matrix
D2D1::Matrix3x2F GetCurrentTransform();
ID2D1RenderTarget* m_Target; ID2D1RenderTarget* m_Target;
WICBitmapDIB m_Bitmap; WICBitmapDIB m_Bitmap;

View File

@ -138,13 +138,10 @@ void CanvasGDIP::ResetTransform()
m_Graphics->ResetTransform(); m_Graphics->ResetTransform();
} }
void CanvasGDIP::RotateTransform(float angle) void CanvasGDIP::RotateTransform(float angle, float x, float y, float dx, float dy)
{ {
m_Graphics->TranslateTransform(x, y);
m_Graphics->RotateTransform(angle); m_Graphics->RotateTransform(angle);
}
void CanvasGDIP::TranslateTransform(float dx, float dy)
{
m_Graphics->TranslateTransform(dx, dy); m_Graphics->TranslateTransform(dx, dy);
} }

View File

@ -50,8 +50,7 @@ public:
virtual void SetTransform(const Gdiplus::Matrix& matrix) override; virtual void SetTransform(const Gdiplus::Matrix& matrix) override;
virtual void ResetTransform() override; virtual void ResetTransform() override;
virtual void RotateTransform(float angle) override; virtual void RotateTransform(float angle, float x, float y, float dx, float dy) override;
virtual void TranslateTransform(float dx, float dy) override;
virtual void SetAntiAliasing(bool enable) override; virtual void SetAntiAliasing(bool enable) override;
virtual void SetTextAntiAliasing(bool enable) override; virtual void SetTextAntiAliasing(bool enable) override;

View File

@ -164,6 +164,7 @@ bool CMeterRotator::Draw(Gfx::Canvas& canvas)
// Calculate the rotation // Calculate the rotation
REAL angle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value + m_StartAngle)); 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.TranslateTransform(cx, cy);
graphics.RotateTransform(angle); graphics.RotateTransform(angle);
graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY); graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY);

View File

@ -542,9 +542,7 @@ bool CMeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
if (m_Angle != 0.0f) if (m_Angle != 0.0f)
{ {
canvas.TranslateTransform((Gdiplus::REAL)CMeter::GetX(), y); canvas.RotateTransform(CONVERT_TO_DEGREES(m_Angle), x, y, -x, -y);
canvas.RotateTransform(CONVERT_TO_DEGREES(m_Angle));
canvas.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y);
} }
if (m_Effect != EFFECT_NONE) if (m_Effect != EFFECT_NONE)