Code cleanup

This commit is contained in:
spx 2013-01-15 01:37:13 +09:00
parent 731a0c611a
commit c3982da712
5 changed files with 51 additions and 46 deletions

View File

@ -67,13 +67,11 @@ public:
static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords); static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords);
static void RemoveTrailingZero(WCHAR* str, int strLen); static void RemoveTrailingZero(WCHAR* str, int strLen);
std::wstring GetOnUpdateAction() { return m_OnUpdateAction; } const std::wstring& GetOnChangeAction() { return m_OnChangeAction; }
std::wstring GetOnChangeAction() { return m_OnChangeAction; }
void SetOldValue(double value) { m_OldValue = value; } void SetOldValue(double value) { m_OldValue = value; }
double GetOldValue() { return m_OldValue; } double GetOldValue() { return m_OldValue; }
void SetOldStringValue(std::wstring value) { m_OldStringValue = value; } void SetOldStringValue(std::wstring value) { m_OldStringValue = value; }
std::wstring GetOldStringValue() { return m_OldStringValue; } const std::wstring& GetOldStringValue() { return m_OldStringValue; }
CMeterWindow* GetMeterWindow() { return m_MeterWindow; } CMeterWindow* GetMeterWindow() { return m_MeterWindow; }
@ -118,8 +116,6 @@ protected:
bool m_Disabled; // Status of the measure bool m_Disabled; // Status of the measure
bool m_Initialized; bool m_Initialized;
std::wstring m_OnUpdateAction;
std::wstring m_OnChangeAction; std::wstring m_OnChangeAction;
double m_OldValue; double m_OldValue;
std::wstring m_OldStringValue; std::wstring m_OldStringValue;

View File

@ -76,8 +76,6 @@ public:
void SetMouseOver(bool over) { m_MouseOver = over; } void SetMouseOver(bool over) { m_MouseOver = over; }
bool IsMouseOver() { return m_MouseOver; } bool IsMouseOver() { return m_MouseOver; }
std::wstring GetOnUpdateAction() { return m_OnUpdateAction; }
CMeterWindow* GetMeterWindow() { return m_MeterWindow; } CMeterWindow* GetMeterWindow() { return m_MeterWindow; }
static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHAR* name); static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow, const WCHAR* name);
@ -153,8 +151,6 @@ protected:
bool m_AntiAlias; bool m_AntiAlias;
bool m_Initialized; bool m_Initialized;
std::wstring m_OnUpdateAction;
CMeterWindow* m_MeterWindow; CMeterWindow* m_MeterWindow;
}; };

View File

@ -1226,12 +1226,9 @@ void CMeterWindow::UpdateMeter(const std::wstring& name, bool group)
{ {
if (all || (bContinue && CompareName((*j), meter, group))) if (all || (bContinue && CompareName((*j), meter, group)))
{ {
UpdateMeter((*j), bActiveTransition, true); if (UpdateMeter((*j), bActiveTransition, true))
std::wstring updateAction = (*j)->GetOnUpdateAction();
if (!updateAction.empty())
{ {
Rainmeter->ExecuteCommand(updateAction.c_str(), this); DoUpdateAction((*j));
} }
SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size SetResizeWindowMode(RESIZEMODE_CHECK); // Need to recalculate the window size
@ -1355,12 +1352,10 @@ void CMeterWindow::UpdateMeasure(const std::wstring& name, bool group)
bNetStats = false; bNetStats = false;
} }
UpdateMeasure((*i), true); if (UpdateMeasure((*i), true))
std::wstring updateAction = (*i)->GetOnUpdateAction();
if (!updateAction.empty())
{ {
Rainmeter->ExecuteCommand(updateAction.c_str(), this); DoUpdateAction((*i));
//DoChangeAction((*i), false); // TODO: Check that this is the first update or not
} }
if (!group) return; if (!group) return;
@ -2698,27 +2693,8 @@ void CMeterWindow::Update(bool refresh)
{ {
if (UpdateMeasure((*i), refresh)) if (UpdateMeasure((*i), refresh))
{ {
std::wstring updateAction = (*i)->GetOnUpdateAction(); DoUpdateAction((*i));
if (!updateAction.empty()) DoChangeAction((*i), refresh);
{
Rainmeter->ExecuteCommand(updateAction.c_str(), this);
}
double newValue = (*i)->GetValue();
const WCHAR* newStringValue = (*i)->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
std::wstring changeAction = (*i)->GetOnChangeAction();
if (refresh)
{
(*i)->SetOldValue(newValue);
(*i)->SetOldStringValue(newStringValue);
}
else if (((*i)->GetOldValue() != newValue || (*i)->GetOldStringValue() != newStringValue) && !changeAction.empty())
{
(*i)->SetOldValue(newValue);
(*i)->SetOldStringValue(newStringValue);
Rainmeter->ExecuteCommand(changeAction.c_str(), this);
}
} }
} }
} }
@ -2735,11 +2711,7 @@ void CMeterWindow::Update(bool refresh)
{ {
bUpdate = true; bUpdate = true;
std::wstring updateAction = (*j)->GetOnUpdateAction(); DoUpdateAction((*j));
if (!updateAction.empty())
{
Rainmeter->ExecuteCommand(updateAction.c_str(), this);
}
} }
} }
@ -2769,6 +2741,40 @@ void CMeterWindow::Update(bool refresh)
} }
} }
void CMeterWindow::DoUpdateAction(CSection* section)
{
const std::wstring& updateAction = section->GetOnUpdateAction();
if (!updateAction.empty())
{
Rainmeter->ExecuteCommand(updateAction.c_str(), this);
}
}
void CMeterWindow::DoChangeAction(CMeasure* measure, bool first)
{
const std::wstring& changeAction = measure->GetOnChangeAction();
if (first)
{
double newValue = measure->GetValue();
const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
measure->SetOldValue(newValue);
measure->SetOldStringValue(newStringValue);
}
else if (!changeAction.empty())
{
double newValue = measure->GetValue();
const WCHAR* newStringValue = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
if (measure->GetOldValue() != newValue || wcscmp(measure->GetOldStringValue().c_str(), newStringValue) != 0)
{
measure->SetOldValue(newValue);
measure->SetOldStringValue(newStringValue);
Rainmeter->ExecuteCommand(changeAction.c_str(), this);
}
}
}
/* /*
** Updates the window contents ** Updates the window contents
** **

View File

@ -25,6 +25,7 @@
#include <string> #include <string>
#include <list> #include <list>
#include "ConfigParser.h" #include "ConfigParser.h"
#include "Section.h"
#include "Group.h" #include "Group.h"
#include "Mouse.h" #include "Mouse.h"
@ -317,6 +318,8 @@ private:
bool UpdateMeasure(CMeasure* measure, bool force); bool UpdateMeasure(CMeasure* measure, bool force);
bool UpdateMeter(CMeter* meter, bool& bActiveTransition, bool force); bool UpdateMeter(CMeter* meter, bool& bActiveTransition, bool force);
void Update(bool refresh); void Update(bool refresh);
void DoUpdateAction(CSection* section);
void DoChangeAction(CMeasure* measure, bool first);
void UpdateWindow(int alpha, bool reset); void UpdateWindow(int alpha, bool reset);
void ReadOptions(); void ReadOptions();
void WriteOptions(INT setting = OPTION_ALL); void WriteOptions(INT setting = OPTION_ALL);

View File

@ -40,6 +40,8 @@ public:
int GetUpdateCounter() const { return m_UpdateCounter; } int GetUpdateCounter() const { return m_UpdateCounter; }
int GetUpdateDivider() const { return m_UpdateDivider; } int GetUpdateDivider() const { return m_UpdateDivider; }
const std::wstring& GetOnUpdateAction() { return m_OnUpdateAction; }
protected: protected:
CSection(const WCHAR* name) : m_Name(name), m_DynamicVariables(false), m_UpdateDivider(1), m_UpdateCounter(1) {} CSection(const WCHAR* name) : m_Name(name), m_DynamicVariables(false), m_UpdateDivider(1), m_UpdateCounter(1) {}
@ -48,6 +50,8 @@ protected:
bool m_DynamicVariables; // If true, the section contains dynamic variables bool m_DynamicVariables; // If true, the section contains dynamic variables
int m_UpdateDivider; // Divider for the update int m_UpdateDivider; // Divider for the update
int m_UpdateCounter; // Current update counter int m_UpdateCounter; // Current update counter
std::wstring m_OnUpdateAction;
}; };
#endif #endif