2009-02-10 18:37:48 +00:00
|
|
|
/*
|
2009-03-12 19:32:43 +00:00
|
|
|
Copyright (C) 2009 Kimmo Pekkola, Brian Todoroff
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "MeterRoundLine.h"
|
|
|
|
#include "Measure.h"
|
|
|
|
#include "Error.h"
|
2013-03-25 15:42:18 +00:00
|
|
|
#include "../Common/Gfx/Canvas.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
using namespace Gdiplus;
|
2010-12-28 19:43:19 +00:00
|
|
|
|
|
|
|
#define PI (3.14159265358979323846)
|
|
|
|
#define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterRoundLine::MeterRoundLine(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_Solid(false),
|
|
|
|
m_LineWidth(1.0),
|
|
|
|
m_LineLength(20.0),
|
|
|
|
m_LineStart(-1.0),
|
|
|
|
m_StartAngle(),
|
|
|
|
m_RotationAngle(6.2832),
|
|
|
|
m_CntrlAngle(true),
|
|
|
|
m_CntrlLineStart(false),
|
|
|
|
m_CntrlLineLength(false),
|
|
|
|
m_LineStartShift(),
|
|
|
|
m_LineLengthShift(),
|
|
|
|
m_ValueRemainder(),
|
|
|
|
m_LineColor(Color::Black),
|
|
|
|
m_Value()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterRoundLine::~MeterRoundLine()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-01 13:06:36 +00:00
|
|
|
** Read the options specified in the ini file.
|
2009-02-10 18:37:48 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterRoundLine::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
Meter::ReadOptions(parser, section);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-04-06 12:16:54 +00:00
|
|
|
m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
|
|
|
|
m_LineLength = parser.ReadFloat(section, L"LineLength", 20.0);
|
|
|
|
m_LineStart = parser.ReadFloat(section, L"LineStart", -1.0);
|
|
|
|
m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
|
|
|
|
m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
|
2009-09-04 16:37:51 +00:00
|
|
|
m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
|
|
|
|
m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
|
|
|
|
m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black);
|
|
|
|
m_Solid = 0!=parser.ReadInt(section, L"Solid", 0);
|
|
|
|
m_CntrlAngle = 0!=parser.ReadInt(section, L"ControlAngle", 1);
|
|
|
|
m_CntrlLineStart = 0!=parser.ReadInt(section, L"ControlStart", 0);
|
|
|
|
m_CntrlLineLength = 0!=parser.ReadInt(section, L"ControlLength", 0);
|
2011-01-29 00:11:01 +00:00
|
|
|
m_LineStartShift = parser.ReadFloat(section, L"StartShift", 0.0);
|
|
|
|
m_LineLengthShift = parser.ReadFloat(section, L"LengthShift", 0.0);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool MeterRoundLine::Update()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
if (Meter::Update())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-09-29 19:16:32 +00:00
|
|
|
if (m_Measures.empty())
|
|
|
|
{
|
|
|
|
m_Value = 1.0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
Measure* measure = m_Measures[0];
|
2009-02-10 18:37:48 +00:00
|
|
|
if (m_ValueRemainder > 0)
|
|
|
|
{
|
2012-07-17 07:37:53 +00:00
|
|
|
LONGLONG time = (LONGLONG)measure->GetValue();
|
2011-04-27 11:35:25 +00:00
|
|
|
m_Value = (double)(time % m_ValueRemainder);
|
2009-02-10 18:37:48 +00:00
|
|
|
m_Value /= (double)m_ValueRemainder;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-17 07:37:53 +00:00
|
|
|
m_Value = measure->GetRelativeValue();
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Draws the meter on the double buffer
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool MeterRoundLine::Draw(Gfx::Canvas& canvas)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
if (!Meter::Draw(canvas)) return false;
|
2013-03-25 15:42:18 +00:00
|
|
|
|
|
|
|
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Calculate the center of for the line
|
|
|
|
int x = GetX();
|
|
|
|
int y = GetY();
|
2011-05-04 18:48:26 +00:00
|
|
|
double cx = x + m_W / 2.0;
|
|
|
|
double cy = y + m_H / 2.0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-04-27 11:35:25 +00:00
|
|
|
double lineStart = ((m_CntrlLineStart) ? m_LineStartShift * m_Value : 0) + m_LineStart;
|
|
|
|
double lineLength = ((m_CntrlLineLength) ? m_LineLengthShift * m_Value : 0) + m_LineLength;
|
|
|
|
|
|
|
|
// Calculate the end point of the line
|
|
|
|
double angle = ((m_CntrlAngle) ? m_RotationAngle * m_Value : m_RotationAngle) + m_StartAngle;
|
2011-05-04 18:48:26 +00:00
|
|
|
double e_cos = cos(angle);
|
|
|
|
double e_sin = sin(angle);
|
|
|
|
|
|
|
|
REAL sx = (REAL)(e_cos * lineStart + cx);
|
|
|
|
REAL sy = (REAL)(e_sin * lineStart + cy);
|
|
|
|
REAL ex = (REAL)(e_cos * lineLength + cx);
|
|
|
|
REAL ey = (REAL)(e_sin * lineLength + cy);
|
2011-04-27 11:35:25 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
if (m_Solid)
|
|
|
|
{
|
2013-05-16 19:45:32 +00:00
|
|
|
REAL startAngle = (REAL)(fmod(CONVERT_TO_DEGREES(m_StartAngle), 360.0));
|
2010-12-28 19:43:19 +00:00
|
|
|
REAL sweepAngle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value));
|
|
|
|
|
2011-04-27 11:35:25 +00:00
|
|
|
// Calculate the start point of the line
|
2011-05-04 18:48:26 +00:00
|
|
|
double s_cos = cos(m_StartAngle);
|
|
|
|
double s_sin = sin(m_StartAngle);
|
2010-12-28 19:43:19 +00:00
|
|
|
|
2011-04-27 11:35:25 +00:00
|
|
|
//Create a path to surround the arc
|
|
|
|
GraphicsPath path;
|
|
|
|
path.AddArc((REAL)(cx - lineStart), (REAL)(cy - lineStart), (REAL)(lineStart * 2.0), (REAL)(lineStart * 2.0), startAngle, sweepAngle);
|
2011-05-04 18:48:26 +00:00
|
|
|
path.AddLine((REAL)(lineStart * s_cos + cx), (REAL)(lineStart * s_sin + cy), (REAL)(lineLength * s_cos + cx), (REAL)(lineLength * s_sin + cy));
|
2011-04-27 11:35:25 +00:00
|
|
|
path.AddArc((REAL)(cx - lineLength), (REAL)(cy - lineLength), (REAL)(lineLength * 2.0), (REAL)(lineLength * 2.0), startAngle, sweepAngle);
|
2011-05-04 18:48:26 +00:00
|
|
|
path.AddLine(ex, ey, sx, sy);
|
2011-04-27 11:35:25 +00:00
|
|
|
|
|
|
|
SolidBrush solidBrush(m_LineColor);
|
|
|
|
graphics.FillPath(&solidBrush, &path);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-28 19:43:19 +00:00
|
|
|
Pen pen(m_LineColor, (REAL)m_LineWidth);
|
2011-05-04 18:48:26 +00:00
|
|
|
graphics.DrawLine(&pen, sx, sy, ex, ey);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 15:42:18 +00:00
|
|
|
canvas.EndGdiplusContext();
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-29 19:29:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Overridden method. The roundline meters need not to be bound on anything
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterRoundLine::BindMeasures(ConfigParser& parser, const WCHAR* section)
|
2012-09-29 19:29:38 +00:00
|
|
|
{
|
|
|
|
BindPrimaryMeasure(parser, section, true);
|
|
|
|
}
|