From 7440667743bf24c0096752ebd9460f652e455e92 Mon Sep 17 00:00:00 2001 From: Kimmo Pekkola Date: Thu, 30 Jul 2009 15:19:47 +0000 Subject: [PATCH] New build-in variables: #WORKAREAWIDTH#, #WORKAREAHEIGHT#, #SCREENAREAWIDTH#, #SCREENAREAHEIGHT# Added support for math formulas for the X, Y, W, H, WindowX and WindowY (e.g. "WindowX=(#WORKAREAWIDTH# / 2)"). The formula must be surrounded by parenthesis. --- Library/ConfigParser.cpp | 37 ++++++++++++++++++++++++++- Library/ConfigParser.h | 4 +++ Library/Meter.cpp | 12 +++++++-- Library/MeterWindow.cpp | 16 ++++++++++++ Library/ccalc-0.5.1/lexer.h | 2 ++ Library/ccalc-0.5.1/mparser.h | 2 ++ Library/ccalc-0.5.1/strmap.h | 2 ++ Plugins/PluginiTunes/iTunesPlugin.cpp | 1 - 8 files changed, 72 insertions(+), 4 deletions(-) diff --git a/Library/ConfigParser.cpp b/Library/ConfigParser.cpp index be88e936..3f420e22 100644 --- a/Library/ConfigParser.cpp +++ b/Library/ConfigParser.cpp @@ -36,6 +36,7 @@ using namespace Gdiplus; */ CConfigParser::CConfigParser() { + m_Parser = MathParser_Create(NULL); } /* @@ -46,6 +47,7 @@ CConfigParser::CConfigParser() */ CConfigParser::~CConfigParser() { + MathParser_Destroy(m_Parser); } /* @@ -59,7 +61,7 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter) m_Variables.clear(); - // Set the paths as default variables + // Set the default variables if (pRainmeter) { m_Variables[L"PROGRAMPATH"] = pRainmeter->GetPath(); @@ -68,6 +70,16 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter) m_Variables[L"PLUGINSPATH"] = pRainmeter->GetPluginPath(); m_Variables[L"CURRENTPATH"] = CRainmeter::ExtractPath(filename); m_Variables[L"ADDONSPATH"] = pRainmeter->GetPath() + L"Addons\\"; + + TCHAR buffer[256]; + swprintf(buffer, L"%i", GetSystemMetrics(SM_CXFULLSCREEN)); + m_Variables[L"WORKAREAWIDTH"] = buffer; + swprintf(buffer, L"%i", GetSystemMetrics(SM_CYFULLSCREEN)); + m_Variables[L"WORKAREAHEIGHT"] = buffer; + swprintf(buffer, L"%i", GetSystemMetrics(SM_CXSCREEN)); + m_Variables[L"SCREENAREAWIDTH"] = buffer; + swprintf(buffer, L"%i", GetSystemMetrics(SM_CYSCREEN)); + m_Variables[L"SCREENAREAHEIGHT"] = buffer; } ReadVariables(); @@ -271,6 +283,29 @@ int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue) return _wtoi(result.c_str()); } +// Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula +double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) +{ + TCHAR buffer[256]; + swprintf(buffer, L"%f", defValue); + + const std::wstring& result = ReadString(section, key, buffer); + + // Formulas must be surrounded by parenthesis + if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') + { + double resultValue = defValue; + char* errMsg = MathParser_Parse(m_Parser, ConvertToAscii(result.substr(1, result.size() - 2).c_str()).c_str(), &resultValue); + if (errMsg != NULL) + { + DebugLog(ConvertToWide(errMsg).c_str()); + } + + return resultValue; + } + return wcstod(result.c_str(), NULL); +} + Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, Color defValue) { TCHAR buffer[256]; diff --git a/Library/ConfigParser.h b/Library/ConfigParser.h index f3e849f0..3c5788d5 100644 --- a/Library/ConfigParser.h +++ b/Library/ConfigParser.h @@ -24,6 +24,7 @@ #include #include #include +#include "ccalc-0.5.1/mparser.h" class CRainmeter; @@ -37,6 +38,7 @@ public: const std::wstring& ReadString(LPCTSTR section, LPCTSTR key, LPCTSTR defValue); double ReadFloat(LPCTSTR section, LPCTSTR key, double defValue); + double ReadFormula(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); @@ -50,6 +52,8 @@ private: std::map m_Variables; std::wstring m_Filename; + + hqMathParser* m_Parser; }; #endif diff --git a/Library/Meter.cpp b/Library/Meter.cpp index ab7dca3e..2887200b 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -221,6 +221,10 @@ void CMeter::ReadConfig(const WCHAR* section) { m_RelativeX = POSITION_RELATIVE_BR; } + else + { + m_X = (int)parser.ReadFormula(section, L"X", 0.0); + } } const std::wstring& y = parser.ReadString(section, L"Y", L"0"); @@ -235,10 +239,14 @@ void CMeter::ReadConfig(const WCHAR* section) { m_RelativeY = POSITION_RELATIVE_BR; } + else + { + m_Y = (int)parser.ReadFormula(section, L"Y", 0.0); + } } - m_W = parser.ReadInt(section, L"W", 1); - m_H = parser.ReadInt(section, L"H", 1); + m_W = (int)parser.ReadFormula(section, L"W", 1.0); + m_H = (int)parser.ReadFormula(section, L"H", 1.0); m_Hidden = 0!=parser.ReadInt(section, L"Hidden", 0); m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", m_SolidBevel); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index d7477dbc..b3761c2f 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -1176,6 +1176,22 @@ void CMeterWindow::ReadConfig() m_WindowY = ConvertToWide(tmpSz); } + // Check if the window position should be read as a formula + if (!m_WindowX.empty() && m_WindowX[0] == L'(' && m_WindowX[m_WindowX.size() - 1] == L')') + { + double value = parser.ReadFormula(section, _T("WindowX"), 0.0); + TCHAR buffer[256]; + swprintf(buffer, L"%i", (int)value); + m_WindowX = buffer; + } + if (!m_WindowY.empty() && m_WindowY[0] == L'(' && m_WindowY[m_WindowY.size() - 1] == L')') + { + double value = parser.ReadFormula(section, _T("WindowY"), 0.0); + TCHAR buffer[256]; + swprintf(buffer, L"%i", (int)value); + m_WindowY = buffer; + } + int zPos = parser.ReadInt(section, L"AlwaysOnTop", m_WindowZPosition); if (zPos == -1) { diff --git a/Library/ccalc-0.5.1/lexer.h b/Library/ccalc-0.5.1/lexer.h index 1e4acf70..a4ffee38 100644 --- a/Library/ccalc-0.5.1/lexer.h +++ b/Library/ccalc-0.5.1/lexer.h @@ -1,3 +1,5 @@ +#pragma once + /* Universal lexical analiser by hq_software */ diff --git a/Library/ccalc-0.5.1/mparser.h b/Library/ccalc-0.5.1/mparser.h index 1bc2d8a6..360d8b31 100644 --- a/Library/ccalc-0.5.1/mparser.h +++ b/Library/ccalc-0.5.1/mparser.h @@ -1,3 +1,5 @@ +#pragma once + /* Math parser for CCalc library. */ diff --git a/Library/ccalc-0.5.1/strmap.h b/Library/ccalc-0.5.1/strmap.h index 6c834d46..23ae4ca5 100644 --- a/Library/ccalc-0.5.1/strmap.h +++ b/Library/ccalc-0.5.1/strmap.h @@ -1,3 +1,5 @@ +#pragma once + #include "pack.h" #ifdef __cplusplus diff --git a/Plugins/PluginiTunes/iTunesPlugin.cpp b/Plugins/PluginiTunes/iTunesPlugin.cpp index 63440c24..58b477c2 100644 --- a/Plugins/PluginiTunes/iTunesPlugin.cpp +++ b/Plugins/PluginiTunes/iTunesPlugin.cpp @@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning(disable: 4996) #include -//#include #include #include "iTunesCOMInterface.h" #include "..\..\Library\Export.h" // Rainmeter's exported functions