2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Kimmo Pekkola
|
|
|
|
|
|
|
|
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 "MeterRotator.h"
|
|
|
|
#include "Measure.h"
|
|
|
|
#include "Error.h"
|
|
|
|
#include "Litestep.h"
|
|
|
|
#include "Rainmeter.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;
|
|
|
|
|
2011-05-04 18:48:26 +00:00
|
|
|
#define PI (3.14159265358979323846)
|
|
|
|
#define CONVERT_TO_DEGREES(X) ((X) * (180.0 / PI))
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
extern Rainmeter* g_Rainmeter;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterRotator::MeterRotator(MeterWindow* meterWindow, const WCHAR* name) : Meter(meterWindow, name),
|
2013-06-07 19:35:36 +00:00
|
|
|
m_Image(L"ImageName", nullptr, false, meterWindow),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_NeedsReload(false),
|
|
|
|
m_OffsetX(),
|
|
|
|
m_OffsetY(),
|
|
|
|
m_StartAngle(),
|
|
|
|
m_RotationAngle(6.2832),
|
|
|
|
m_ValueRemainder(),
|
|
|
|
m_Value()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
MeterRotator::~MeterRotator()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-06-01 13:06:36 +00:00
|
|
|
** Load the image.
|
2009-02-10 18:37:48 +00:00
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
void MeterRotator::Initialize()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
Meter::Initialize();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Load the bitmaps if defined
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!m_ImageName.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_Image.LoadImage(m_ImageName, m_NeedsReload);
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
2010-11-27 19:53:23 +00:00
|
|
|
else if (m_Image.IsLoaded())
|
2010-06-03 14:14:53 +00:00
|
|
|
{
|
2010-11-27 19:53:23 +00:00
|
|
|
m_Image.DisposeImage();
|
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 MeterRotator::ReadOptions(ConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-09-07 20:00:50 +00:00
|
|
|
// Store the current values so we know if the image needs to be updated
|
|
|
|
std::wstring oldImageName = m_ImageName;
|
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
Meter::ReadOptions(parser, section);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_ImageName = parser.ReadString(section, L"ImageName", L"");
|
2010-11-25 22:00:34 +00:00
|
|
|
if (!m_ImageName.empty())
|
|
|
|
{
|
2012-06-01 13:06:36 +00:00
|
|
|
// Read tinting options
|
2012-05-30 18:53:44 +00:00
|
|
|
m_Image.ReadOptions(parser, section);
|
2010-11-27 19:53:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-30 18:51:06 +00:00
|
|
|
m_Image.ClearOptionFlags();
|
2010-11-25 22:00:34 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0);
|
|
|
|
m_OffsetY = parser.ReadFloat(section, L"OffsetY", 0.0);
|
2012-04-06 12:16:54 +00:00
|
|
|
m_StartAngle = parser.ReadFloat(section, L"StartAngle", 0.0);
|
|
|
|
m_RotationAngle = parser.ReadFloat(section, L"RotationAngle", 6.2832);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
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);
|
2009-09-07 20:00:50 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (m_Initialized)
|
2009-09-07 20:00:50 +00:00
|
|
|
{
|
2011-11-27 08:30:39 +00:00
|
|
|
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
if (m_NeedsReload ||
|
2012-05-30 18:51:06 +00:00
|
|
|
m_Image.IsOptionsChanged())
|
2010-11-27 19:53:23 +00:00
|
|
|
{
|
|
|
|
Initialize(); // Reload the image
|
|
|
|
}
|
2009-09-07 20:00:50 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
2013-05-31 14:18:52 +00:00
|
|
|
bool MeterRotator::Update()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2013-05-31 14:18:52 +00:00
|
|
|
if (Meter::Update() && !m_Measures.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
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-05-04 18:48:26 +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 MeterRotator::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
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
if (m_Image.IsLoaded())
|
|
|
|
{
|
|
|
|
// Calculate the center for rotation
|
|
|
|
int x = GetX();
|
|
|
|
int y = GetY();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
REAL cx = (REAL)(x + m_W / 2.0);
|
|
|
|
REAL cy = (REAL)(y + m_H / 2.0);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
// Calculate the rotation
|
2011-05-04 18:48:26 +00:00
|
|
|
REAL angle = (REAL)(CONVERT_TO_DEGREES(m_RotationAngle * m_Value + m_StartAngle));
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-04-05 08:35:20 +00:00
|
|
|
// TODO: convert to Canvas: canvas.RotateTransform(angle, cx, cy, (REAL)-m_OffsetX, (REAL)-m_OffsetY);
|
2010-11-27 19:53:23 +00:00
|
|
|
graphics.TranslateTransform(cx, cy);
|
|
|
|
graphics.RotateTransform(angle);
|
|
|
|
graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-27 19:53:23 +00:00
|
|
|
Bitmap* drawBitmap = m_Image.GetImage();
|
2010-10-17 17:51:14 +00:00
|
|
|
|
|
|
|
UINT width = drawBitmap->GetWidth();
|
|
|
|
UINT height = drawBitmap->GetHeight();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Blit the image
|
2010-10-17 17:51:14 +00:00
|
|
|
graphics.DrawImage(drawBitmap, 0, 0, width, height);
|
2010-11-27 19:53:23 +00:00
|
|
|
|
|
|
|
graphics.ResetTransform();
|
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;
|
|
|
|
}
|