Added AutoScale=2 and "k" postfix to Meter=STRING.

----
For instance:
A=2800000000, B=0

- AutoScale=0
AutoScale is disabled. Uses Scale value. (Same as before.)
A="2800000000", B="0"

- AutoScale=1
Scales value by 1024. (Same as before.)
A="2.6 G", B="0.0 "

- AutoScale=2
Scales value by 1000.
A="2.8 G", B="0.0 "

- AutoScale=1k
Scales value by 1024, and uses kilo as the lowest unit.
A="2.6 G", B="0.0 k"

- AutoScale=2k
Scales value by 1000, and uses kilo as the lowest unit.
A="2.8 G", B="0.0 k"
----
This commit is contained in:
spx 2011-01-19 15:31:45 +00:00
parent 837488871b
commit 235841e01f
24 changed files with 97 additions and 44 deletions

View File

@ -204,10 +204,10 @@ void UpdateAboutStatistics(LPCTSTR entryName)
WCHAR buffer[256];
double minVal = (*i)->GetMinValue();
double maxVal = (*i)->GetMaxValue();
CMeasure::GetScaledValue(1, minVal, buffer, _countof(buffer));
CMeasure::GetScaledValue(AUTOSCALE_ON, 1, minVal, buffer, _countof(buffer));
std::wstring range = buffer;
range += L" - ";
CMeasure::GetScaledValue(1, maxVal, buffer, _countof(buffer));
CMeasure::GetScaledValue(AUTOSCALE_ON, 1, maxVal, buffer, _countof(buffer));
range += buffer;
if (name && *name)

View File

@ -530,7 +530,7 @@ bool CConfigParser::ReplaceMeasures(std::wstring& result)
CMeasure* measure = GetMeasure(var);
if (measure)
{
std::wstring value = measure->GetStringValue(false, 1, -1, false);
std::wstring value = measure->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
// Measure found, replace it with the value
result.replace(result.begin() + pos, result.begin() + end + 1, value);

View File

@ -38,6 +38,27 @@
#include "Error.h"
#include "Litestep.h"
enum AUTOSCALE_INDEX
{
AUTOSCALE_INDEX_1024 = 0,
AUTOSCALE_INDEX_1000 = 1
};
static const double g_TblScale[2][4] = {
{
1024.0 * 1024.0 * 1024.0 * 1024.0,
1024.0 * 1024.0 * 1024.0,
1024.0 * 1024.0,
1024.0
},
{
1000.0 * 1000.0 * 1000.0 * 1000.0,
1000.0 * 1000.0 * 1000.0,
1000.0 * 1000.0,
1000.0
}
};
const int MEDIAN_SIZE = 7;
extern CRainmeter* Rainmeter;
@ -500,7 +521,7 @@ double CMeasure::GetValueRange()
** decimals Number of decimals used in the value. If -1, get rid of ".00000" for dynamic variables.
** percentual Return the value as % from the maximum value.
*/
const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasure::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
static WCHAR buffer[MAX_LINE_LENGTH];
WCHAR format[32];
@ -519,9 +540,9 @@ const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals
_snwprintf_s(buffer, _TRUNCATE, format, val);
}
}
else if(autoScale)
else if(autoScale != AUTOSCALE_OFF)
{
GetScaledValue(decimals, GetValue(), buffer, _countof(buffer));
GetScaledValue(autoScale, decimals, GetValue(), buffer, _countof(buffer));
}
else
{
@ -552,7 +573,7 @@ const WCHAR* CMeasure::GetStringValue(bool autoScale, double scale, int decimals
return CheckSubstitute(buffer);
}
void CMeasure::GetScaledValue(int decimals, double theValue, WCHAR* buffer, size_t sizeInWords)
void CMeasure::GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords)
{
WCHAR format[32];
double value = 0;
@ -566,25 +587,27 @@ void CMeasure::GetScaledValue(int decimals, double theValue, WCHAR* buffer, size
_snwprintf_s(format, _TRUNCATE, L"%%.%if", decimals);
}
if(theValue > 1000.0 * 1000.0 * 1000.0 * 1000.0)
int index = (autoScale == AUTOSCALE_1000 || autoScale == AUTOSCALE_1000K) ? AUTOSCALE_INDEX_1000 : AUTOSCALE_INDEX_1024;
if(theValue > (g_TblScale[index][0] * 0.99))
{
wcsncat_s(format, L" T", _TRUNCATE);
value = theValue / (1024.0 * 1024.0 * 1024.0 * 1024.0);
value = theValue / g_TblScale[index][0];
}
else if(theValue > 1000.0 * 1000.0 * 1000.0)
else if(theValue > (g_TblScale[index][1] * 0.99))
{
wcsncat_s(format, L" G", _TRUNCATE);
value = theValue / (1024.0 * 1024.0 * 1024.0);
value = theValue / g_TblScale[index][1];
}
else if(theValue > 1000.0 * 1000.0)
else if(theValue > (g_TblScale[index][2] * 0.99))
{
wcsncat_s(format, L" M", _TRUNCATE);
value = theValue / (1024.0 * 1024.0);
value = theValue / g_TblScale[index][2];
}
else if(theValue > 1000.0)
else if(autoScale == AUTOSCALE_1024K || autoScale == AUTOSCALE_1000K || theValue > (g_TblScale[index][3] * 0.99))
{
wcsncat_s(format, L" k", _TRUNCATE);
value = theValue / 1024.0;
value = theValue / g_TblScale[index][3];
}
else
{
@ -604,7 +627,7 @@ const WCHAR* CMeasure::GetStats()
{
static std::wstring value;
value = GetStringValue(true, 1, 1, false);
value = GetStringValue(AUTOSCALE_ON, 1, 1, false);
return value.c_str();
}

View File

@ -23,6 +23,18 @@
#include "Litestep.h"
#include "Group.h"
enum AUTOSCALE
{
AUTOSCALE_1024 = 1, // scales by 1024
AUTOSCALE_1000 = 2, // scales by 1000
AUTOSCALE_1024K = 101, // scales by 1024, and uses kilo as the lowest unit
AUTOSCALE_1000K = 102, // scales by 1000, and uses kilo as the lowest unit
AUTOSCALE_OFF = 0,
AUTOSCALE_ON = AUTOSCALE_1024
};
class CMeter;
class CMeasure : public CGroup
@ -59,8 +71,8 @@ public:
int GetUpdateCounter() { return m_UpdateCounter; }
int GetUpdateDivider() { return m_UpdateDivider; }
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
static void GetScaledValue(int decimals, double theValue, WCHAR* buffer, size_t sizeInWords);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
static void GetScaledValue(AUTOSCALE autoScale, int decimals, double theValue, WCHAR* buffer, size_t sizeInWords);
static CMeasure* Create(const WCHAR* measure, CMeterWindow* meterWindow);

View File

@ -127,7 +127,7 @@ bool CMeasureDiskSpace::Update()
** Returns the time as string.
**
*/
const WCHAR* CMeasureDiskSpace::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasureDiskSpace::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
if (m_Label)
{

View File

@ -29,7 +29,7 @@ public:
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
virtual bool Update();
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
private:
std::wstring m_Drive;

View File

@ -220,7 +220,7 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section)
** Gets the string value from the plugin.
**
*/
const WCHAR* CMeasurePlugin::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasurePlugin::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
if(GetStringFunc)
{

View File

@ -36,7 +36,7 @@ public:
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
virtual bool Update();
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
virtual void ExecuteBang(const WCHAR* args);
private:

View File

@ -177,7 +177,7 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section)
** value to string as normal.
**
*/
const WCHAR* CMeasureRegistry::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasureRegistry::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
if (m_StringValue.empty())
{

View File

@ -29,7 +29,7 @@ public:
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
virtual bool Update();
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
private:
std::wstring m_RegKeyName;

View File

@ -81,7 +81,7 @@ void CMeasureScript::SetValue(double d)
** decimals Number of decimals used in the value.
** percentual Return the value as % from the maximum value.
*/
const WCHAR* CMeasureScript::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasureScript::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
if (m_bGetStringValueDefined && m_pLuaScript->IsInitialized() )

View File

@ -23,7 +23,7 @@ public:
void SetValue(double d);
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
void MeterMouseEvent(CMeter* p_pMeter, MOUSE p_eMouse);
void RunFunctionWithMeter(const char* p_strFunction, CMeter* p_pMeter);

View File

@ -168,7 +168,7 @@ bool CMeasureTime::Update()
** Returns the time as string.
**
*/
const WCHAR* CMeasureTime::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasureTime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
static WCHAR tmpSz[MAX_LINE_LENGTH];
struct tm today;

View File

@ -29,7 +29,7 @@ public:
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
virtual bool Update();
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
private:
void TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format, const struct tm* time);

View File

@ -75,7 +75,7 @@ bool CMeasureUptime::Update()
** Returns the uptime as string.
**
*/
const WCHAR* CMeasureUptime::GetStringValue(bool autoScale, double scale, int decimals, bool percentual)
const WCHAR* CMeasureUptime::GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
static WCHAR buffer[MAX_LINE_LENGTH];

View File

@ -28,7 +28,7 @@ public:
virtual ~CMeasureUptime();
virtual bool Update();
virtual const WCHAR* GetStringValue(bool autoScale, double scale, int decimals, bool percentual);
virtual const WCHAR* GetStringValue(AUTOSCALE autoScale, double scale, int decimals, bool percentual);
virtual void ReadConfig(CConfigParser& parser, const WCHAR* section);
private:

View File

@ -649,12 +649,12 @@ void CMeter::ReplaceToolTipMeasures(std::wstring& str)
// Get the values for the measures
for (size_t i = 0; i < m_AllMeasures.size(); ++i)
{
stringValues.push_back(m_AllMeasures[i]->GetStringValue(true, 1, 0, false));
stringValues.push_back(m_AllMeasures[i]->GetStringValue(AUTOSCALE_ON, 1, 0, false));
}
}
else if (m_Measure != NULL)
{
stringValues.push_back(m_Measure->GetStringValue(true, 1, 0, false));
stringValues.push_back(m_Measure->GetStringValue(AUTOSCALE_ON, 1, 0, false));
}
else
{

View File

@ -182,7 +182,7 @@ bool CMeterImage::Update()
if (m_Measure) // read from the measures
{
std::wstring val = m_Measure->GetStringValue(false, 1, 0, false);
std::wstring val = m_Measure->GetStringValue(AUTOSCALE_OFF, 1, 0, false);
if (m_ImageName.empty())
{
@ -197,7 +197,7 @@ bool CMeterImage::Update()
// Get the values for the other measures
for (size_t i = 0; i < m_Measures.size(); ++i)
{
stringValues.push_back(m_Measures[i]->GetStringValue(false, 1, 0, false));
stringValues.push_back(m_Measures[i]->GetStringValue(AUTOSCALE_OFF, 1, 0, false));
}
m_ImageNameResult = m_ImageName;

View File

@ -71,7 +71,7 @@ CMeterString::CMeterString(CMeterWindow* meterWindow) : CMeter(meterWindow),
m_EffectColor(Color::Black)
{
m_Effect = EFFECT_NONE;
m_AutoScale = true;
m_AutoScale = AUTOSCALE_OFF;
m_Align = ALIGN_LEFT;
m_Font = NULL;
m_FontFamily = NULL;
@ -315,7 +315,6 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_Text = parser.ReadString(section, L"Text", L"");
m_Percentual = 0!=parser.ReadInt(section, L"Percentual", 0);
m_AutoScale = 0!=parser.ReadInt(section, L"AutoScale", 0);
m_ClipString = 0!=parser.ReadInt(section, L"ClipString", 0);
m_FontFace = parser.ReadString(section, L"FontFace", L"Arial");
@ -334,6 +333,24 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
std::wstring autoscale = parser.ReadString(section, L"AutoScale", L"0");
int autoscaleValue = _wtoi(autoscale.c_str());
if (autoscaleValue == 0)
{
m_AutoScale = AUTOSCALE_OFF;
}
else
{
if (autoscale.find_last_of(L"kK") == std::wstring::npos)
{
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000 : AUTOSCALE_1024;
}
else
{
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000K : AUTOSCALE_1024K;
}
}
std::wstring scale = parser.ReadString(section, L"Scale", L"1");
if (scale.find(L'.') == std::wstring::npos)
{
@ -467,7 +484,7 @@ bool CMeterString::Update()
{
std::vector<std::wstring> stringValues;
int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || !m_AutoScale)) ? 0 : 1;
int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || m_AutoScale == AUTOSCALE_OFF)) ? 0 : 1;
if (m_Measure) stringValues.push_back(m_Measure->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual));

View File

@ -21,6 +21,7 @@
#include "Meter.h"
#include "MeterWindow.h"
#include "Measure.h"
namespace Gdiplus
{
@ -78,7 +79,7 @@ private:
std::wstring m_Prefix; // The prefix of the text
std::wstring m_Text; // The text
std::wstring m_FontFace; // name of the font face
bool m_AutoScale; // true, if the value should be autoscaled
AUTOSCALE m_AutoScale; // true, if the value should be autoscaled
METER_ALIGNMENT m_Align; // Alignment of the text
TEXTSTYLE m_Style; // Style of the text
TEXTEFFECT m_Effect; // Text effect

View File

@ -2730,7 +2730,7 @@ void CMeterWindow::Update(bool nodraw)
// std::list<CMeasure*>::iterator i = m_Measures.begin();
// for( ; i != m_Measures.end(); i++)
// {
// const char* sz = (*i)->GetStringValue(true, 1, 1, false);
// const char* sz = (*i)->GetStringValue(AUTOSCALE_ON, 1, 1, false);
// if (sz && wcslen(sz) > 0)
// {
// WCHAR* wideSz = CMeter::ConvertToWide(sz);

View File

@ -3068,7 +3068,7 @@ std::wstring CRainmeter::ParseCommand(const WCHAR* command, CMeterWindow* meterW
{
if (_wcsicmp((*iter)->GetName(), measureName.c_str()) == 0)
{
std::wstring value = (*iter)->GetStringValue(false, 1, -1, false);
std::wstring value = (*iter)->GetStringValue(AUTOSCALE_OFF, 1, -1, false);
strCommand.replace(start, (end - start) + 1, value);
start += value.length();
break;

View File

@ -1,6 +1,6 @@
/*
** Lua binding: measure
** Generated automatically by tolua++-1.0.92 on 11/23/10 00:33:48.
** Generated automatically by tolua++-1.0.92 on 01/19/11 04:59:42.
*/
#ifndef __cplusplus
@ -451,7 +451,7 @@ static int tolua_measure_CMeasure_GetStringValue00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"CMeasure",0,&tolua_err) ||
!tolua_isboolean(tolua_S,2,1,&tolua_err) ||
!tolua_isnumber(tolua_S,2,1,&tolua_err) ||
!tolua_isnumber(tolua_S,3,1,&tolua_err) ||
!tolua_isnumber(tolua_S,4,1,&tolua_err) ||
!tolua_isboolean(tolua_S,5,1,&tolua_err) ||
@ -462,7 +462,7 @@ static int tolua_measure_CMeasure_GetStringValue00(lua_State* tolua_S)
#endif
{
CMeasure* self = (CMeasure*) tolua_tousertype(tolua_S,1,0);
bool autoScale = ((bool) tolua_toboolean(tolua_S,2,false));
AUTOSCALE autoScale = ((AUTOSCALE) (int) tolua_tonumber(tolua_S,2,0));
double scale = ((double) tolua_tonumber(tolua_S,3,1.0));
int decimals = ((int) tolua_tonumber(tolua_S,4,0));
bool percentual = ((bool) tolua_toboolean(tolua_S,5,false));

View File

@ -1,6 +1,6 @@
/*
** Lua binding: measure
** Generated automatically by tolua++-1.0.92 on 11/23/10 00:33:48.
** Generated automatically by tolua++-1.0.92 on 01/19/11 04:59:42.
*/
/* Exported function */