Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 163 lines (139 sloc) 5.002 kb
30edc89
Kimmo Pekkola authored
1 /*
a035c76 Fixed RoundLine implementation for Solid=1, AntiAlias=1, and LineStart >...
Brian Todoroff authored
2 Copyright (C) 2009 Kimmo Pekkola, Brian Todoroff
30edc89
Kimmo Pekkola authored
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
ebec089 spx Adjusted copyright notice.
spx268 authored
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30edc89
Kimmo Pekkola authored
17 */
18
0b4ba32 Added cache for the fonts.
Kimmo Pekkola authored
19 #include "StdAfx.h"
30edc89
Kimmo Pekkola authored
20 #include "MeterRoundLine.h"
21 #include "Measure.h"
22 #include "Error.h"
23
24 using namespace Gdiplus;
365206e spx Code cleanup.
spx268 authored
25
26 #define PI (3.14159265358979323846)
27 #define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
30edc89
Kimmo Pekkola authored
28
29 /*
30 ** The constructor
31 **
32 */
fe9fd9f spx Code cleanup.
spx268 authored
33 CMeterRoundLine::CMeterRoundLine(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name),
7ea3a76 spx - Fixed that r716 (precompiled header) doesn't work on x64.
spx268 authored
34 m_Solid(false),
35 m_LineWidth(1.0),
36 m_LineLength(20.0),
37 m_LineStart(-1.0),
38 m_StartAngle(),
39 m_RotationAngle(6.2832),
40 m_CntrlAngle(true),
41 m_CntrlLineStart(false),
42 m_CntrlLineLength(false),
43 m_LineStartShift(),
44 m_LineLengthShift(),
45 m_ValueRemainder(),
46 m_LineColor(Color::Black),
47 m_Value()
30edc89
Kimmo Pekkola authored
48 {
49 }
50
51 /*
52 ** The destructor
53 **
54 */
55 CMeterRoundLine::~CMeterRoundLine()
56 {
57 }
58
59 /*
922dd09 Birunthan Mohanathas Cosmetics: Changed "config" to more consistent and descriptive terms
poiru authored
60 ** Read the options specified in the ini file.
30edc89
Kimmo Pekkola authored
61 **
62 */
e3d92d3 Birunthan Mohanathas Cosmetics
poiru authored
63 void CMeterRoundLine::ReadOptions(CConfigParser& parser, const WCHAR* section)
30edc89
Kimmo Pekkola authored
64 {
e3d92d3 Birunthan Mohanathas Cosmetics
poiru authored
65 CMeter::ReadOptions(parser, section);
30edc89
Kimmo Pekkola authored
66
ba239ff Birunthan Mohanathas Changed all numerical options or numerical parameters of bangs to accept...
poiru authored
67 m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
68 m_LineLength = parser.ReadFloat(section, L"LineLength", 20.0);
69 m_LineStart = parser.ReadFloat(section, L"LineStart", -1.0);
70 m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
71 m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
4bf4e51 Reverted the changes from r209.
Kimmo Pekkola authored
72 m_ValueRemainder = parser.ReadInt(section, L"ValueReminder", 0); // Typo
73 m_ValueRemainder = parser.ReadInt(section, L"ValueRemainder", m_ValueRemainder);
74 m_LineColor = parser.ReadColor(section, L"LineColor", Color::Black);
75 m_Solid = 0!=parser.ReadInt(section, L"Solid", 0);
76 m_CntrlAngle = 0!=parser.ReadInt(section, L"ControlAngle", 1);
77 m_CntrlLineStart = 0!=parser.ReadInt(section, L"ControlStart", 0);
78 m_CntrlLineLength = 0!=parser.ReadInt(section, L"ControlLength", 0);
7ea3a76 spx - Fixed that r716 (precompiled header) doesn't work on x64.
spx268 authored
79 m_LineStartShift = parser.ReadFloat(section, L"StartShift", 0.0);
80 m_LineLengthShift = parser.ReadFloat(section, L"LengthShift", 0.0);
30edc89
Kimmo Pekkola authored
81 }
82
83 /*
84 ** Updates the value(s) from the measures.
85 **
86 */
87 bool CMeterRoundLine::Update()
88 {
4bbc372 Birunthan Mohanathas Tweaked measure binding
poiru authored
89 if (CMeter::Update() && !m_Measures.empty())
30edc89
Kimmo Pekkola authored
90 {
4bbc372 Birunthan Mohanathas Tweaked measure binding
poiru authored
91 CMeasure* measure = m_Measures[0];
30edc89
Kimmo Pekkola authored
92 if (m_ValueRemainder > 0)
93 {
4bbc372 Birunthan Mohanathas Tweaked measure binding
poiru authored
94 LONGLONG time = (LONGLONG)measure->GetValue();
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
95 m_Value = (double)(time % m_ValueRemainder);
30edc89
Kimmo Pekkola authored
96 m_Value /= (double)m_ValueRemainder;
97 }
98 else
99 {
4bbc372 Birunthan Mohanathas Tweaked measure binding
poiru authored
100 m_Value = measure->GetRelativeValue();
30edc89
Kimmo Pekkola authored
101 }
102 return true;
103 }
104
105 return false;
106 }
107
108
109 /*
110 ** Draws the meter on the double buffer
111 **
112 */
dd9ab1d Added support for transformation matrix in meters.
Kimmo Pekkola authored
113 bool CMeterRoundLine::Draw(Graphics& graphics)
30edc89
Kimmo Pekkola authored
114 {
a92bdd9 Birunthan Mohanathas Cosmetic changes to code.
poiru authored
115 if (!CMeter::Draw(graphics)) return false;
30edc89
Kimmo Pekkola authored
116
117 // Calculate the center of for the line
118 int x = GetX();
119 int y = GetY();
a3572f3 spx Tweaks.
spx268 authored
120 double cx = x + m_W / 2.0;
121 double cy = y + m_H / 2.0;
30edc89
Kimmo Pekkola authored
122
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
123 double lineStart = ((m_CntrlLineStart) ? m_LineStartShift * m_Value : 0) + m_LineStart;
124 double lineLength = ((m_CntrlLineLength) ? m_LineLengthShift * m_Value : 0) + m_LineLength;
125
126 // Calculate the end point of the line
127 double angle = ((m_CntrlAngle) ? m_RotationAngle * m_Value : m_RotationAngle) + m_StartAngle;
a3572f3 spx Tweaks.
spx268 authored
128 double e_cos = cos(angle);
129 double e_sin = sin(angle);
130
131 REAL sx = (REAL)(e_cos * lineStart + cx);
132 REAL sy = (REAL)(e_sin * lineStart + cy);
133 REAL ex = (REAL)(e_cos * lineLength + cx);
134 REAL ey = (REAL)(e_sin * lineLength + cy);
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
135
30edc89
Kimmo Pekkola authored
136 if (m_Solid)
137 {
365206e spx Code cleanup.
spx268 authored
138 REAL startAngle = (REAL)(CONVERT_TO_DEGREES(m_StartAngle));
139 REAL sweepAngle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value));
140
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
141 // Calculate the start point of the line
a3572f3 spx Tweaks.
spx268 authored
142 double s_cos = cos(m_StartAngle);
143 double s_sin = sin(m_StartAngle);
365206e spx Code cleanup.
spx268 authored
144
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
145 //Create a path to surround the arc
146 GraphicsPath path;
147 path.AddArc((REAL)(cx - lineStart), (REAL)(cy - lineStart), (REAL)(lineStart * 2.0), (REAL)(lineStart * 2.0), startAngle, sweepAngle);
a3572f3 spx Tweaks.
spx268 authored
148 path.AddLine((REAL)(lineStart * s_cos + cx), (REAL)(lineStart * s_sin + cy), (REAL)(lineLength * s_cos + cx), (REAL)(lineLength * s_sin + cy));
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
149 path.AddArc((REAL)(cx - lineLength), (REAL)(cy - lineLength), (REAL)(lineLength * 2.0), (REAL)(lineLength * 2.0), startAngle, sweepAngle);
a3572f3 spx Tweaks.
spx268 authored
150 path.AddLine(ex, ey, sx, sy);
9b32f45 spx Fixed an issue that Roundline/"Shift"-parameters not working when Solid=...
spx268 authored
151
152 SolidBrush solidBrush(m_LineColor);
153 graphics.FillPath(&solidBrush, &path);
30edc89
Kimmo Pekkola authored
154 }
155 else
156 {
365206e spx Code cleanup.
spx268 authored
157 Pen pen(m_LineColor, (REAL)m_LineWidth);
a3572f3 spx Tweaks.
spx268 authored
158 graphics.DrawLine(&pen, sx, sy, ex, ey);
30edc89
Kimmo Pekkola authored
159 }
160
161 return true;
162 }
Something went wrong with that request. Please try again.