mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
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.
This commit is contained in:
parent
920268395d
commit
7440667743
@ -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];
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gdiplus.h>
|
||||
#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<Gdiplus::REAL> ReadFloats(LPCTSTR section, LPCTSTR key);
|
||||
@ -50,6 +52,8 @@ private:
|
||||
|
||||
std::map<std::wstring, std::wstring> m_Variables;
|
||||
std::wstring m_Filename;
|
||||
|
||||
hqMathParser* m_Parser;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
Universal lexical analiser by hq_software
|
||||
*/
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
Math parser for CCalc library.
|
||||
*/
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "pack.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#pragma warning(disable: 4996)
|
||||
|
||||
#include <windows.h>
|
||||
//#include <atlbase.h>
|
||||
#include <comdef.h>
|
||||
#include "iTunesCOMInterface.h"
|
||||
#include "..\..\Library\Export.h" // Rainmeter's exported functions
|
||||
|
Loading…
Reference in New Issue
Block a user