Fixed the issue that dynamic image name is not correctly applied in most meters. (Issue 157) An error message is now output to the log instead of showing the dialog box.

This commit is contained in:
spx 2010-06-03 14:14:53 +00:00
parent 7a919f35fc
commit c7cd612502
7 changed files with 256 additions and 69 deletions

View File

@ -72,20 +72,25 @@ void CMeterBar::Initialize()
Status status = m_Bitmap->GetLastStatus(); Status status = m_Bitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap; delete m_Bitmap;
m_Bitmap = NULL; m_Bitmap = NULL;
throw CError(std::wstring(L"Bitmap image not found: ") + m_ImageName, __LINE__, __FILE__);
}
m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight();
} }
else else
{ {
if (m_Bitmap != NULL) delete m_Bitmap; m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight();
}
}
else
{
if (m_Bitmap)
{
delete m_Bitmap;
m_Bitmap = NULL; m_Bitmap = NULL;
} }
}
} }
/* /*

View File

@ -75,12 +75,13 @@ void CMeterBitmap::Initialize()
Status status = m_Bitmap->GetLastStatus(); Status status = m_Bitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap; delete m_Bitmap;
m_Bitmap = NULL; m_Bitmap = NULL;
throw CError(std::wstring(L"Bitmap image not found: ") + m_ImageName, __LINE__, __FILE__);
} }
else
{
m_W = m_Bitmap->GetWidth(); m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight(); m_H = m_Bitmap->GetHeight();
@ -93,6 +94,15 @@ void CMeterBitmap::Initialize()
m_W = m_W / m_FrameCount; m_W = m_W / m_FrameCount;
} }
} }
}
else
{
if (m_Bitmap)
{
delete m_Bitmap;
m_Bitmap = NULL;
}
}
} }
/* /*
@ -167,6 +177,8 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
{ {
// Store the current values so we know if the image needs to be updated // Store the current values so we know if the image needs to be updated
std::wstring oldImageName = m_ImageName; std::wstring oldImageName = m_ImageName;
int oldW = m_W;
int oldH = m_H;
// Read common configs // Read common configs
CMeter::ReadConfig(section); CMeter::ReadConfig(section);
@ -205,11 +217,19 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
throw CError(std::wstring(L"No such BitmapAlign: ") + align, __LINE__, __FILE__); throw CError(std::wstring(L"No such BitmapAlign: ") + align, __LINE__, __FILE__);
} }
if (m_Initialized && if (m_Initialized)
oldImageName != m_ImageName) {
if (oldImageName != m_ImageName)
{ {
Initialize(); // Reload the image Initialize(); // Reload the image
} }
else
{
// Reset to old dimensions
m_W = oldW;
m_H = oldH;
}
}
} }
/* /*

View File

@ -88,17 +88,17 @@ void CMeterButton::Initialize()
} }
} }
if (m_Bitmap != NULL) delete m_Bitmap; if (m_Bitmap != NULL) delete m_Bitmap;
m_Bitmap = new Bitmap(m_ImageName.c_str()); m_Bitmap = new Bitmap(m_ImageName.c_str());
Status status = m_Bitmap->GetLastStatus(); Status status = m_Bitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap; delete m_Bitmap;
m_Bitmap = NULL; m_Bitmap = NULL;
throw CError(std::wstring(L"Bitmap image not found: ") + m_ImageName, __LINE__, __FILE__);
} }
else
{
m_W = m_Bitmap->GetWidth(); m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight(); m_H = m_Bitmap->GetHeight();
@ -131,6 +131,23 @@ void CMeterButton::Initialize()
m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics); m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics);
} }
} }
}
else
{
for (int i = 0; i < BUTTON_FRAMES; ++i)
{
if (m_Bitmaps[i])
{
delete m_Bitmaps[i];
m_Bitmaps[i] = NULL;
}
}
if (m_Bitmap)
{
delete m_Bitmap;
m_Bitmap = NULL;
}
}
} }
/* /*

View File

@ -50,6 +50,7 @@ CMeterHistogram::CMeterHistogram(CMeterWindow* meterWindow) : CMeter(meterWindow
m_MinPrimaryValue = 0.0; m_MinPrimaryValue = 0.0;
m_MaxSecondaryValue = 1.0; m_MaxSecondaryValue = 1.0;
m_MinSecondaryValue = 0.0; m_MinSecondaryValue = 0.0;
m_WidthChanged = false;
} }
/* /*
@ -86,11 +87,31 @@ void CMeterHistogram::Initialize()
Status status = m_PrimaryBitmap->GetLastStatus(); Status status = m_PrimaryBitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
throw CError(std::wstring(L"PrimaryImage not found: ") + m_PrimaryImageName, __LINE__, __FILE__); DebugLog(L"PrimaryImage not found: %s", m_PrimaryImageName.c_str());
delete m_PrimaryBitmap;
m_PrimaryBitmap = NULL;
} }
else
{
int oldW = m_W;
m_W = m_PrimaryBitmap->GetWidth(); m_W = m_PrimaryBitmap->GetWidth();
m_H = m_PrimaryBitmap->GetHeight(); m_H = m_PrimaryBitmap->GetHeight();
if (oldW != m_W)
{
m_WidthChanged = true;
}
}
}
else
{
if (m_PrimaryBitmap)
{
delete m_PrimaryBitmap;
m_PrimaryBitmap = NULL;
}
} }
if(!m_SecondaryImageName.empty()) if(!m_SecondaryImageName.empty())
@ -100,7 +121,18 @@ void CMeterHistogram::Initialize()
Status status = m_SecondaryBitmap->GetLastStatus(); Status status = m_SecondaryBitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
throw CError(std::wstring(L"SecondaryImage not found: ") + m_SecondaryImageName, __LINE__, __FILE__); DebugLog(L"SecondaryImage not found: %s", m_SecondaryImageName.c_str());
delete m_SecondaryBitmap;
m_SecondaryBitmap = NULL;
}
}
else
{
if (m_SecondaryBitmap)
{
delete m_SecondaryBitmap;
m_SecondaryBitmap = NULL;
} }
} }
@ -111,15 +143,68 @@ void CMeterHistogram::Initialize()
Status status = m_BothBitmap->GetLastStatus(); Status status = m_BothBitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{ {
throw CError(std::wstring(L"BothImage not found: ") + m_BothImageName, __LINE__, __FILE__); DebugLog(L"BothImage not found: %s", m_BothImageName.c_str());
delete m_BothBitmap;
m_BothBitmap = NULL;
}
}
else
{
if (m_BothBitmap)
{
delete m_BothBitmap;
m_BothBitmap = NULL;
} }
} }
// A sanity check // A sanity check
if (m_SecondaryMeasure && !m_PrimaryImageName.empty() && (m_BothImageName.empty() || m_SecondaryImageName.empty())) if (m_SecondaryMeasure && !m_PrimaryImageName.empty() && (m_BothImageName.empty() || m_SecondaryImageName.empty()))
{ {
throw CError(std::wstring(L"You need to define SecondaryImage and BothImage also!"), __LINE__, __FILE__); LSLog(LOG_DEBUG, L"Rainmeter", L"You need to define SecondaryImage and BothImage also!");
if (m_PrimaryBitmap)
{
delete m_PrimaryBitmap;
m_PrimaryBitmap = NULL;
} }
if (m_SecondaryBitmap)
{
delete m_SecondaryBitmap;
m_SecondaryBitmap = NULL;
}
if (m_BothBitmap)
{
delete m_BothBitmap;
m_BothBitmap = NULL;
}
}
if ((!m_PrimaryImageName.empty() && !m_PrimaryBitmap) ||
(!m_SecondaryImageName.empty() && !m_SecondaryBitmap) ||
(!m_BothImageName.empty() && !m_BothBitmap))
{
// Reset current position
m_MeterPos = 0;
// Delete buffers
if (m_PrimaryValues)
{
delete [] m_PrimaryValues;
m_PrimaryValues = NULL;
}
if (m_SecondaryValues)
{
delete [] m_SecondaryValues;
m_SecondaryValues = NULL;
}
m_WidthChanged = false;
}
else if (m_WidthChanged)
{
// Reset current position
m_MeterPos = 0;
// Create buffers for values // Create buffers for values
if (m_PrimaryValues) delete [] m_PrimaryValues; if (m_PrimaryValues) delete [] m_PrimaryValues;
@ -131,6 +216,9 @@ void CMeterHistogram::Initialize()
m_SecondaryValues = new double[m_W]; m_SecondaryValues = new double[m_W];
memset(m_SecondaryValues, 0, sizeof(double) * m_W); memset(m_SecondaryValues, 0, sizeof(double) * m_W);
} }
m_WidthChanged = false;
}
} }
/* /*
@ -141,6 +229,13 @@ void CMeterHistogram::Initialize()
*/ */
void CMeterHistogram::ReadConfig(const WCHAR* section) void CMeterHistogram::ReadConfig(const WCHAR* section)
{ {
// Store the current values so we know if the image needs to be updated
std::wstring oldPrimaryImageName = m_PrimaryImageName;
std::wstring oldSecondaryImageName = m_SecondaryImageName;
std::wstring oldBothImageName = m_BothImageName;
int oldW = m_W;
int oldH = m_H;
// Read common configs // Read common configs
CMeter::ReadConfig(section); CMeter::ReadConfig(section);
@ -163,6 +258,31 @@ void CMeterHistogram::ReadConfig(const WCHAR* section)
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0); m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 0);
m_Flip = 0!=parser.ReadInt(section, L"Flip", 0); m_Flip = 0!=parser.ReadInt(section, L"Flip", 0);
if (m_Initialized)
{
if (m_PrimaryImageName.empty())
{
if (oldW != m_W)
{
m_WidthChanged = true;
Initialize(); // Reload the image
}
}
else
{
// Reset to old dimensions
m_W = oldW;
m_H = oldH;
if (oldPrimaryImageName != m_PrimaryImageName ||
oldSecondaryImageName != m_SecondaryImageName ||
oldBothImageName != m_BothImageName)
{
Initialize(); // Reload the image
}
}
}
} }
/* /*
@ -173,12 +293,12 @@ void CMeterHistogram::ReadConfig(const WCHAR* section)
*/ */
bool CMeterHistogram::Update() bool CMeterHistogram::Update()
{ {
if (CMeter::Update() && m_Measure) if (CMeter::Update() && m_Measure && m_PrimaryValues)
{ {
// Gather values // Gather values
m_PrimaryValues[m_MeterPos] = m_Measure->GetValue(); m_PrimaryValues[m_MeterPos] = m_Measure->GetValue();
if (m_SecondaryMeasure != NULL) if (m_SecondaryMeasure && m_SecondaryValues)
{ {
m_SecondaryValues[m_MeterPos] = m_SecondaryMeasure->GetValue(); m_SecondaryValues[m_MeterPos] = m_SecondaryMeasure->GetValue();
} }
@ -213,7 +333,7 @@ bool CMeterHistogram::Update()
m_MaxPrimaryValue *= 2; m_MaxPrimaryValue *= 2;
} }
if (m_SecondaryMeasure) if (m_SecondaryMeasure && m_SecondaryValues)
{ {
for (int i = 0; i != m_W; ++i) for (int i = 0; i != m_W; ++i)
{ {
@ -241,7 +361,9 @@ bool CMeterHistogram::Update()
*/ */
bool CMeterHistogram::Draw(Graphics& graphics) bool CMeterHistogram::Draw(Graphics& graphics)
{ {
if(!CMeter::Draw(graphics)) return false; if(!CMeter::Draw(graphics) ||
(m_Measure && !m_PrimaryValues) ||
(m_SecondaryMeasure && !m_SecondaryValues)) return false;
Pen primaryPen(m_PrimaryColor); Pen primaryPen(m_PrimaryColor);
Pen secondaryPen(m_SecondaryColor); Pen secondaryPen(m_SecondaryColor);

View File

@ -60,6 +60,8 @@ private:
double m_MinPrimaryValue; double m_MinPrimaryValue;
double m_MaxSecondaryValue; double m_MaxSecondaryValue;
double m_MinSecondaryValue; double m_MinSecondaryValue;
bool m_WidthChanged;
}; };
#endif #endif

View File

@ -250,6 +250,19 @@ void CMeterImage::LoadImage(bool bLoadAlways)
} }
} }
} }
else
{
if (m_Bitmap)
{
delete m_Bitmap;
m_Bitmap = NULL;
}
if (m_BitmapTint)
{
delete m_BitmapTint;
m_BitmapTint = NULL;
}
}
} }
/* /*

View File

@ -67,11 +67,19 @@ void CMeterRotator::Initialize()
m_Bitmap = new Bitmap(m_ImageName.c_str()); m_Bitmap = new Bitmap(m_ImageName.c_str());
Status status = m_Bitmap->GetLastStatus(); Status status = m_Bitmap->GetLastStatus();
if(Ok != status) if(Ok != status)
{
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap;
m_Bitmap = NULL;
}
}
else
{
if (m_Bitmap)
{ {
delete m_Bitmap; delete m_Bitmap;
m_Bitmap = NULL; m_Bitmap = NULL;
throw CError(std::wstring(L"Bitmap image not found: ") + m_ImageName, __LINE__, __FILE__);
} }
} }
} }