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,19 +72,24 @@ void CMeterBar::Initialize()
Status status = m_Bitmap->GetLastStatus();
if(Ok != status)
{
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap;
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
{
m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight();
}
}
else
{
if (m_Bitmap != NULL) delete m_Bitmap;
m_Bitmap = NULL;
if (m_Bitmap)
{
delete m_Bitmap;
m_Bitmap = NULL;
}
}
}

View File

@ -75,22 +75,32 @@ void CMeterBitmap::Initialize()
Status status = m_Bitmap->GetLastStatus();
if(Ok != status)
{
delete m_Bitmap;
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap;
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();
if(m_H > m_W)
{
m_H = m_H / m_FrameCount;
}
else
{
m_W = m_W / m_FrameCount;
m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight();
if(m_H > m_W)
{
m_H = m_H / m_FrameCount;
}
else
{
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
std::wstring oldImageName = m_ImageName;
int oldW = m_W;
int oldH = m_H;
// Read common configs
CMeter::ReadConfig(section);
@ -205,10 +217,18 @@ void CMeterBitmap::ReadConfig(const WCHAR* section)
throw CError(std::wstring(L"No such BitmapAlign: ") + align, __LINE__, __FILE__);
}
if (m_Initialized &&
oldImageName != m_ImageName)
if (m_Initialized)
{
Initialize(); // Reload the image
if (oldImageName != m_ImageName)
{
Initialize(); // Reload the image
}
else
{
// Reset to old dimensions
m_W = oldW;
m_H = oldH;
}
}
}

View File

@ -88,47 +88,64 @@ void CMeterButton::Initialize()
}
}
if (m_Bitmap != NULL) delete m_Bitmap;
m_Bitmap = new Bitmap(m_ImageName.c_str());
Status status = m_Bitmap->GetLastStatus();
if(Ok != status)
{
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap;
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();
if(m_H > m_W)
{
m_H = m_H / BUTTON_FRAMES;
}
else
{
m_W = m_W / BUTTON_FRAMES;
}
m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight();
// Separate the frames
Graphics desktopGraphics(GetDesktopWindow());
for (int i = 0; i < BUTTON_FRAMES; ++i)
{
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppARGB);
Graphics graphics(&bitmapPart);
Rect r(0, 0, m_W, m_H);
if(m_Bitmap->GetHeight() > m_Bitmap->GetWidth())
if(m_H > m_W)
{
graphics.DrawImage(m_Bitmap, r, 0, m_H * i, m_W, m_H, UnitPixel);
m_H = m_H / BUTTON_FRAMES;
}
else
{
graphics.DrawImage(m_Bitmap, r, m_W * i, 0, m_W, m_H, UnitPixel);
m_W = m_W / BUTTON_FRAMES;
}
m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics);
// Separate the frames
Graphics desktopGraphics(GetDesktopWindow());
for (int i = 0; i < BUTTON_FRAMES; ++i)
{
Bitmap bitmapPart(m_W, m_H, PixelFormat32bppARGB);
Graphics graphics(&bitmapPart);
Rect r(0, 0, m_W, m_H);
if(m_Bitmap->GetHeight() > m_Bitmap->GetWidth())
{
graphics.DrawImage(m_Bitmap, r, 0, m_H * i, m_W, m_H, UnitPixel);
}
else
{
graphics.DrawImage(m_Bitmap, r, m_W * i, 0, m_W, m_H, UnitPixel);
}
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_MaxSecondaryValue = 1.0;
m_MinSecondaryValue = 0.0;
m_WidthChanged = false;
}
/*
@ -86,11 +87,31 @@ void CMeterHistogram::Initialize()
Status status = m_PrimaryBitmap->GetLastStatus();
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());
m_W = m_PrimaryBitmap->GetWidth();
m_H = m_PrimaryBitmap->GetHeight();
delete m_PrimaryBitmap;
m_PrimaryBitmap = NULL;
}
else
{
int oldW = m_W;
m_W = m_PrimaryBitmap->GetWidth();
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())
@ -100,7 +121,18 @@ void CMeterHistogram::Initialize()
Status status = m_SecondaryBitmap->GetLastStatus();
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,25 +143,81 @@ void CMeterHistogram::Initialize()
Status status = m_BothBitmap->GetLastStatus();
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
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;
}
}
// Create buffers for values
if (m_PrimaryValues) delete [] m_PrimaryValues;
m_PrimaryValues = new double[m_W];
memset(m_PrimaryValues, 0, sizeof(double) * m_W);
if (m_SecondaryMeasure)
if ((!m_PrimaryImageName.empty() && !m_PrimaryBitmap) ||
(!m_SecondaryImageName.empty() && !m_SecondaryBitmap) ||
(!m_BothImageName.empty() && !m_BothBitmap))
{
if (m_SecondaryValues) delete [] m_SecondaryValues;
m_SecondaryValues = new double[m_W];
memset(m_SecondaryValues, 0, sizeof(double) * m_W);
// 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
if (m_PrimaryValues) delete [] m_PrimaryValues;
m_PrimaryValues = new double[m_W];
memset(m_PrimaryValues, 0, sizeof(double) * m_W);
if (m_SecondaryMeasure)
{
if (m_SecondaryValues) delete [] m_SecondaryValues;
m_SecondaryValues = new 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)
{
// 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
CMeter::ReadConfig(section);
@ -163,6 +258,31 @@ void CMeterHistogram::ReadConfig(const WCHAR* section)
m_Autoscale = 0!=parser.ReadInt(section, L"AutoScale", 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()
{
if (CMeter::Update() && m_Measure)
if (CMeter::Update() && m_Measure && m_PrimaryValues)
{
// Gather values
m_PrimaryValues[m_MeterPos] = m_Measure->GetValue();
if (m_SecondaryMeasure != NULL)
if (m_SecondaryMeasure && m_SecondaryValues)
{
m_SecondaryValues[m_MeterPos] = m_SecondaryMeasure->GetValue();
}
@ -213,7 +333,7 @@ bool CMeterHistogram::Update()
m_MaxPrimaryValue *= 2;
}
if (m_SecondaryMeasure)
if (m_SecondaryMeasure && m_SecondaryValues)
{
for (int i = 0; i != m_W; ++i)
{
@ -241,7 +361,9 @@ bool CMeterHistogram::Update()
*/
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 secondaryPen(m_SecondaryColor);

View File

@ -60,6 +60,8 @@ private:
double m_MinPrimaryValue;
double m_MaxSecondaryValue;
double m_MinSecondaryValue;
bool m_WidthChanged;
};
#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());
Status status = m_Bitmap->GetLastStatus();
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;
m_Bitmap = NULL;
throw CError(std::wstring(L"Bitmap image not found: ") + m_ImageName, __LINE__, __FILE__);
}
}
}