Cosmetics

This commit is contained in:
Birunthan Mohanathas 2012-05-30 21:51:06 +03:00
parent dc35b31559
commit 6efb485e69
8 changed files with 60 additions and 60 deletions

View File

@ -104,7 +104,7 @@ void CMeterBar::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_Image.ClearConfigFlags(); m_Image.ClearOptionFlags();
} }
m_Border = parser.ReadInt(section, L"BarBorder", 0); m_Border = parser.ReadInt(section, L"BarBorder", 0);
@ -130,7 +130,7 @@ void CMeterBar::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0); m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
if (m_NeedsReload || if (m_NeedsReload ||
m_Image.IsConfigsChanged()) m_Image.IsOptionsChanged())
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }

View File

@ -174,7 +174,7 @@ void CMeterBitmap::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_Image.ClearConfigFlags(); m_Image.ClearOptionFlags();
} }
m_FrameCount = parser.ReadInt(section, L"BitmapFrames", 1); m_FrameCount = parser.ReadInt(section, L"BitmapFrames", 1);
@ -209,7 +209,7 @@ void CMeterBitmap::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0); m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
if (m_NeedsReload || if (m_NeedsReload ||
m_Image.IsConfigsChanged()) m_Image.IsOptionsChanged())
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }

View File

@ -146,7 +146,7 @@ void CMeterButton::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_Image.ClearConfigFlags(); m_Image.ClearOptionFlags();
} }
m_Command = parser.ReadString(section, L"ButtonCommand", L"", false); m_Command = parser.ReadString(section, L"ButtonCommand", L"", false);
@ -156,7 +156,7 @@ void CMeterButton::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0); m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
if (m_NeedsReload || if (m_NeedsReload ||
m_Image.IsConfigsChanged()) m_Image.IsOptionsChanged())
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }

View File

@ -26,9 +26,9 @@ using namespace Gdiplus;
extern CRainmeter* Rainmeter; extern CRainmeter* Rainmeter;
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_PrimaryConfigArray, L"Primary"); CTintedImageHelper_DefineOptionArray(CMeterHistogram::c_PrimaryOptionArray, L"Primary");
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_SecondaryConfigArray, L"Secondary"); CTintedImageHelper_DefineOptionArray(CMeterHistogram::c_SecondaryOptionArray, L"Secondary");
CTintedImageHelper_DefineConfigArray(CMeterHistogram::c_BothConfigArray, L"Both"); CTintedImageHelper_DefineOptionArray(CMeterHistogram::c_BothOptionArray, L"Both");
/* /*
** The constructor ** The constructor
@ -42,9 +42,9 @@ CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow, const WCHAR* name) :
m_MeterPos(), m_MeterPos(),
m_Autoscale(false), m_Autoscale(false),
m_Flip(false), m_Flip(false),
m_PrimaryImage(L"PrimaryImage", c_PrimaryConfigArray), m_PrimaryImage(L"PrimaryImage", c_PrimaryOptionArray),
m_SecondaryImage(L"SecondaryImage", c_SecondaryConfigArray), m_SecondaryImage(L"SecondaryImage", c_SecondaryOptionArray),
m_OverlapImage(L"BothImage", c_BothConfigArray), m_OverlapImage(L"BothImage", c_BothOptionArray),
m_PrimaryNeedsReload(false), m_PrimaryNeedsReload(false),
m_SecondaryNeedsReload(false), m_SecondaryNeedsReload(false),
m_OverlapNeedsReload(false), m_OverlapNeedsReload(false),
@ -217,7 +217,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_PrimaryImage.ClearConfigFlags(); m_PrimaryImage.ClearOptionFlags();
} }
m_SecondaryImageName = parser.ReadString(section, L"SecondaryImage", L""); m_SecondaryImageName = parser.ReadString(section, L"SecondaryImage", L"");
@ -230,7 +230,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_SecondaryImage.ClearConfigFlags(); m_SecondaryImage.ClearOptionFlags();
} }
m_OverlapImageName = parser.ReadString(section, L"BothImage", L""); m_OverlapImageName = parser.ReadString(section, L"BothImage", L"");
@ -243,7 +243,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_OverlapImage.ClearConfigFlags(); m_OverlapImage.ClearOptionFlags();
} }
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0); m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
@ -272,9 +272,9 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_PrimaryNeedsReload || if (m_PrimaryNeedsReload ||
m_SecondaryNeedsReload || m_SecondaryNeedsReload ||
m_OverlapNeedsReload || m_OverlapNeedsReload ||
m_PrimaryImage.IsConfigsChanged() || m_PrimaryImage.IsOptionsChanged() ||
m_SecondaryImage.IsConfigsChanged() || m_SecondaryImage.IsOptionsChanged() ||
m_OverlapImage.IsConfigsChanged()) m_OverlapImage.IsOptionsChanged())
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }

View File

@ -76,9 +76,9 @@ private:
bool m_GraphStartLeft; bool m_GraphStartLeft;
bool m_GraphHorizontalOrientation; bool m_GraphHorizontalOrientation;
static const WCHAR* c_PrimaryConfigArray[CTintedImage::ConfigCount]; static const WCHAR* c_PrimaryOptionArray[CTintedImage::ConfigCount];
static const WCHAR* c_SecondaryConfigArray[CTintedImage::ConfigCount]; static const WCHAR* c_SecondaryOptionArray[CTintedImage::ConfigCount];
static const WCHAR* c_BothConfigArray[CTintedImage::ConfigCount]; static const WCHAR* c_BothOptionArray[CTintedImage::ConfigCount];
}; };
#endif #endif

View File

@ -94,7 +94,7 @@ void CMeterRotator::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
m_Image.ClearConfigFlags(); m_Image.ClearOptionFlags();
} }
m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0); m_OffsetX = parser.ReadFloat(section, L"OffsetX", 0.0);
@ -110,7 +110,7 @@ void CMeterRotator::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0); m_NeedsReload = (wcscmp(oldImageName.c_str(), m_ImageName.c_str()) != 0);
if (m_NeedsReload || if (m_NeedsReload ||
m_Image.IsConfigsChanged()) m_Image.IsOptionsChanged())
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }

View File

@ -143,7 +143,7 @@ const Gdiplus::ColorMatrix CTintedImage::c_IdentityMatrix = {
0.0f, 0.0f, 0.0f, 0.0f, 1.0f 0.0f, 0.0f, 0.0f, 0.0f, 1.0f
}; };
CTintedImageHelper_DefineConfigArray(CTintedImage::c_DefaultConfigArray, L""); CTintedImageHelper_DefineOptionArray(CTintedImage::c_DefaultOptionArray, L"");
/* /*
** The constructor. ** The constructor.
@ -154,8 +154,8 @@ CTintedImageHelper_DefineConfigArray(CTintedImage::c_DefaultConfigArray, L"");
** **
*/ */
CTintedImage::CTintedImage(const WCHAR* name, const WCHAR** configArray, bool disableTransform) : m_DisableTransform(disableTransform), CTintedImage::CTintedImage(const WCHAR* name, const WCHAR** configArray, bool disableTransform) : m_DisableTransform(disableTransform),
m_ConfigName(name ? name : L"Image"), m_Name(name ? name : L"Image"),
m_ConfigArray(configArray ? configArray : c_DefaultConfigArray), m_OptionArray(configArray ? configArray : c_DefaultOptionArray),
m_Bitmap(), m_Bitmap(),
m_BitmapTint(), m_BitmapTint(),
@ -326,7 +326,7 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
} }
else else
{ {
LogWithArgs(LOG_ERROR, L"%s: Unable to load: %s", m_ConfigName.c_str(), filename.c_str()); LogWithArgs(LOG_ERROR, L"%s: Unable to load: %s", m_Name, filename.c_str());
} }
} }
CloseHandle(fileHandle); CloseHandle(fileHandle);
@ -358,7 +358,7 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
} }
else else
{ {
LogWithArgs(LOG_ERROR, L"%s: Unable to open: %s", m_ConfigName.c_str(), filename.c_str()); LogWithArgs(LOG_ERROR, L"%s: Unable to open: %s", m_Name, filename.c_str());
if (fileHandle != INVALID_HANDLE_VALUE) if (fileHandle != INVALID_HANDLE_VALUE)
{ {
@ -581,7 +581,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_Crop.X = m_Crop.Y = m_Crop.Width = m_Crop.Height = -1; m_Crop.X = m_Crop.Y = m_Crop.Width = m_Crop.Height = -1;
m_CropMode = CROPMODE_TL; m_CropMode = CROPMODE_TL;
const std::wstring& crop = parser.ReadString(section, m_ConfigArray[ConfigIndexImageCrop], L""); const std::wstring& crop = parser.ReadString(section, m_OptionArray[OptionIndexImageCrop], L"");
if (!crop.empty()) if (!crop.empty())
{ {
if (wcschr(crop.c_str(), L',')) if (wcschr(crop.c_str(), L','))
@ -624,17 +624,17 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C) if (m_CropMode < CROPMODE_TL || m_CropMode > CROPMODE_C)
{ {
m_CropMode = CROPMODE_TL; m_CropMode = CROPMODE_TL;
LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_ConfigArray[ConfigIndexImageCrop], crop, section); LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_OptionArray[OptionIndexImageCrop], crop, section);
} }
} }
} }
m_NeedsCrop = (oldCrop.X != m_Crop.X || oldCrop.Y != m_Crop.Y || oldCrop.Width != m_Crop.Width || oldCrop.Height != m_Crop.Height || oldCropMode != m_CropMode); m_NeedsCrop = (oldCrop.X != m_Crop.X || oldCrop.Y != m_Crop.Y || oldCrop.Width != m_Crop.Width || oldCrop.Height != m_Crop.Height || oldCropMode != m_CropMode);
m_GreyScale = 0!=parser.ReadInt(section, m_ConfigArray[ConfigIndexGreyscale], 0); m_GreyScale = 0!=parser.ReadInt(section, m_OptionArray[OptionIndexGreyscale], 0);
Color tint = parser.ReadColor(section, m_ConfigArray[ConfigIndexImageTint], Color::White); Color tint = parser.ReadColor(section, m_OptionArray[OptionIndexImageTint], Color::White);
int alpha = parser.ReadInt(section, m_ConfigArray[ConfigIndexImageAlpha], tint.GetAlpha()); // for backwards compatibility int alpha = parser.ReadInt(section, m_OptionArray[OptionIndexImageAlpha], tint.GetAlpha()); // for backwards compatibility
alpha = min(255, alpha); alpha = min(255, alpha);
alpha = max(0, alpha); alpha = max(0, alpha);
@ -644,7 +644,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
// It has to be read in like this because it crashes when reading over 17 floats // It has to be read in like this because it crashes when reading over 17 floats
// at one time. The parser does it fine, but after putting the returned values // at one time. The parser does it fine, but after putting the returned values
// into the Color Matrix the next time the parser is used it crashes. // into the Color Matrix the next time the parser is used it crashes.
std::vector<Gdiplus::REAL> matrix1 = parser.ReadFloats(section, m_ConfigArray[ConfigIndexColorMatrix1]); std::vector<Gdiplus::REAL> matrix1 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix1]);
if (matrix1.size() == 5) if (matrix1.size() == 5)
{ {
for (int i = 0; i < 4; ++i) // The fifth column must be 0. for (int i = 0; i < 4; ++i) // The fifth column must be 0.
@ -657,7 +657,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ColorMatrix->m[0][0] = (REAL)tint.GetRed() / 255.0f; m_ColorMatrix->m[0][0] = (REAL)tint.GetRed() / 255.0f;
} }
std::vector<Gdiplus::REAL> matrix2 = parser.ReadFloats(section, m_ConfigArray[ConfigIndexColorMatrix2]); std::vector<Gdiplus::REAL> matrix2 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix2]);
if (matrix2.size() == 5) if (matrix2.size() == 5)
{ {
for (int i = 0; i < 4; ++i) // The fifth column must be 0. for (int i = 0; i < 4; ++i) // The fifth column must be 0.
@ -670,7 +670,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ColorMatrix->m[1][1] = (REAL)tint.GetGreen() / 255.0f; m_ColorMatrix->m[1][1] = (REAL)tint.GetGreen() / 255.0f;
} }
std::vector<Gdiplus::REAL> matrix3 = parser.ReadFloats(section, m_ConfigArray[ConfigIndexColorMatrix3]); std::vector<Gdiplus::REAL> matrix3 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix3]);
if (matrix3.size() == 5) if (matrix3.size() == 5)
{ {
for (int i = 0; i < 4; ++i) // The fifth column must be 0. for (int i = 0; i < 4; ++i) // The fifth column must be 0.
@ -683,7 +683,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ColorMatrix->m[2][2] = (REAL)tint.GetBlue() / 255.0f; m_ColorMatrix->m[2][2] = (REAL)tint.GetBlue() / 255.0f;
} }
std::vector<Gdiplus::REAL> matrix4 = parser.ReadFloats(section, m_ConfigArray[ConfigIndexColorMatrix4]); std::vector<Gdiplus::REAL> matrix4 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix4]);
if (matrix4.size() == 5) if (matrix4.size() == 5)
{ {
for (int i = 0; i < 4; ++i) // The fifth column must be 0. for (int i = 0; i < 4; ++i) // The fifth column must be 0.
@ -696,7 +696,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ColorMatrix->m[3][3] = (REAL)alpha / 255.0f; m_ColorMatrix->m[3][3] = (REAL)alpha / 255.0f;
} }
std::vector<Gdiplus::REAL> matrix5 = parser.ReadFloats(section, m_ConfigArray[ConfigIndexColorMatrix5]); std::vector<Gdiplus::REAL> matrix5 = parser.ReadFloats(section, m_OptionArray[OptionIndexColorMatrix5]);
if (matrix5.size() == 5) if (matrix5.size() == 5)
{ {
for (int i = 0; i < 4; ++i) // The fifth column must be 1. for (int i = 0; i < 4; ++i) // The fifth column must be 1.
@ -707,7 +707,7 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(&oldColorMatrix, m_ColorMatrix)); m_NeedsTinting = (oldGreyScale != m_GreyScale || !CompareColorMatrix(&oldColorMatrix, m_ColorMatrix));
const WCHAR* flip = parser.ReadString(section, m_ConfigArray[ConfigIndexImageFlip], L"NONE").c_str(); const WCHAR* flip = parser.ReadString(section, m_OptionArray[OptionIndexImageFlip], L"NONE").c_str();
if (_wcsicmp(flip, L"NONE") == 0) if (_wcsicmp(flip, L"NONE") == 0)
{ {
m_Flip = RotateNoneFlipNone; m_Flip = RotateNoneFlipNone;
@ -726,12 +726,12 @@ void CTintedImage::ReadConfig(CConfigParser& parser, const WCHAR* section)
} }
else else
{ {
LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_ConfigArray[ConfigIndexImageFlip], flip, section); LogWithArgs(LOG_ERROR, L"%s=%s (origin) is not valid in [%s]", m_OptionArray[OptionIndexImageFlip], flip, section);
} }
if (!m_DisableTransform) if (!m_DisableTransform)
{ {
m_Rotate = (REAL)parser.ReadFloat(section, m_ConfigArray[ConfigIndexImageRotate], 0.0); m_Rotate = (REAL)parser.ReadFloat(section, m_OptionArray[OptionIndexImageRotate], 0.0);
} }
m_NeedsTransform = (oldFlip != m_Flip || oldRotate != m_Rotate); m_NeedsTransform = (oldFlip != m_Flip || oldRotate != m_Rotate);

View File

@ -28,7 +28,7 @@
** It's necessary to give a string literal to the prefix parameter. ** It's necessary to give a string literal to the prefix parameter.
** **
*/ */
#define CTintedImageHelper_DefineConfigArray(name, prefix) \ #define CTintedImageHelper_DefineOptionArray(name, prefix) \
const WCHAR* (name)[CTintedImage::ConfigCount] = { \ const WCHAR* (name)[CTintedImage::ConfigCount] = { \
prefix L"ImageCrop", \ prefix L"ImageCrop", \
prefix L"Greyscale", \ prefix L"Greyscale", \
@ -48,32 +48,32 @@ class CConfigParser;
class CTintedImage class CTintedImage
{ {
public: public:
enum ConfigIndex enum OptionIndex
{ {
ConfigIndexImageCrop = 0, OptionIndexImageCrop = 0,
ConfigIndexGreyscale, OptionIndexGreyscale,
ConfigIndexImageTint, OptionIndexImageTint,
ConfigIndexImageAlpha, OptionIndexImageAlpha,
ConfigIndexColorMatrix1, OptionIndexColorMatrix1,
ConfigIndexColorMatrix2, OptionIndexColorMatrix2,
ConfigIndexColorMatrix3, OptionIndexColorMatrix3,
ConfigIndexColorMatrix4, OptionIndexColorMatrix4,
ConfigIndexColorMatrix5, OptionIndexColorMatrix5,
ConfigIndexImageFlip, OptionIndexImageFlip,
ConfigIndexImageRotate, OptionIndexImageRotate,
ConfigCount ConfigCount
}; };
CTintedImage(const WCHAR* name = L"Image", const WCHAR** configArray = c_DefaultConfigArray, bool disableTransform = false); CTintedImage(const WCHAR* name = L"Image", const WCHAR** configArray = c_DefaultOptionArray, bool disableTransform = false);
~CTintedImage(); ~CTintedImage();
void ReadConfig(CConfigParser& parser, const WCHAR* section); void ReadConfig(CConfigParser& parser, const WCHAR* section);
bool IsLoaded() { return (m_Bitmap != NULL); } bool IsLoaded() { return (m_Bitmap != NULL); }
bool IsTinted() { return (m_BitmapTint != NULL); } bool IsTinted() { return (m_BitmapTint != NULL); }
bool IsConfigsChanged() { return m_NeedsCrop || m_NeedsTinting || m_NeedsTransform; } bool IsOptionsChanged() { return m_NeedsCrop || m_NeedsTinting || m_NeedsTransform; }
void ClearConfigFlags() { m_NeedsCrop = m_NeedsTinting = m_NeedsTransform = false; } void ClearOptionFlags() { m_NeedsCrop = m_NeedsTinting = m_NeedsTransform = false; }
Gdiplus::Bitmap* GetOriginalImage() { return m_Bitmap; } Gdiplus::Bitmap* GetOriginalImage() { return m_Bitmap; }
Gdiplus::Bitmap* GetTintedImage() { return m_BitmapTint; } Gdiplus::Bitmap* GetTintedImage() { return m_BitmapTint; }
@ -104,8 +104,8 @@ protected:
Gdiplus::Bitmap* m_Bitmap; Gdiplus::Bitmap* m_Bitmap;
Gdiplus::Bitmap* m_BitmapTint; // Tinted bitmap Gdiplus::Bitmap* m_BitmapTint; // Tinted bitmap
const std::wstring m_ConfigName; const WCHAR* m_Name;
const WCHAR** m_ConfigArray; const WCHAR** m_OptionArray;
const bool m_DisableTransform; const bool m_DisableTransform;
bool m_NeedsCrop; bool m_NeedsCrop;
@ -124,7 +124,7 @@ protected:
static const Gdiplus::ColorMatrix c_GreyScaleMatrix; static const Gdiplus::ColorMatrix c_GreyScaleMatrix;
static const Gdiplus::ColorMatrix c_IdentityMatrix; static const Gdiplus::ColorMatrix c_IdentityMatrix;
static const WCHAR* c_DefaultConfigArray[ConfigCount]; static const WCHAR* c_DefaultOptionArray[ConfigCount];
}; };
#endif #endif