mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added support for transformation matrix in meters.
This commit is contained in:
parent
bded6e6fc7
commit
dd9ab1dc04
@ -243,6 +243,24 @@ double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
|
||||
return wcstod(result.c_str(), NULL);
|
||||
}
|
||||
|
||||
std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key)
|
||||
{
|
||||
std::vector<Gdiplus::REAL> result;
|
||||
std::wstring tmp = ReadString(section, key, L"");
|
||||
if (!tmp.empty() && tmp[tmp.length() - 1] != L';')
|
||||
{
|
||||
tmp += L";";
|
||||
}
|
||||
|
||||
// Tokenize and parse the floats
|
||||
std::vector<std::wstring> tokens = Tokenize(tmp, L";");
|
||||
for (size_t i = 0; i < tokens.size(); i++)
|
||||
{
|
||||
result.push_back((Gdiplus::REAL)wcstod(tokens[i].c_str(), NULL));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue)
|
||||
{
|
||||
TCHAR buffer[256];
|
||||
@ -263,6 +281,30 @@ Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, Color defValue)
|
||||
return ParseColor(result.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
** Tokenize
|
||||
**
|
||||
** Splits the string from the delimiters
|
||||
**
|
||||
** http://www.digitalpeer.com/id/simple
|
||||
*/
|
||||
std::vector<std::wstring> CConfigParser::Tokenize(const std::wstring& str, const std::wstring delimiters)
|
||||
{
|
||||
std::vector<std::wstring> tokens;
|
||||
|
||||
std::wstring::size_type lastPos = str.find_first_not_of(L";", 0); // skip delimiters at beginning.
|
||||
std::wstring::size_type pos = str.find_first_of(delimiters, lastPos); // find first "non-delimiter".
|
||||
|
||||
while (std::wstring::npos != pos || std::wstring::npos != lastPos)
|
||||
{
|
||||
tokens.push_back(str.substr(lastPos, pos - lastPos)); // found a token, add it to the vector.
|
||||
lastPos = str.find_first_not_of(delimiters, pos); // skip delimiters. Note the "not_of"
|
||||
pos = str.find_first_of(delimiters, lastPos); // find next "non-delimiter"
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/*
|
||||
** ParseColor
|
||||
**
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <windows.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gdiplus.h>
|
||||
|
||||
class CRainmeter;
|
||||
@ -38,12 +39,14 @@ public:
|
||||
double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue);
|
||||
int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
|
||||
Gdiplus::Color ReadColor(LPCTSTR section, LPCTSTR key, Gdiplus::Color defValue);
|
||||
std::vector<Gdiplus::REAL> ReadFloats(LPCTSTR section, LPCTSTR key);
|
||||
|
||||
std::wstring& GetFilename() { return m_Filename; }
|
||||
|
||||
private:
|
||||
void ReadVariables();
|
||||
Gdiplus::Color ParseColor(LPCTSTR string);
|
||||
std::vector<std::wstring> Tokenize(const std::wstring& str, const std::wstring delimiters);
|
||||
|
||||
std::map<std::wstring, std::wstring> m_Variables;
|
||||
std::wstring m_Filename;
|
||||
|
@ -258,6 +258,17 @@ void CMeter::ReadConfig(const WCHAR* section)
|
||||
m_UpdateDivider = parser.ReadInt(section, L"UpdateDivider", 1);
|
||||
m_UpdateCounter = m_UpdateDivider;
|
||||
|
||||
std::vector<Gdiplus::REAL> matrix = parser.ReadFloats(section, L"TransformationMatrix");
|
||||
if (matrix.size() == 6)
|
||||
{
|
||||
m_Transformation.SetElements(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
|
||||
}
|
||||
else if (!matrix.empty())
|
||||
{
|
||||
DebugLog(L"The transformation matrix has incorrect number of values:", parser.ReadString(section, L"TransformationMatrix", L"").c_str());
|
||||
}
|
||||
|
||||
|
||||
if (m_W == 0 || m_H == 0)
|
||||
{
|
||||
throw CError(std::wstring(L"The meter ") + section + L" has zero dimensions.", __LINE__, __FILE__);
|
||||
@ -367,14 +378,12 @@ bool CMeter::Update()
|
||||
**
|
||||
** Draws the solid background & bevel if such are defined
|
||||
*/
|
||||
bool CMeter::Draw()
|
||||
bool CMeter::Draw(Graphics& graphics)
|
||||
{
|
||||
if (IsHidden()) return false;
|
||||
|
||||
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
|
||||
{
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
int x = GetX();
|
||||
int y = GetY();
|
||||
|
||||
@ -393,8 +402,6 @@ bool CMeter::Draw()
|
||||
|
||||
if (m_SolidBevel != BEVELTYPE_NONE)
|
||||
{
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
int x = GetX();
|
||||
int y = GetY();
|
||||
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual bool HasActiveTransition() { return false; }
|
||||
|
||||
@ -59,6 +59,8 @@ public:
|
||||
void Show() { m_Hidden = false; };
|
||||
bool IsHidden() { return m_Hidden; };
|
||||
|
||||
const Gdiplus::Matrix& GetTransformationMatrix() { return m_Transformation; }
|
||||
|
||||
virtual bool HitTest(int x, int y);
|
||||
|
||||
void SetMouseOver(bool over) { m_MouseOver = over; }
|
||||
@ -88,6 +90,7 @@ protected:
|
||||
POSITION_RELATIVE_BR
|
||||
};
|
||||
|
||||
Gdiplus::Matrix m_Transformation; // The transformation matrix
|
||||
std::wstring m_Name; // Name of the meter
|
||||
std::wstring m_MeasureName; // Name of the measure this is bound to
|
||||
CMeasure* m_Measure; // Pointer to the measure this meter is bound to
|
||||
|
@ -142,15 +142,13 @@ bool CMeterBar::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterBar::Draw()
|
||||
bool CMeterBar::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
int x = GetX();
|
||||
int y = GetY();
|
||||
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
if(m_Orientation == VERTICAL)
|
||||
{
|
||||
int size = (int)((m_H - 2 * m_Border) * m_Value);
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
|
||||
private:
|
||||
enum ORIENTATION
|
||||
|
@ -263,9 +263,9 @@ bool CMeterBitmap::HasActiveTransition()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterBitmap::Draw()
|
||||
bool CMeterBitmap::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
int newY, newX;
|
||||
|
||||
@ -309,8 +309,6 @@ bool CMeterBitmap::Draw()
|
||||
|
||||
// Blit the images
|
||||
int offset;
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
if (m_Align == ALIGN_RIGHT)
|
||||
{
|
||||
offset = 0;
|
||||
@ -435,7 +433,6 @@ bool CMeterBitmap::Draw()
|
||||
}
|
||||
|
||||
// Blit the image
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
Rect r(x, y, m_W, m_H);
|
||||
graphics.DrawImage(m_Bitmap, r, newX, newY, m_W, m_H, UnitPixel);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual bool HasActiveTransition();
|
||||
|
||||
private:
|
||||
|
@ -158,9 +158,9 @@ bool CMeterButton::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterButton::Draw()
|
||||
bool CMeterButton::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
if (m_Bitmaps[m_State] == NULL) return false; // Unable to continue
|
||||
|
||||
@ -168,7 +168,6 @@ bool CMeterButton::Draw()
|
||||
int y = GetY();
|
||||
|
||||
// Blit the image
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
graphics.DrawCachedBitmap(m_Bitmaps[m_State], x, y);
|
||||
|
||||
// TEST
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
|
||||
bool MouseMove(POINT pos);
|
||||
|
@ -237,11 +237,10 @@ bool CMeterHistogram::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterHistogram::Draw()
|
||||
bool CMeterHistogram::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
Pen primaryPen(m_PrimaryColor);
|
||||
Pen secondaryPen(m_SecondaryColor);
|
||||
Pen bothPen(m_BothColor);
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
|
@ -231,14 +231,12 @@ bool CMeterImage::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterImage::Draw()
|
||||
bool CMeterImage::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
if (m_Bitmap != NULL)
|
||||
{
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
// Copy the image over the doublebuffer
|
||||
int x = GetX();
|
||||
int y = GetY();
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
|
@ -186,9 +186,9 @@ bool CMeterLine::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterLine::Draw()
|
||||
bool CMeterLine::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
double maxValue = 0.0;
|
||||
int counter = 0;
|
||||
@ -235,7 +235,7 @@ bool CMeterLine::Draw()
|
||||
maxValue = 1.0;
|
||||
}
|
||||
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer()); //GDI+
|
||||
SmoothingMode mode = graphics.GetSmoothingMode();
|
||||
if (m_AntiAlias)
|
||||
{
|
||||
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
|
||||
@ -321,6 +321,11 @@ bool CMeterLine::Draw()
|
||||
counter++;
|
||||
}
|
||||
|
||||
if (m_AntiAlias)
|
||||
{
|
||||
graphics.SetSmoothingMode(mode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
|
@ -132,9 +132,9 @@ bool CMeterRotator::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterRotator::Draw()
|
||||
bool CMeterRotator::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
// Calculate the center for rotation
|
||||
int x = GetX();
|
||||
@ -146,8 +146,6 @@ bool CMeterRotator::Draw()
|
||||
// Calculate the rotation
|
||||
REAL angle = (REAL)(m_RotationAngle * m_Value + m_StartAngle);
|
||||
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
|
||||
angle = angle * 180.0f / 3.14159265f; // Convert to degrees
|
||||
|
||||
graphics.TranslateTransform(cx, cy);
|
||||
@ -162,6 +160,7 @@ bool CMeterRotator::Draw()
|
||||
// Blit the image
|
||||
graphics.DrawImage(m_Bitmap, 0, 0, width, height);
|
||||
}
|
||||
graphics.ResetTransform();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
|
||||
private:
|
||||
Gdiplus::Bitmap* m_Bitmap; // The bar bitmap
|
||||
|
@ -126,11 +126,11 @@ bool CMeterRoundLine::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterRoundLine::Draw()
|
||||
bool CMeterRoundLine::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer()); //GDI+
|
||||
SmoothingMode mode = graphics.GetSmoothingMode();
|
||||
if (m_AntiAlias)
|
||||
{
|
||||
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
|
||||
@ -213,5 +213,10 @@ bool CMeterRoundLine::Draw()
|
||||
graphics.DrawLine(&pen, cx, cy, x, y);
|
||||
}
|
||||
|
||||
if (m_AntiAlias)
|
||||
{
|
||||
graphics.SetSmoothingMode(mode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
|
||||
private:
|
||||
bool m_AntiAlias; // If true, the line is antialiased
|
||||
|
@ -331,7 +331,8 @@ bool CMeterString::Update()
|
||||
{
|
||||
// Calculate the text size
|
||||
RectF rect;
|
||||
DrawString(&rect);
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
DrawString(graphics, &rect);
|
||||
m_W = (int)rect.Width;
|
||||
m_H = (int)rect.Height;
|
||||
}
|
||||
@ -347,11 +348,11 @@ bool CMeterString::Update()
|
||||
** Draws the meter on the double buffer
|
||||
**
|
||||
*/
|
||||
bool CMeterString::Draw()
|
||||
bool CMeterString::Draw(Graphics& graphics)
|
||||
{
|
||||
if(!CMeter::Draw()) return false;
|
||||
if(!CMeter::Draw(graphics)) return false;
|
||||
|
||||
return DrawString(NULL);
|
||||
return DrawString(graphics, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -360,9 +361,8 @@ bool CMeterString::Draw()
|
||||
** Draws the string or calculates it's size
|
||||
**
|
||||
*/
|
||||
bool CMeterString::DrawString(RectF* rect)
|
||||
bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
|
||||
{
|
||||
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
||||
StringFormat stringFormat;
|
||||
|
||||
if (m_AntiAlias)
|
||||
@ -418,6 +418,8 @@ bool CMeterString::DrawString(RectF* rect)
|
||||
graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y);
|
||||
|
||||
graphics.DrawString(m_String.c_str(), -1, m_Font, rc, &stringFormat, &solidBrush);
|
||||
|
||||
graphics.ResetTransform();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
virtual void ReadConfig(const WCHAR* section);
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
@ -49,7 +49,7 @@ private:
|
||||
BOLDITALIC
|
||||
};
|
||||
|
||||
bool DrawString(Gdiplus::RectF* rect);
|
||||
bool DrawString(Gdiplus::Graphics& graphics, Gdiplus::RectF* rect);
|
||||
|
||||
Gdiplus::Color m_Color; // The color of the text
|
||||
std::wstring m_Postfix; // The postfix of the text
|
||||
|
@ -1745,10 +1745,11 @@ void CMeterWindow::Redraw()
|
||||
CreateRegion(true);
|
||||
}
|
||||
|
||||
Graphics graphics(GetDoubleBuffer());
|
||||
|
||||
if (m_Background)
|
||||
{
|
||||
// Copy the background over the doublebuffer
|
||||
Graphics graphics(GetDoubleBuffer());
|
||||
Rect r(0, 0, m_WindowW, m_WindowH);
|
||||
graphics.DrawImage(m_Background, r, 0, 0, m_Background->GetWidth(), m_Background->GetHeight(), UnitPixel);
|
||||
}
|
||||
@ -1759,7 +1760,20 @@ void CMeterWindow::Redraw()
|
||||
{
|
||||
try
|
||||
{
|
||||
(*j)->Draw();
|
||||
if (!(*j)->GetTransformationMatrix().IsIdentity())
|
||||
{
|
||||
// Change the world matrix
|
||||
graphics.SetTransform(&((*j)->GetTransformationMatrix()));
|
||||
|
||||
(*j)->Draw(graphics);
|
||||
|
||||
// Set back to identity matrix
|
||||
graphics.ResetTransform();
|
||||
}
|
||||
else
|
||||
{
|
||||
(*j)->Draw(graphics);
|
||||
}
|
||||
}
|
||||
catch (CError& error)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user