Minor tweaks.

This commit is contained in:
spx 2011-11-28 14:13:20 +00:00
parent c0cc3f2e70
commit f28ecf6e83
17 changed files with 86 additions and 80 deletions

View File

@ -790,7 +790,7 @@ bool CConfigParser::ParseFormula(const std::wstring& result, double* resultValue
return false;
}
Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, const Color& defValue)
ARGB CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, ARGB defValue)
{
const std::wstring& result = ReadString(section, key, L"");

View File

@ -69,7 +69,7 @@ public:
double ReadFormula(LPCTSTR section, LPCTSTR key, double defValue);
int ReadInt(LPCTSTR section, LPCTSTR key, int defValue);
unsigned int ReadUInt(LPCTSTR section, LPCTSTR key, unsigned int defValue);
Gdiplus::Color ReadColor(LPCTSTR section, LPCTSTR key, const Gdiplus::Color& defValue);
Gdiplus::ARGB ReadColor(LPCTSTR section, LPCTSTR key, Gdiplus::ARGB defValue);
Gdiplus::Rect ReadRect(LPCTSTR section, LPCTSTR key, const Gdiplus::Rect& defValue);
RECT ReadRECT(LPCTSTR section, LPCTSTR key, const RECT& defValue);
std::vector<Gdiplus::REAL> ReadFloats(LPCTSTR section, LPCTSTR key);

View File

@ -134,11 +134,15 @@ void CMeasureScript::ReadConfig(CConfigParser& parser, const WCHAR* section)
// Read common configs
CMeasure::ReadConfig(parser, section);
const std::wstring& file = parser.ReadString(section, L"ScriptFile", L"");
std::wstring file = parser.ReadString(section, L"ScriptFile", L"");
if (!file.empty())
{
std::string scriptFile = ConvertToAscii(m_MeterWindow->MakePathAbsolute(file).c_str());
if (m_MeterWindow)
{
m_MeterWindow->MakePathAbsolute(file);
}
std::string scriptFile = ConvertToAscii(file.c_str());
if (!m_Initialized ||
strcmp(scriptFile.c_str(), m_ScriptFile.c_str()) != 0)

View File

@ -387,8 +387,8 @@ void CMeter::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_SolidBevel = (BEVELTYPE)parser.ReadInt(section, L"BevelType", BEVELTYPE_NONE);
m_SolidColor = parser.ReadColor(section, L"SolidColor", Color(0, 0, 0, 0));
m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor);
m_SolidColor = parser.ReadColor(section, L"SolidColor", Color::MakeARGB(0, 0, 0, 0));
m_SolidColor2 = parser.ReadColor(section, L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)parser.ReadFloat(section, L"GradientAngle", 0.0);
m_LeftMouseDownAction = parser.ReadString(section, L"LeftMouseDownAction", L"", false);

View File

@ -105,7 +105,7 @@ void CMeterBar::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"BarImage", L"");
if (!m_ImageName.empty())
{
m_ImageName = m_MeterWindow->MakePathAbsolute(m_ImageName);
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting configs
m_Image.ReadConfig(parser, section);

View File

@ -177,7 +177,7 @@ void CMeterBitmap::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"BitmapImage", L"");
if (!m_ImageName.empty())
{
m_ImageName = m_MeterWindow->MakePathAbsolute(m_ImageName);
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting configs
m_Image.ReadConfig(parser, section);

View File

@ -147,7 +147,7 @@ void CMeterButton::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"ButtonImage", L"");
if (!m_ImageName.empty())
{
m_ImageName = m_MeterWindow->MakePathAbsolute(m_ImageName);
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting configs
m_Image.ReadConfig(parser, section);

View File

@ -218,7 +218,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_PrimaryImageName = parser.ReadString(section, L"PrimaryImage", L"");
if (!m_PrimaryImageName.empty())
{
m_PrimaryImageName = m_MeterWindow->MakePathAbsolute(m_PrimaryImageName);
m_MeterWindow->MakePathAbsolute(m_PrimaryImageName);
// Read tinting configs
m_PrimaryImage.ReadConfig(parser, section);
@ -231,7 +231,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_SecondaryImageName = parser.ReadString(section, L"SecondaryImage", L"");
if (!m_SecondaryImageName.empty())
{
m_SecondaryImageName = m_MeterWindow->MakePathAbsolute(m_SecondaryImageName);
m_MeterWindow->MakePathAbsolute(m_SecondaryImageName);
// Read tinting configs
m_SecondaryImage.ReadConfig(parser, section);
@ -244,7 +244,7 @@ void CMeterHistogram::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_BothImageName = parser.ReadString(section, L"BothImage", L"");
if (!m_BothImageName.empty())
{
m_BothImageName = m_MeterWindow->MakePathAbsolute(m_BothImageName);
m_MeterWindow->MakePathAbsolute(m_BothImageName);
// Read tinting configs
m_BothImage.ReadConfig(parser, section);

View File

@ -65,7 +65,7 @@ void CMeterImage::Initialize()
{
m_ImageNameResult = m_Path;
m_ImageNameResult += m_ImageName;
m_ImageNameResult = m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
LoadImage(m_ImageNameResult, true);
}
}
@ -207,7 +207,7 @@ bool CMeterImage::Update()
if (!m_ImageNameResult.empty())
{
m_ImageNameResult.insert(0, m_Path);
m_ImageNameResult = m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
m_MeterWindow->MakePathAbsolute(m_ImageNameResult);
}
LoadImage(m_ImageNameResult, (wcscmp(oldResult.c_str(), m_ImageNameResult.c_str()) != 0));

View File

@ -158,8 +158,8 @@ void CMeterLine::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
m_LineWidth = parser.ReadFloat(section, L"LineWidth", 1.0);
m_HorizontalLines = 0!=parser.ReadInt(section, L"HorizontalLines", 0);
m_HorizontalColor = parser.ReadColor(section, L"HorizontalColor", Color::Black); // This is left here for backwards compatibility
m_HorizontalColor = parser.ReadColor(section, L"HorizontalLineColor", m_HorizontalColor); // This is what it should be
ARGB color = parser.ReadColor(section, L"HorizontalColor", Color::Black); // This is left here for backwards compatibility
m_HorizontalColor = parser.ReadColor(section, L"HorizontalLineColor", color); // This is what it should be
if (m_Initialized &&
(oldLineCount != lineCount ||

View File

@ -95,7 +95,7 @@ void CMeterRotator::ReadConfig(CConfigParser& parser, const WCHAR* section)
m_ImageName = parser.ReadString(section, L"ImageName", L"");
if (!m_ImageName.empty())
{
m_ImageName = m_MeterWindow->MakePathAbsolute(m_ImageName);
m_MeterWindow->MakePathAbsolute(m_ImageName);
// Read tinting configs
m_Image.ReadConfig(parser, section);

View File

@ -2120,7 +2120,7 @@ bool CMeterWindow::ReadSkin()
m_SolidBevel = (BEVELTYPE)m_Parser.ReadInt(L"Rainmeter", L"BevelType", BEVELTYPE_NONE);
m_SolidColor = m_Parser.ReadColor(L"Rainmeter", L"SolidColor", Color::Gray);
m_SolidColor2 = m_Parser.ReadColor(L"Rainmeter", L"SolidColor2", m_SolidColor);
m_SolidColor2 = m_Parser.ReadColor(L"Rainmeter", L"SolidColor2", m_SolidColor.GetValue());
m_SolidAngle = (Gdiplus::REAL)m_Parser.ReadFloat(L"Rainmeter", L"GradientAngle", 0.0);
m_DynamicWindowSize = 0!=m_Parser.ReadInt(L"Rainmeter", L"DynamicWindowSize", 0);
@ -2130,7 +2130,7 @@ bool CMeterWindow::ReadSkin()
m_BackgroundName = m_Parser.ReadString(L"Rainmeter", L"Background", L"");
if (!m_BackgroundName.empty())
{
m_BackgroundName = MakePathAbsolute(m_BackgroundName);
MakePathAbsolute(m_BackgroundName);
}
else
{
@ -5076,23 +5076,22 @@ void CMeterWindow::SetWindowSizeVariables(int w, int h)
** Converts the path to absolute by adding the skin's path to it (unless it already is absolute).
**
*/
std::wstring CMeterWindow::MakePathAbsolute(const std::wstring& path)
void CMeterWindow::MakePathAbsolute(std::wstring& path)
{
std::wstring absolute;
if (path.empty() || CSystem::IsAbsolutePath(path))
{
absolute = path; // It's already absolute path (or it's empty)
return; // It's already absolute path (or it's empty)
}
else
{
std::wstring absolute;
absolute.reserve(m_SkinPath.size() + m_SkinName.size() + 1 + path.size());
absolute = m_SkinPath;
absolute += m_SkinName;
absolute += L"\\";
absolute += path;
absolute.swap(path);
}
return absolute;
}
std::wstring CMeterWindow::GetSkinRootPath()

View File

@ -243,7 +243,7 @@ public:
LRESULT OnCopyData(UINT uMsg, WPARAM wParam, LPARAM lParam);
std::wstring MakePathAbsolute(const std::wstring& path);
void MakePathAbsolute(std::wstring& path);
Gdiplus::PrivateFontCollection* GetPrivateFontCollection() { return m_FontCollection; }

View File

@ -25,42 +25,28 @@
using namespace Gdiplus;
class ImageCache
{
public:
ImageCache(Bitmap* bitmap) : m_Bitmap(bitmap), m_Ref(1) {}
~ImageCache() { Dispose(); }
void AddRef() { ++m_Ref; }
void Release() { if (m_Ref > 0) { --m_Ref; } if (m_Ref == 0) { Dispose(); } }
bool IsInvalid() { return m_Ref == 0; }
//int GetRef() { return m_Ref; }
Bitmap* GetCache() { return m_Bitmap; }
private:
ImageCache() {}
ImageCache(const ImageCache& cache) {}
void Dispose() { delete m_Bitmap; m_Bitmap = NULL; }
Bitmap* m_Bitmap;
int m_Ref;
};
class ImageCachePool
{
public:
static std::wstring CreateKey(const std::wstring& fname, FILETIME ftime, DWORD fileSize)
static std::wstring CreateKey(const std::wstring& name, ULONGLONG time, DWORD size)
{
std::wstring key;
WCHAR buffer[MAX_PATH];
if (PathCanonicalize(buffer, name.c_str()))
{
key = buffer;
}
else
{
key = name;
}
std::transform(key.begin(), key.end(), key.begin(), ::towlower);
std::wstring key = (PathCanonicalize(buffer, fname.c_str())) ? buffer : fname;
_snwprintf_s(buffer, _TRUNCATE, L":%x%08x:%x", ftime.dwHighDateTime, ftime.dwLowDateTime, fileSize);
_snwprintf_s(buffer, _TRUNCATE, L":%llx:%x", time, size);
key += buffer;
std::transform(key.begin(), key.end(), key.begin(), ::towlower);
return key;
}
@ -74,7 +60,7 @@ public:
return NULL;
}
static void AddCache(const std::wstring& key, ImageCache* cache)
static void AddCache(const std::wstring& key, Bitmap* bitmap)
{
std::unordered_map<std::wstring, ImageCache*>::const_iterator iter = c_CacheMap.find(key);
if (iter != c_CacheMap.end())
@ -82,10 +68,10 @@ public:
(*iter).second->AddRef();
//LogWithArgs(LOG_DEBUG, L"* ADD: key=%s, ref=%i", key.c_str(), (*iter).second->GetRef());
}
else if (cache)
else
{
c_CacheMap[key] = cache;
//LogWithArgs(LOG_DEBUG, L"* ADD: key=%s, ref=%i", key.c_str(), cache->GetRef());
c_CacheMap[key] = new ImageCache(bitmap);
//LogWithArgs(LOG_DEBUG, L"* ADD: key=%s, ref=new", key.c_str());
}
}
@ -108,9 +94,32 @@ public:
}
private:
class ImageCache
{
public:
ImageCache(Bitmap* bitmap) : m_Bitmap(bitmap), m_Ref(1) {}
~ImageCache() { Dispose(); }
void AddRef() { ++m_Ref; }
void Release() { if (m_Ref > 0) { --m_Ref; } if (m_Ref == 0) { Dispose(); } }
bool IsInvalid() { return m_Ref == 0; }
//int GetRef() { return m_Ref; }
Bitmap* GetCache() { return m_Bitmap; }
private:
ImageCache() {}
ImageCache(const ImageCache& cache) {}
void Dispose() { delete m_Bitmap; m_Bitmap = NULL; }
Bitmap* m_Bitmap;
int m_Ref;
};
static std::unordered_map<std::wstring, ImageCache*> c_CacheMap;
};
std::unordered_map<std::wstring, ImageCache*> ImageCachePool::c_CacheMap;
std::unordered_map<std::wstring, ImageCachePool::ImageCache*> ImageCachePool::c_CacheMap;
#define PI (3.14159265f)
@ -157,11 +166,10 @@ CTintedImage::CTintedImage(const WCHAR* name, const WCHAR** configArray, bool di
m_Crop(-1, -1, -1, -1),
m_CropMode(CROPMODE_TL),
m_GreyScale(false),
m_ColorMatrix(new ColorMatrix),
m_ColorMatrix(new ColorMatrix(c_IdentityMatrix)),
m_Flip(RotateNoneFlipNone),
m_Rotate()
{
*m_ColorMatrix = c_IdentityMatrix;
}
/*
@ -203,7 +211,7 @@ void CTintedImage::DisposeImage()
** Loads the image from file handle
**
*/
Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, ImageCache** ppCache)
Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize)
{
HGLOBAL hBuffer = ::GlobalAlloc(GMEM_MOVEABLE, fileSize);
if (hBuffer)
@ -236,10 +244,8 @@ Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize,
bitmap = clone;
::GlobalFree(hBuffer);
hBuffer = NULL;
}
////////////////////////////////////////////
*ppCache = new ImageCache(bitmap);
return bitmap;
}
@ -267,9 +273,8 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
std::wstring filename = imageName;
// Check extension and if it is missing, add .png
size_t pos = filename.find_last_of(L"\\");
if (pos == std::wstring::npos) pos = 0;
if (std::wstring::npos == filename.find(L'.', pos))
size_t pos = filename.rfind(L'\\');
if (filename.find(L'.', (pos == std::wstring::npos) ? 0 : pos + 1) == std::wstring::npos)
{
filename += L".png";
}
@ -280,25 +285,24 @@ void CTintedImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
if (fileHandle != INVALID_HANDLE_VALUE && (fileSize = GetFileSize(fileHandle, NULL)) != INVALID_FILE_SIZE)
{
// Compare the filename/timestamp/filesize to check if the file has been changed (don't load if it's not)
FILETIME tmpTime;
GetFileTime(fileHandle, NULL, NULL, &tmpTime);
std::wstring key = ImageCachePool::CreateKey(filename, tmpTime, fileSize);
ULONGLONG fileTime;
GetFileTime(fileHandle, NULL, NULL, (LPFILETIME)&fileTime);
std::wstring key = ImageCachePool::CreateKey(filename, fileTime, fileSize);
if (bLoadAlways || key != m_CacheKey)
if (bLoadAlways || wcscmp(key.c_str(), m_CacheKey.c_str()) != 0)
{
DisposeImage();
Bitmap* bitmap = ImageCachePool::GetCache(key);
ImageCache* cache = NULL;
m_Bitmap = (bitmap) ?
bitmap :
LoadImageFromFileHandle(fileHandle, fileSize, &cache);
LoadImageFromFileHandle(fileHandle, fileSize);
if (m_Bitmap)
{
m_CacheKey = key;
ImageCachePool::AddCache(key, cache);
ImageCachePool::AddCache(key, m_Bitmap);
// Check whether the new image needs tinting (or cropping, flipping, rotating)
if (!m_NeedsCrop)

View File

@ -46,7 +46,6 @@
};
class CConfigParser;
class ImageCache;
class CTintedImage
{
@ -99,7 +98,7 @@ protected:
void ApplyTint();
void ApplyTransform();
Gdiplus::Bitmap* LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, ImageCache** ppCache);
Gdiplus::Bitmap* LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize);
static Gdiplus::Bitmap* TurnGreyscale(Gdiplus::Bitmap* source);
static bool CompareColorMatrix(const Gdiplus::ColorMatrix* a, const Gdiplus::ColorMatrix* b);

View File

@ -342,8 +342,8 @@ void CTrayWindow::ReadConfig(CConfigParser& parser)
else if (_wcsicmp(type, L"HISTOGRAM") == 0)
{
m_MeterType = TRAY_METER_TYPE_HISTOGRAM;
m_TrayColor1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color(0, 100, 0));
m_TrayColor2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color(0, 255, 0));
m_TrayColor1 = parser.ReadColor(L"TrayMeasure", L"TrayColor1", Color::MakeARGB(255, 0, 100, 0));
m_TrayColor2 = parser.ReadColor(L"TrayMeasure", L"TrayColor2", Color::MakeARGB(255, 0, 255, 0));
}
else if (_wcsicmp(type, L"BITMAP") == 0)
{

View File

@ -82,10 +82,10 @@ static int MeterWindow_GetY(lua_State* L)
static int MeterWindow_MakePathAbsolute(lua_State* L)
{
CMeterWindow* self = (CMeterWindow*)tolua_tousertype(L, 1, 0);
const std::wstring path = LuaManager::ToWide(L, 2);
std::wstring path = LuaManager::ToWide(L, 2);
std::wstring val = self->MakePathAbsolute(path);
LuaManager::PushWide(L, val.c_str());
self->MakePathAbsolute(path);
LuaManager::PushWide(L, path.c_str());
return 1;
}