Code cleanup.

This commit is contained in:
spx 2011-11-01 04:56:46 +00:00
parent 6644b81909
commit 1aaa03308c
13 changed files with 46 additions and 60 deletions

View File

@ -39,7 +39,8 @@ std::unordered_map<std::wstring, std::wstring> CConfigParser::c_MonitorVariables
CConfigParser::CConfigParser() :
m_Parser(MathParser_Create(NULL)),
m_LastReplaced(false),
m_LastDefaultUsed(false)
m_LastDefaultUsed(false),
m_LastValueDefined(false)
{
}
@ -71,6 +72,12 @@ void CConfigParser::Initialize(LPCTSTR filename, CRainmeter* pRainmeter, CMeterW
m_FoundSections.clear();
m_ListVariables.clear();
m_StyleTemplate.clear();
m_LastUsedStyle.clear();
m_LastReplaced = false;
m_LastDefaultUsed = false;
m_LastValueDefined = false;
// Set the built-in variables. Do this before the ini file is read so that the paths can be used with @include
SetBuiltInVariables(pRainmeter, meterWindow);
ResetMonitorVariables(meterWindow);
@ -580,6 +587,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
m_LastUsedStyle.clear();
m_LastReplaced = false;
m_LastDefaultUsed = false;
m_LastValueDefined = false;
const std::wstring strSection = section;
const std::wstring strKey = key;
@ -634,6 +642,10 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
}
}
if (result.size() > 0)
{
m_LastValueDefined = true;
const std::wstring CURRENTSECTION = L"CURRENTSECTION";
SetBuiltInVariable(CURRENTSECTION, strSection); // Set temporarily
@ -648,6 +660,7 @@ const std::wstring& CConfigParser::ReadString(LPCTSTR section, LPCTSTR key, LPCT
{
m_LastReplaced = true;
}
}
return result;
}

View File

@ -57,6 +57,8 @@ public:
const std::wstring& GetLastUsedStyle() { return m_LastUsedStyle; }
bool GetLastReplaced() { return m_LastReplaced; }
bool GetLastDefaultUsed() { return m_LastDefaultUsed; }
bool GetLastKeyDefined() { return !m_LastDefaultUsed; }
bool GetLastValueDefined() { return m_LastValueDefined; }
void ResetMonitorVariables(CMeterWindow* meterWindow = NULL);
@ -119,6 +121,7 @@ private:
std::wstring m_LastUsedStyle;
bool m_LastReplaced;
bool m_LastDefaultUsed;
bool m_LastValueDefined;
std::vector<std::wstring> m_Sections; // The sections must be an ordered array
std::unordered_set<std::wstring> m_FoundSections;

View File

@ -741,14 +741,6 @@
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MaxSpeed</Optimization>
</ClCompile>
<ClCompile Include="ccalc-0.5.1\wininit.c">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EnableFastChecks</BasicRuntimeChecks>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Disabled</Optimization>
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">EnableFastChecks</BasicRuntimeChecks>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MaxSpeed</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MaxSpeed</Optimization>
</ClCompile>
<ClCompile Include="lua\LuaManager.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Use</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>

View File

@ -156,9 +156,6 @@
<ClCompile Include="ccalc-0.5.1\strmap.c">
<Filter>CCalc</Filter>
</ClCompile>
<ClCompile Include="ccalc-0.5.1\wininit.c">
<Filter>CCalc</Filter>
</ClCompile>
<ClCompile Include="lua\LuaManager.cpp">
<Filter>Lua</Filter>
</ClCompile>

View File

@ -46,6 +46,8 @@ CMeter::CMeter(CMeterWindow* meterWindow, const WCHAR* name) : m_MeterWindow(met
m_W(),
m_H(),
m_Hidden(false),
m_WDefined(false),
m_HDefined(false),
m_RelativeMeter(),
m_DynamicVariables(false),
m_ToolTipWidth(),
@ -358,8 +360,10 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
}
m_W = (int)parser.ReadFormula(section, L"W", 1.0);
m_WDefined = parser.GetLastValueDefined();
if (m_W < 0) m_W = 0;
m_H = (int)parser.ReadFormula(section, L"H", 1.0);
m_HDefined = parser.GetLastValueDefined();
if (m_H < 0) m_H = 0;
if (!m_Initialized)

View File

@ -138,6 +138,8 @@ protected:
int m_W; // Width of the meter
int m_H; // Height of the meter
bool m_Hidden; // Status of the meter
bool m_WDefined;
bool m_HDefined;
CMeter* m_RelativeMeter;
bool m_DynamicVariables; // If true, the measure contains dynamic variables

View File

@ -104,15 +104,13 @@ void CMeterButton::Initialize()
}
// Separate the frames
Graphics desktopGraphics(GetDesktopWindow());
for (int i = 0; i < BUTTON_FRAMES; ++i)
{
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppPARGB);
Graphics graphics(&bitmapPart);
Rect r(0, 0, m_W, m_H);
if (bitmap->GetHeight() > bitmap->GetWidth())
if (m_H > m_W)
{
graphics.DrawImage(bitmap, r, 0, m_H * i, m_W, m_H, UnitPixel);
}

View File

@ -34,8 +34,6 @@ using namespace Gdiplus;
*/
CMeterImage::CMeterImage(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name),
m_NeedsRedraw(false),
m_WidthDefined(false),
m_HeightDefined(false),
m_PreserveAspectRatio(false),
m_Tile(false),
m_ScaleMargins()
@ -89,16 +87,16 @@ void CMeterImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
int imageW = bitmap->GetWidth();
int imageH = bitmap->GetHeight();
if (m_WidthDefined)
if (m_WDefined)
{
if (!m_HeightDefined)
if (!m_HDefined)
{
m_H = (imageW == 0) ? 0 : (m_Tile) ? imageH : m_W * imageH / imageW;
}
}
else
{
if (m_HeightDefined)
if (m_HDefined)
{
m_W = (imageH == 0) ? 0 : (m_Tile) ? imageW : m_H * imageW / imageH;
}
@ -146,15 +144,6 @@ void CMeterImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
static const RECT defMargins = {0};
m_ScaleMargins = parser.ReadRECT(section, L"ScaleMargins", defMargins);
if (parser.IsValueDefined(section, L"W"))
{
m_WidthDefined = true;
}
if (parser.IsValueDefined(section, L"H"))
{
m_HeightDefined = true;
}
// Read tinting configs
m_Image.ReadConfig(parser, section);
@ -274,7 +263,7 @@ bool CMeterImage::Draw(Graphics& graphics)
}
else if (m_PreserveAspectRatio)
{
if (m_WidthDefined && m_HeightDefined)
if (m_WDefined && m_HDefined)
{
REAL imageRatio = imageW / (REAL)imageH;
REAL meterRatio = m_W / (REAL)m_H;

View File

@ -43,8 +43,6 @@ protected:
std::wstring m_Path;
bool m_NeedsRedraw;
bool m_WidthDefined;
bool m_HeightDefined;
bool m_PreserveAspectRatio; // If true, aspect ratio of the image is preserved when the image is scaled
bool m_Tile;

View File

@ -85,7 +85,6 @@ CMeterString::CMeterString(CMeterWindow* meterWindow, const WCHAR* name) : CMete
m_Font(),
m_FontFamily(),
m_NumOfDecimals(-1),
m_DimensionsDefined(false),
m_Angle()
{
}
@ -459,11 +458,6 @@ void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
throw CError(error, __LINE__, __FILE__);
}
if (parser.IsValueDefined(section, L"W") && parser.IsValueDefined(section, L"H"))
{
m_DimensionsDefined = true;
}
if (m_Initialized &&
(oldFontFace != m_FontFace ||
oldFontSize != m_FontSize ||
@ -529,7 +523,7 @@ bool CMeterString::Update()
break;
}
if (!m_DimensionsDefined)
if (!m_WDefined && !m_HDefined)
{
// Calculate the text size
RectF rect;
@ -636,10 +630,7 @@ bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y);
}
if (m_Effect == EFFECT_NONE)
{
}
else
if (m_Effect != EFFECT_NONE)
{
SolidBrush solidBrush(m_EffectColor);
RectF rcEffect(rcDest);

View File

@ -92,7 +92,6 @@ private:
Gdiplus::Font* m_Font; // The font
Gdiplus::FontFamily* m_FontFamily; // The font family
int m_NumOfDecimals; // Number of decimals to be displayed
bool m_DimensionsDefined;
Gdiplus::REAL m_Angle;
Gdiplus::RectF m_Rect;

View File

@ -126,7 +126,7 @@ const Gdiplus::ColorMatrix CTintedImage::c_GreyScaleMatrix = {
0.0f, 0.0f, 0.0f, 0.0f, 1.0f
};
const Gdiplus::ColorMatrix CTintedImage::c_IdentifyMatrix = {
const Gdiplus::ColorMatrix CTintedImage::c_IdentityMatrix = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
@ -162,7 +162,7 @@ CTintedImage::CTintedImage(const WCHAR* name, const WCHAR** configArray, bool di
m_Flip(RotateNoneFlipNone),
m_Rotate()
{
*m_ColorMatrix = c_IdentifyMatrix;
*m_ColorMatrix = c_IdentityMatrix;
}
/*
@ -317,7 +317,7 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
}
if (!m_NeedsTinting)
{
if (m_GreyScale || !CompareColorMatrix(m_ColorMatrix, &c_IdentifyMatrix))
if (m_GreyScale || !CompareColorMatrix(m_ColorMatrix, &c_IdentityMatrix))
{
m_NeedsTinting = true;
}
@ -442,7 +442,7 @@ void CTintedImage::ApplyCrop()
*/
void CTintedImage::ApplyTint()
{
bool useColorMatrix = !CompareColorMatrix(m_ColorMatrix, &c_IdentifyMatrix);
bool useColorMatrix = !CompareColorMatrix(m_ColorMatrix, &c_IdentityMatrix);
if (m_GreyScale || useColorMatrix)
{
@ -651,7 +651,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
alpha = min(255, alpha);
alpha = max(0, alpha);
*m_ColorMatrix = c_IdentifyMatrix;
*m_ColorMatrix = c_IdentityMatrix;
// Read in the Color Matrix
// It has to be read in like this because it crashes when reading over 17 floats

View File

@ -128,7 +128,7 @@ protected:
std::wstring m_CacheKey;
static const Gdiplus::ColorMatrix c_GreyScaleMatrix;
static const Gdiplus::ColorMatrix c_IdentifyMatrix;
static const Gdiplus::ColorMatrix c_IdentityMatrix;
static const WCHAR* c_DefaultConfigArray[ConfigCount];
};