mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
- Code cleanup.
- MeterLine: Small performance improvement on Draw().
This commit is contained in:
parent
8144592ec4
commit
45e33ce704
@ -446,7 +446,7 @@ void CMeter::ReadConfig(const WCHAR* section)
|
||||
** several meters but one meter and only be bound to one measure.
|
||||
**
|
||||
*/
|
||||
void CMeter::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeter::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
// The meter is not bound to anything
|
||||
if (m_MeasureName.empty())
|
||||
@ -554,7 +554,7 @@ void CMeter::SetAllMeasures(CMeasure* measure)
|
||||
**
|
||||
** Creates a vector containing all the defined measures (for Line/String)
|
||||
*/
|
||||
void CMeter::SetAllMeasures(std::vector<CMeasure*> measures)
|
||||
void CMeter::SetAllMeasures(const std::vector<CMeasure*>& measures)
|
||||
{
|
||||
m_AllMeasures.clear();
|
||||
m_AllMeasures.push_back(m_Measure);
|
||||
@ -571,11 +571,40 @@ void CMeter::SetAllMeasures(std::vector<CMeasure*> measures)
|
||||
**
|
||||
** Replaces %1, %2 etc with the corresponding measure value
|
||||
*/
|
||||
std::wstring CMeter::ReplaceMeasures(std::wstring source)
|
||||
void CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str)
|
||||
{
|
||||
WCHAR buffer[64];
|
||||
|
||||
// Create the actual text (i.e. replace %1, %2, .. with the measure texts)
|
||||
for (size_t i = stringValues.size(); i > 0; --i)
|
||||
{
|
||||
wsprintf(buffer, L"%%%i", i);
|
||||
|
||||
size_t start = 0;
|
||||
size_t pos = std::wstring::npos;
|
||||
|
||||
do
|
||||
{
|
||||
pos = str.find(buffer, start);
|
||||
if (pos != std::wstring::npos)
|
||||
{
|
||||
str.replace(str.begin() + pos, str.begin() + pos + wcslen(buffer), stringValues[i - 1]);
|
||||
start = pos + stringValues[i - 1].length();
|
||||
}
|
||||
} while(pos != std::wstring::npos);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** ReplaceToolTipMeasures
|
||||
**
|
||||
** Replaces %1, %2 etc with the corresponding measure value
|
||||
*/
|
||||
void CMeter::ReplaceToolTipMeasures(std::wstring& str)
|
||||
{
|
||||
std::vector<std::wstring> stringValues;
|
||||
|
||||
if (!m_AllMeasures.empty())
|
||||
if (!m_AllMeasures.empty())
|
||||
{
|
||||
// Get the values for the measures
|
||||
for (size_t i = 0; i < m_AllMeasures.size(); ++i)
|
||||
@ -589,30 +618,13 @@ std::wstring CMeter::ReplaceMeasures(std::wstring source)
|
||||
}
|
||||
else
|
||||
{
|
||||
return source;
|
||||
return;
|
||||
}
|
||||
|
||||
WCHAR buffer[64];
|
||||
// Create the actual text (i.e. replace %1, %2, .. with the measure texts)
|
||||
|
||||
for (size_t i = stringValues.size(); i > 0; --i)
|
||||
if (!stringValues.empty())
|
||||
{
|
||||
wsprintf(buffer, L"%%%i", i);
|
||||
|
||||
size_t start = 0;
|
||||
size_t pos = std::wstring::npos;
|
||||
|
||||
do
|
||||
{
|
||||
pos = source.find(buffer, start);
|
||||
if (pos != std::wstring::npos)
|
||||
{
|
||||
source.replace(source.begin() + pos, source.begin() + pos + wcslen(buffer), stringValues[i - 1]);
|
||||
start = pos + stringValues[i - 1].length();
|
||||
}
|
||||
} while(pos != std::wstring::npos);
|
||||
ReplaceMeasures(stringValues, str);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -674,7 +686,8 @@ void CMeter::UpdateToolTip()
|
||||
|
||||
SendMessage(hwndTT, TTM_GETTOOLINFO, NULL, (LPARAM) (LPTOOLINFO) &ti);
|
||||
|
||||
std::wstring text = ReplaceMeasures(m_ToolTipText);
|
||||
std::wstring text = m_ToolTipText;
|
||||
ReplaceToolTipMeasures(text);
|
||||
ti.lpszText = (PTSTR) text.c_str();
|
||||
ti.rect = GetMeterRect();
|
||||
|
||||
@ -715,7 +728,8 @@ void CMeter::UpdateToolTip()
|
||||
}
|
||||
}
|
||||
|
||||
text = ReplaceMeasures(m_ToolTipTitle);
|
||||
text = m_ToolTipTitle;
|
||||
ReplaceToolTipMeasures(text);
|
||||
SendMessage(hwndTT, TTM_SETTITLE, (WPARAM) hIcon, (LPARAM) text.c_str());
|
||||
|
||||
if (destroy)
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
virtual bool HasActiveTransition() { return false; }
|
||||
|
||||
bool HasDynamicVariables() { return m_DynamicVariables; }
|
||||
@ -52,22 +52,17 @@ public:
|
||||
void SetX(int x) { m_X = x; m_RelativeX = POSITION_ABSOLUTE; }
|
||||
void SetY(int y) { m_Y = y; m_RelativeY = POSITION_ABSOLUTE; }
|
||||
|
||||
std::wstring& GetRightMouseDownAction() { return m_RightMouseDownAction; }
|
||||
std::wstring& GetRightMouseUpAction() { return m_RightMouseUpAction; }
|
||||
std::wstring& GetRightMouseDoubleClickAction() { return m_RightMouseDoubleClickAction; }
|
||||
std::wstring& GetLeftMouseDownAction() { return m_LeftMouseDownAction; }
|
||||
std::wstring& GetLeftMouseUpAction() { return m_LeftMouseUpAction; }
|
||||
std::wstring& GetLeftMouseDoubleClickAction() { return m_LeftMouseDoubleClickAction; }
|
||||
std::wstring& GetMiddleMouseDownAction() { return m_MiddleMouseDownAction; }
|
||||
std::wstring& GetMiddleMouseUpAction() { return m_MiddleMouseUpAction; }
|
||||
std::wstring& GetMiddleMouseDoubleClickAction() { return m_MiddleMouseDoubleClickAction; }
|
||||
std::wstring& GetMouseOverAction() { return m_MouseOverAction; }
|
||||
std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; }
|
||||
|
||||
void SetAllMeasures(CMeasure* measure);
|
||||
void SetAllMeasures(std::vector<CMeasure*> measures);
|
||||
|
||||
std::wstring CMeter::ReplaceMeasures(std::wstring source);
|
||||
const std::wstring& GetRightMouseDownAction() { return m_RightMouseDownAction; }
|
||||
const std::wstring& GetRightMouseUpAction() { return m_RightMouseUpAction; }
|
||||
const std::wstring& GetRightMouseDoubleClickAction() { return m_RightMouseDoubleClickAction; }
|
||||
const std::wstring& GetLeftMouseDownAction() { return m_LeftMouseDownAction; }
|
||||
const std::wstring& GetLeftMouseUpAction() { return m_LeftMouseUpAction; }
|
||||
const std::wstring& GetLeftMouseDoubleClickAction() { return m_LeftMouseDoubleClickAction; }
|
||||
const std::wstring& GetMiddleMouseDownAction() { return m_MiddleMouseDownAction; }
|
||||
const std::wstring& GetMiddleMouseUpAction() { return m_MiddleMouseUpAction; }
|
||||
const std::wstring& GetMiddleMouseDoubleClickAction() { return m_MiddleMouseDoubleClickAction; }
|
||||
const std::wstring& GetMouseOverAction() { return m_MouseOverAction; }
|
||||
const std::wstring& GetMouseLeaveAction() { return m_MouseLeaveAction; }
|
||||
|
||||
const std::wstring& GetToolTipText() { return m_ToolTipText; }
|
||||
bool HasToolTip() { return m_ToolTipHandle != NULL; }
|
||||
@ -114,6 +109,12 @@ protected:
|
||||
POSITION_RELATIVE_BR
|
||||
};
|
||||
|
||||
void SetAllMeasures(CMeasure* measure);
|
||||
void SetAllMeasures(const std::vector<CMeasure*>& measures);
|
||||
void ReplaceToolTipMeasures(std::wstring& str);
|
||||
|
||||
static void ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str);
|
||||
|
||||
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
|
||||
|
@ -227,7 +227,7 @@ bool CMeterButton::Draw(Graphics& graphics)
|
||||
** Overridden method. The meters need not to be bound on anything
|
||||
**
|
||||
*/
|
||||
void CMeterButton::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeterButton::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
// It's ok not to bind meter to anything
|
||||
if (!m_MeasureName.empty())
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
|
||||
bool MouseMove(POINT pos);
|
||||
bool MouseUp(POINT pos, CMeterWindow* window);
|
||||
|
@ -562,7 +562,7 @@ bool CMeterHistogram::Draw(Graphics& graphics)
|
||||
** Overwritten method to handle the secondary measure binding.
|
||||
**
|
||||
*/
|
||||
void CMeterHistogram::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeterHistogram::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
CMeter::BindMeasure(measures);
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
std::wstring m_SecondaryMeasureName; // Name of the secondary measure
|
||||
|
@ -668,7 +668,7 @@ bool CMeterImage::Draw(Graphics& graphics)
|
||||
** Overridden method. The Image meters need not to be bound on anything
|
||||
**
|
||||
*/
|
||||
void CMeterImage::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeterImage::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
// It's ok not to bind image meter to anything
|
||||
if (!m_MeasureName.empty())
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
|
||||
protected:
|
||||
void LoadImage(bool bLoadAlways);
|
||||
|
@ -69,6 +69,11 @@ void CMeterLine::Initialize()
|
||||
{
|
||||
m_AllValues.push_back(std::vector<double>());
|
||||
|
||||
if (m_W > 0)
|
||||
{
|
||||
m_AllValues.back().reserve(m_W);
|
||||
}
|
||||
|
||||
if (num > 0)
|
||||
{
|
||||
m_AllValues.back().assign(num, 0);
|
||||
@ -299,23 +304,37 @@ bool CMeterLine::Draw(Graphics& graphics)
|
||||
}
|
||||
|
||||
// Draw all the lines
|
||||
const REAL H = m_H - 1.0f;
|
||||
const bool closeRequired = (m_LineWidth != 1.0);
|
||||
counter = 0;
|
||||
std::vector< std::vector<double> >::const_iterator i = m_AllValues.begin();
|
||||
for (; i != m_AllValues.end(); ++i)
|
||||
{
|
||||
// Draw a line
|
||||
REAL Y = 0.0f;
|
||||
REAL oldY = 0.0f;
|
||||
REAL H = m_H - 1.0f;
|
||||
REAL Y, oldY;
|
||||
|
||||
double scale = m_ScaleValues[counter] * H / maxValue;
|
||||
const double scale = m_ScaleValues[counter] * H / maxValue;
|
||||
const int size = (int)(*i).size();
|
||||
|
||||
int pos = m_CurrentPos;
|
||||
int size = (int)(*i).size();
|
||||
|
||||
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
||||
if (pos >= m_W) pos = 0;
|
||||
|
||||
for (int j = x, R = x + m_W; j < R; ++j)
|
||||
if (pos < size)
|
||||
{
|
||||
oldY = (REAL)((*i)[pos] * scale);
|
||||
oldY = min(oldY, H);
|
||||
oldY = max(oldY, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldY = 0.0f;
|
||||
}
|
||||
oldY = (m_Flip) ? y + oldY : y + H - oldY;
|
||||
++pos;
|
||||
|
||||
// Cache all lines
|
||||
GraphicsPath path;
|
||||
for (int j = x + 1, R = x + m_W; j < R; ++j)
|
||||
{
|
||||
if (pos >= m_W) pos = 0;
|
||||
|
||||
@ -327,20 +346,25 @@ bool CMeterLine::Draw(Graphics& graphics)
|
||||
}
|
||||
else
|
||||
{
|
||||
Y = 0.0f;
|
||||
Y = 0.0f;
|
||||
}
|
||||
|
||||
Y = (m_Flip) ? y + Y : y + H - Y;
|
||||
|
||||
if (j != x)
|
||||
{
|
||||
graphics.DrawLine(&pen, (REAL)(j - 1), oldY, (REAL)j, Y); // GDI+
|
||||
}
|
||||
oldY = Y;
|
||||
path.AddLine((REAL)(j - 1), oldY, (REAL)j, Y);
|
||||
|
||||
if (closeRequired)
|
||||
{
|
||||
path.CloseFigure();
|
||||
}
|
||||
|
||||
oldY = Y;
|
||||
++pos;
|
||||
}
|
||||
|
||||
// Draw cached lines
|
||||
Pen pen(m_Colors[counter], (REAL)m_LineWidth);
|
||||
graphics.DrawPath(&pen, &path);
|
||||
|
||||
++counter;
|
||||
}
|
||||
|
||||
@ -353,7 +377,7 @@ bool CMeterLine::Draw(Graphics& graphics)
|
||||
** Overwritten method to handle the other measure bindings.
|
||||
**
|
||||
*/
|
||||
void CMeterLine::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeterLine::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
CMeter::BindMeasure(measures);
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
|
||||
private:
|
||||
std::vector<std::wstring> m_MeasureNames; // Name of the other measures
|
||||
|
@ -444,31 +444,15 @@ bool CMeterString::Update()
|
||||
m_String += stringValues[0];
|
||||
}
|
||||
}
|
||||
else if (!stringValues.empty())
|
||||
{
|
||||
std::wstring tmpText = m_Text;
|
||||
ReplaceMeasures(stringValues, tmpText);
|
||||
m_String += tmpText;
|
||||
}
|
||||
else
|
||||
{
|
||||
WCHAR buffer[64];
|
||||
// Create the actual text (i.e. replace %1, %2, .. with the measure texts)
|
||||
std::wstring tmpText = m_Text;
|
||||
|
||||
for (size_t i = stringValues.size(); i > 0; --i)
|
||||
{
|
||||
wsprintf(buffer, L"%%%i", i);
|
||||
|
||||
size_t start = 0;
|
||||
size_t pos = std::wstring::npos;
|
||||
|
||||
do
|
||||
{
|
||||
pos = tmpText.find(buffer, start);
|
||||
if (pos != std::wstring::npos)
|
||||
{
|
||||
tmpText.replace(tmpText.begin() + pos, tmpText.begin() + pos + wcslen(buffer), stringValues[i - 1]);
|
||||
start = pos + stringValues[i - 1].length();
|
||||
}
|
||||
} while(pos != std::wstring::npos);
|
||||
}
|
||||
|
||||
m_String += tmpText;
|
||||
m_String += m_Text;
|
||||
}
|
||||
if (!m_Postfix.empty()) m_String += m_Postfix;
|
||||
|
||||
@ -628,7 +612,7 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
|
||||
** Overridden method. The string meters need not to be bound on anything
|
||||
**
|
||||
*/
|
||||
void CMeterString::BindMeasure(std::list<CMeasure*>& measures)
|
||||
void CMeterString::BindMeasure(const std::list<CMeasure*>& measures)
|
||||
{
|
||||
if (m_MeasureName.empty()) return; // Allow NULL measure binding
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
virtual void Initialize();
|
||||
virtual bool Update();
|
||||
virtual bool Draw(Gdiplus::Graphics& graphics);
|
||||
virtual void BindMeasure(std::list<CMeasure*>& measures);
|
||||
virtual void BindMeasure(const std::list<CMeasure*>& measures);
|
||||
|
||||
static void FreeFontCache();
|
||||
static void EnumerateInstalledFontFamilies();
|
||||
|
Loading…
Reference in New Issue
Block a user