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
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
using namespace Gdiplus;
|
|
|
|
|
|
|
|
extern CRainmeter* Rainmeter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** CMeterRotator
|
|
|
|
**
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2010-11-11 20:24:59 +00:00
|
|
|
CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeterImage(meterWindow, L"ImageW", L"ImageH")
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Value = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ~CMeterRotator
|
|
|
|
**
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeterRotator::~CMeterRotator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Initialize
|
|
|
|
**
|
|
|
|
** Load the image & configs.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterRotator::Initialize()
|
|
|
|
{
|
|
|
|
CMeter::Initialize();
|
|
|
|
|
|
|
|
// Load the bitmaps if defined
|
|
|
|
if(!m_ImageName.empty())
|
|
|
|
{
|
2010-10-17 17:51:14 +00:00
|
|
|
// Since loading the image redefines the width of the meter we must
|
|
|
|
// store the width and height that were defined.
|
|
|
|
int Height, Width;
|
|
|
|
Height = m_H;
|
|
|
|
Width = m_W;
|
2010-06-03 14:14:53 +00:00
|
|
|
|
2010-10-17 17:51:14 +00:00
|
|
|
LoadImage(false);
|
|
|
|
|
|
|
|
m_W = Width;
|
|
|
|
m_H = Height;
|
2010-06-03 14:14:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_Bitmap)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-09-07 20:00:50 +00:00
|
|
|
delete m_Bitmap;
|
|
|
|
m_Bitmap = NULL;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ReadConfig
|
|
|
|
**
|
|
|
|
** Read the meter-specific configs from the ini-file.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterRotator::ReadConfig(const WCHAR* section)
|
|
|
|
{
|
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;
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
// Read common configs
|
2010-10-17 17:51:14 +00:00
|
|
|
CMeterImage::ReadConfig(section);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
CConfigParser& parser = m_MeterWindow->GetParser();
|
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_ImageName = parser.ReadString(section, L"ImageName", L"");
|
2009-07-24 07:56:37 +00:00
|
|
|
m_ImageName = m_MeterWindow->MakePathAbsolute(m_ImageName);
|
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);
|
|
|
|
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-10-18 22:30:45 +00:00
|
|
|
if (m_Initialized && oldImageName != m_ImageName || m_NeedsTinting || m_NeedsTransform)
|
2009-09-07 20:00:50 +00:00
|
|
|
{
|
|
|
|
Initialize(); // Reload the image
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Update
|
|
|
|
**
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CMeterRotator::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
|
|
|
|
**
|
|
|
|
*/
|
2009-07-27 11:48:57 +00:00
|
|
|
bool CMeterRotator::Draw(Graphics& graphics)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-07-27 11:48:57 +00:00
|
|
|
if(!CMeter::Draw(graphics)) return false;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Calculate the center for rotation
|
|
|
|
int x = GetX();
|
|
|
|
int y = GetY();
|
|
|
|
|
|
|
|
REAL cx = (REAL)(x + m_W / 2.0);
|
|
|
|
REAL cy = (REAL)(y + m_H / 2.0);
|
|
|
|
|
|
|
|
// Calculate the rotation
|
|
|
|
REAL angle = (REAL)(m_RotationAngle * m_Value + m_StartAngle);
|
|
|
|
|
|
|
|
angle = angle * 180.0f / 3.14159265f; // Convert to degrees
|
|
|
|
|
|
|
|
graphics.TranslateTransform(cx, cy);
|
|
|
|
graphics.RotateTransform(angle);
|
|
|
|
graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY);
|
|
|
|
|
2010-10-17 17:51:14 +00:00
|
|
|
Bitmap* drawBitmap = (m_BitmapTint) ? m_BitmapTint : m_Bitmap;
|
|
|
|
|
|
|
|
if(drawBitmap)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
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);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2009-07-27 11:48:57 +00:00
|
|
|
graphics.ResetTransform();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|