Code cleanup.

This commit is contained in:
spx 2010-12-28 19:43:19 +00:00
parent 2fafb5dcdc
commit 365206e33a
2 changed files with 31 additions and 36 deletions

View File

@ -22,7 +22,9 @@
#include "Error.h" #include "Error.h"
using namespace Gdiplus; using namespace Gdiplus;
#define PI 3.14159265
#define PI (3.14159265358979323846)
#define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
/* /*
** CMeterRoundLine ** CMeterRoundLine
@ -133,6 +135,11 @@ bool CMeterRoundLine::Draw(Graphics& graphics)
if (m_Solid) if (m_Solid)
{ {
REAL startAngle = (REAL)(CONVERT_TO_DEGREES(m_StartAngle));
REAL sweepAngle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value));
SolidBrush solidBrush(m_LineColor);
if (1) //m_LineStart > 0.0) if (1) //m_LineStart > 0.0)
{ {
// Create clipping region // Create clipping region
@ -142,60 +149,47 @@ bool CMeterRoundLine::Draw(Graphics& graphics)
// Calculate the end point of the line // Calculate the end point of the line
//double angle = m_RotationAngle * m_Value + m_StartAngle; //double angle = m_RotationAngle * m_Value + m_StartAngle;
double angle = m_RotationAngle + m_StartAngle; double angle = (m_CntrlAngle) ? m_RotationAngle * m_Value + m_StartAngle : m_RotationAngle + m_StartAngle;
if(m_CntrlAngle) double lineStart = (m_CntrlLineStart) ? m_LineStartShift * m_Value + m_LineStart : m_LineStart;
angle = m_RotationAngle * m_Value + m_StartAngle; double lineLength = (m_CntrlLineLength) ? m_LineLengthShift * m_Value + m_LineLength : m_LineLength;
double lineStart = m_LineStart; REAL s_cos = (REAL)cos(m_StartAngle);
if(m_CntrlLineStart) REAL s_sin = (REAL)sin(m_StartAngle);
{ REAL e_cos = (REAL)cos(angle);
lineStart = m_LineStartShift * m_Value + m_LineStart; REAL e_sin = (REAL)sin(angle);
}
double lineLength = m_LineLength;
if(m_CntrlLineLength)
{
lineLength = m_LineLengthShift * m_Value + m_LineLength;
}
SolidBrush solidBrush(m_LineColor);
//Create a path to surround the arc //Create a path to surround the arc
GraphicsPath path; GraphicsPath path;
path.AddArc((REAL)(cx - lineStart), (REAL)(cy - lineStart), (REAL)(lineStart * 2.0), (REAL)(lineStart * 2.0), (REAL)(m_StartAngle * 180.0 / PI), (REAL)(m_RotationAngle * m_Value * 180.0 / PI)); path.AddArc((REAL)(cx - lineStart), (REAL)(cy - lineStart), (REAL)(lineStart * 2.0), (REAL)(lineStart * 2.0), startAngle, sweepAngle);
path.AddLine((REAL)lineStart*(REAL)cos(m_StartAngle)+cx,(REAL)lineStart*(REAL)sin(m_StartAngle)+cy,(REAL)lineLength*(REAL)cos(m_StartAngle)+cx,(REAL)lineLength*(REAL)sin(m_StartAngle)+cy); path.AddLine((REAL)lineStart * s_cos + cx, (REAL)lineStart * s_sin + cy, (REAL)lineLength * s_cos + cx, (REAL)lineLength * s_sin + cy);
path.AddArc((REAL)(cx - lineLength), (REAL)(cy - lineLength), (REAL)(lineLength * 2.0), (REAL)(lineLength * 2.0), (REAL)(m_StartAngle * 180.0 / PI), (REAL)(m_RotationAngle * m_Value * 180.0 / PI)); path.AddArc((REAL)(cx - lineLength), (REAL)(cy - lineLength), (REAL)(lineLength * 2.0), (REAL)(lineLength * 2.0), startAngle, sweepAngle);
path.AddLine((REAL)lineLength*(REAL)cos(angle)+cx,(REAL)lineLength*(REAL)sin(angle)+cy,(REAL)lineStart*(REAL)cos(angle)+cx,(REAL)lineStart*(REAL)sin(angle)+cy); path.AddLine((REAL)lineLength * e_cos + cx, (REAL)lineLength * e_sin + cy, (REAL)lineStart * e_cos + cx, (REAL)lineStart * e_sin + cy);
graphics.FillPath(&solidBrush,&path); graphics.FillPath(&solidBrush, &path);
} }
else else
{ {
// Calculate the center of for the line // Calculate the center of for the line
SolidBrush solidBrush(m_LineColor); graphics.FillPie(&solidBrush, (REAL)(cx - m_LineLength), (REAL)(cy - m_LineLength), (REAL)(m_LineLength * 2.0), (REAL)(m_LineLength * 2.0), startAngle, sweepAngle);
graphics.FillPie(&solidBrush, (REAL)(cx - m_LineLength), (REAL)(cy - m_LineLength), (REAL)(m_LineLength * 2.0), (REAL)(m_LineLength * 2.0), (REAL)(m_StartAngle * 180.0 / PI), (REAL)(m_RotationAngle * m_Value * 180.0 / PI));
} }
} }
else else
{ {
REAL x, y;
Pen pen(m_LineColor, (REAL)m_LineWidth);
// Calculate the end point of the line // Calculate the end point of the line
double angle = m_RotationAngle * m_Value + m_StartAngle; double angle = m_RotationAngle * m_Value + m_StartAngle;
REAL e_cos = (REAL)cos(angle);
x = (REAL)cos(angle); REAL e_sin = (REAL)sin(angle);
y = (REAL)sin(angle);
// Set the length // Set the length
x = x * (REAL)m_LineLength + cx; REAL x = e_cos * (REAL)m_LineLength + cx;
y = y * (REAL)m_LineLength + cy; REAL y = e_sin * (REAL)m_LineLength + cy;
if (m_LineStart > 0.0) if (m_LineStart > 0.0)
{ {
cx = (REAL)cos(angle) * (REAL)m_LineStart + cx; cx += e_cos * (REAL)m_LineStart;
cy = (REAL)sin(angle) * (REAL)m_LineStart + cy; cy += e_sin * (REAL)m_LineStart;
} }
Pen pen(m_LineColor, (REAL)m_LineWidth);
graphics.DrawLine(&pen, cx, cy, x, y); graphics.DrawLine(&pen, cx, cy, x, y);
} }

View File

@ -23,7 +23,8 @@
using namespace Gdiplus; using namespace Gdiplus;
#define PI 3.14159265f #define PI (3.14159265f)
#define CONVERT_TO_RADIANS(X) ((X) * (PI / 180.0f))
// GrayScale Matrix // GrayScale Matrix
const Gdiplus::ColorMatrix CTintedImage::c_GreyScaleMatrix = { const Gdiplus::ColorMatrix CTintedImage::c_GreyScaleMatrix = {
@ -387,7 +388,7 @@ void CTintedImage::ApplyTransform()
REAL originalW = (REAL)original->GetWidth(); REAL originalW = (REAL)original->GetWidth();
REAL originalH = (REAL)original->GetHeight(); REAL originalH = (REAL)original->GetHeight();
REAL cos_f = cos(m_Rotate * PI / 180.0f), sin_f = sin(m_Rotate * PI / 180.0f); REAL cos_f = cos(CONVERT_TO_RADIANS(m_Rotate)), sin_f = sin(CONVERT_TO_RADIANS(m_Rotate));
REAL transformW = fabs(originalW * cos_f) + fabs(originalH * sin_f); REAL transformW = fabs(originalW * cos_f) + fabs(originalH * sin_f);
REAL transformH = fabs(originalW * sin_f) + fabs(originalH * cos_f); REAL transformH = fabs(originalW * sin_f) + fabs(originalH * cos_f);