rainmeter-studio/Library/MeterRoundLine.cpp

196 lines
5.9 KiB
C++
Raw Normal View History

2009-02-10 18:37:48 +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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "StdAfx.h"
2009-02-10 18:37:48 +00:00
#include "MeterRoundLine.h"
#include "Measure.h"
#include "Error.h"
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
/*
** CMeterRoundLine
**
** The constructor
**
*/
2011-02-15 16:26:54 +00:00
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()
2009-02-10 18:37:48 +00:00
{
}
/*
** ~CMeterRoundLine
**
** The destructor
**
*/
CMeterRoundLine::~CMeterRoundLine()
{
}
/*
** ReadConfig
**
** Read the meter-specific configs from the ini-file.
**
*/
2011-02-15 16:26:54 +00:00
void CMeterRoundLine::ReadConfig(CConfigParser& parser, const WCHAR* section)
2009-02-10 18:37:48 +00:00
{
// Read common configs
2011-02-15 16:26:54 +00:00
CMeter::ReadConfig(parser, section);
2009-02-10 18:37:48 +00:00
2009-09-04 16:37:51 +00:00
m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
m_LineLength = parser.ReadFloat(section, L"LineLength", 20.0);
2011-03-29 19:21:57 +00:00
m_LineStart = parser.ReadFormula(section, L"LineStart", -1.0);
2009-09-04 16:37:51 +00:00
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);
2009-02-10 18:37:48 +00:00
}
/*
** Update
**
** Updates the value(s) from the measures.
**
*/
bool CMeterRoundLine::Update()
{
if (CMeter::Update() && m_Measure)
{
if (m_ValueRemainder > 0)
{
LARGE_INTEGER time;
2009-02-14 10:11:28 +00:00
time.QuadPart = (LONGLONG)m_Measure->GetValue();
m_Value = (double)(time.QuadPart % m_ValueRemainder);
2009-02-10 18:37:48 +00:00
m_Value /= (double)m_ValueRemainder;
}
else
{
m_Value = m_Measure->GetRelativeValue();
}
return true;
}
return false;
}
/*
** Draw
**
** Draws the meter on the double buffer
**
*/
bool CMeterRoundLine::Draw(Graphics& graphics)
2009-02-10 18:37:48 +00:00
{
2011-03-29 19:21:57 +00:00
if (!CMeter::Draw(graphics)) return false;
2009-02-10 18:37:48 +00:00
// Calculate the center of for the line
int x = GetX();
int y = GetY();
REAL cx = (REAL)(x + m_W / 2.0);
REAL cy = (REAL)(y + m_H / 2.0);
if (m_Solid)
{
2010-12-28 19:43:19 +00:00
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)
2009-02-10 18:37:48 +00:00
{
// Create clipping region
//GraphicsPath path;
//path.AddEllipse(REAL(cx - m_LineStart), REAL(cy - m_LineStart), REAL(m_LineStart * 2), REAL(m_LineStart * 2));
//graphics.SetClip(&path, CombineModeExclude);
// Calculate the end point of the line
//double angle = m_RotationAngle * m_Value + m_StartAngle;
2010-12-28 19:43:19 +00:00
double angle = (m_CntrlAngle) ? m_RotationAngle * m_Value + m_StartAngle : m_RotationAngle + m_StartAngle;
double lineStart = (m_CntrlLineStart) ? m_LineStartShift * m_Value + m_LineStart : m_LineStart;
double lineLength = (m_CntrlLineLength) ? m_LineLengthShift * m_Value + m_LineLength : m_LineLength;
REAL s_cos = (REAL)cos(m_StartAngle);
REAL s_sin = (REAL)sin(m_StartAngle);
REAL e_cos = (REAL)cos(angle);
REAL e_sin = (REAL)sin(angle);
2011-03-29 19:21:57 +00:00
//Create a path to surround the arc
GraphicsPath path;
2010-12-28 19:43:19 +00:00
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((REAL)lineLength * e_cos + cx, (REAL)lineLength * e_sin + cy, (REAL)lineStart * e_cos + cx, (REAL)lineStart * e_sin + cy);
2011-03-29 19:21:57 +00:00
2010-12-28 19:43:19 +00:00
graphics.FillPath(&solidBrush, &path);
}
else
{
// Calculate the center of for the line
2010-12-28 19:43:19 +00:00
graphics.FillPie(&solidBrush, (REAL)(cx - m_LineLength), (REAL)(cy - m_LineLength), (REAL)(m_LineLength * 2.0), (REAL)(m_LineLength * 2.0), startAngle, sweepAngle);
2009-02-10 18:37:48 +00:00
}
}
else
{
// Calculate the end point of the line
double angle = m_RotationAngle * m_Value + m_StartAngle;
2010-12-28 19:43:19 +00:00
REAL e_cos = (REAL)cos(angle);
REAL e_sin = (REAL)sin(angle);
2009-02-10 18:37:48 +00:00
// Set the length
2010-12-28 19:43:19 +00:00
REAL x = e_cos * (REAL)m_LineLength + cx;
REAL y = e_sin * (REAL)m_LineLength + cy;
2009-02-10 18:37:48 +00:00
if (m_LineStart > 0.0)
{
2010-12-28 19:43:19 +00:00
cx += e_cos * (REAL)m_LineStart;
cy += e_sin * (REAL)m_LineStart;
2009-02-10 18:37:48 +00:00
}
2010-12-28 19:43:19 +00:00
Pen pen(m_LineColor, (REAL)m_LineWidth);
2009-02-10 18:37:48 +00:00
graphics.DrawLine(&pen, cx, cy, x, y);
}
return true;
}