diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index 2d835cf1..be88e936 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -243,6 +243,24 @@ double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue) return wcstod(result.c_str(), NULL); } +std::vector CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key) +{ + std::vector 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 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 CConfigParser::Tokenize(const std::wstring& str, const std::wstring delimiters) +{ + std::vector 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 ** diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index aa0992b3..f3e849f0 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -22,6 +22,7 @@ #include #include #include +#include #include 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 ReadFloats(LPCTSTR section, LPCTSTR key); std::wstring& GetFilename() { return m_Filename; } private: void ReadVariables(); Gdiplus::Color ParseColor(LPCTSTR string); + std::vector Tokenize(const std::wstring& str, const std::wstring delimiters); std::map m_Variables; std::wstring m_Filename; diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 6d909ffb..a0a306c0 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -258,6 +258,17 @@ void CMeter::ReadConfig(const WCHAR* section) m_UpdateDivider = parser.ReadInt(section, L"UpdateDivider", 1); m_UpdateCounter = m_UpdateDivider; + std::vector 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(); diff --git a/Library/Meter.h b/Library/Meter.h index d0da9120..3f42fae1 100644 --- a/Library/Meter.h +++ b/Library/Meter.h @@ -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& 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 diff --git a/Library/MeterBar.cpp b/Library/MeterBar.cpp index 4571de77..fbf34015 100644 --- a/Library/MeterBar.cpp +++ b/Library/MeterBar.cpp @@ -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); diff --git a/Library/MeterBar.h b/Library/MeterBar.h index e6392273..edcffee5 100644 --- a/Library/MeterBar.h +++ b/Library/MeterBar.h @@ -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 diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index 42aeea58..d7b13137 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -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); } diff --git a/Library/MeterBitmap.h b/Library/MeterBitmap.h index 9343d8a7..31bdaa94 100644 --- a/Library/MeterBitmap.h +++ b/Library/MeterBitmap.h @@ -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: diff --git a/Library/MeterButton.cpp b/Library/MeterButton.cpp index 926277ed..9f42602c 100644 --- a/Library/MeterButton.cpp +++ b/Library/MeterButton.cpp @@ -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 diff --git a/Library/MeterButton.h b/Library/MeterButton.h index 3c2f0d22..abccf417 100644 --- a/Library/MeterButton.h +++ b/Library/MeterButton.h @@ -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& measures); bool MouseMove(POINT pos); diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index 07db0252..672dba1c 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -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); diff --git a/Library/MeterHistogram.h b/Library/MeterHistogram.h index e4b96131..32c92393 100644 --- a/Library/MeterHistogram.h +++ b/Library/MeterHistogram.h @@ -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& measures); private: diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index fd04f358..8c495c1e 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -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(); diff --git a/Library/MeterImage.h b/Library/MeterImage.h index 76835a25..866b5008 100644 --- a/Library/MeterImage.h +++ b/Library/MeterImage.h @@ -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& measures); private: diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index 9063567b..5dfd2ddb 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -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; } diff --git a/Library/MeterLine.h b/Library/MeterLine.h index c7f1f462..6f175d7b 100644 --- a/Library/MeterLine.h +++ b/Library/MeterLine.h @@ -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& measures); private: diff --git a/Library/MeterRotator.cpp b/Library/MeterRotator.cpp index 34d6e315..ee3dff2d 100644 --- a/Library/MeterRotator.cpp +++ b/Library/MeterRotator.cpp @@ -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; } diff --git a/Library/MeterRotator.h b/Library/MeterRotator.h index 88234f9f..229dcda5 100644 --- a/Library/MeterRotator.h +++ b/Library/MeterRotator.h @@ -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 diff --git a/Library/MeterRoundLine.cpp b/Library/MeterRoundLine.cpp index 9ff7431d..ac5fb7c5 100644 --- a/Library/MeterRoundLine.cpp +++ b/Library/MeterRoundLine.cpp @@ -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; } diff --git a/Library/MeterRoundLine.h b/Library/MeterRoundLine.h index c1d457f4..e0708ee2 100644 --- a/Library/MeterRoundLine.h +++ b/Library/MeterRoundLine.h @@ -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 diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 6de7155b..c8118311 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -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; diff --git a/Library/MeterString.h b/Library/MeterString.h index 90933601..a13fd75e 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -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& 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 diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 14d9cc9e..9f261f71 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -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) {