/
MeterRoundLine.cpp
162 lines (139 loc) · 4.88 KB
/
MeterRoundLine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
Copyright (C) 2009 Kimmo Pekkola, Brian Todoroff
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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "MeterRoundLine.h"
#include "Measure.h"
#include "Error.h"
using namespace Gdiplus;
#define PI (3.14159265358979323846)
#define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
/*
** The constructor
**
*/
CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name),
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()
{
}
/*
** The destructor
**
*/
CMeterRoundLine::~CMeterRoundLine()
{
}
/*
** Read the options specified in the ini file.
**
*/
void CMeterRoundLine::ReadOptions(CConfigParser& parser, const WCHAR* section)
{
CMeter::ReadOptions(parser, section);
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);
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);
m_LineStartShift = parser.ReadFloat(section, L"StartShift", 0.0);
m_LineLengthShift = parser.ReadFloat(section, L"LengthShift", 0.0);
}
/*
** Updates the value(s) from the measures.
**
*/
bool CMeterRoundLine::Update()
{
if (CMeter::Update() && !m_Measures.empty())
{
CMeasure* measure = m_Measures[0];
if (m_ValueRemainder > 0)
{
LONGLONG time = (LONGLONG)measure->GetValue();
m_Value = (double)(time % m_ValueRemainder);
m_Value /= (double)m_ValueRemainder;
}
else
{
m_Value = measure->GetRelativeValue();
}
return true;
}
return false;
}
/*
** Draws the meter on the double buffer
**
*/
bool CMeterRoundLine::Draw(Graphics& graphics)
{
if (!CMeter::Draw(graphics)) return false;
// Calculate the center of for the line
int x = GetX();
int y = GetY();
double cx = x + m_W / 2.0;
double cy = y + m_H / 2.0;
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;
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);
if (m_Solid)
{
REAL startAngle = (REAL)(CONVERT_TO_DEGREES(m_StartAngle));
REAL sweepAngle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value));
// Calculate the start point of the line
double s_cos = cos(m_StartAngle);
double s_sin = sin(m_StartAngle);
//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);
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), startAngle, sweepAngle);
path.AddLine(ex, ey, sx, sy);
SolidBrush solidBrush(m_LineColor);
graphics.FillPath(&solidBrush, &path);
}
else
{
Pen pen(m_LineColor, (REAL)m_LineWidth);
graphics.DrawLine(&pen, sx, sy, ex, ey);
}
return true;
}