* MeterImage

+ Added

* MeterBar and MeterRotator
  + Added support for image effects on Bar and Rotator.
This commit is contained in:
mapeki 2010-10-17 17:51:14 +00:00
parent 1ee9137ea2
commit 2b960748f1
6 changed files with 62 additions and 59 deletions

View File

@ -23,6 +23,7 @@
#include "Litestep.h" #include "Litestep.h"
#include "Rainmeter.h" #include "Rainmeter.h"
using namespace Gdiplus; using namespace Gdiplus;
extern CRainmeter* Rainmeter; extern CRainmeter* Rainmeter;
@ -33,13 +34,16 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeterBar::CMeterBar(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterBar::CMeterBar(CMeterWindow* meterWindow) : CMeterImage(meterWindow)
{ {
m_Color = 0; m_Color = 0;
m_Bitmap = NULL; m_Bitmap = NULL;
m_Value = 0.0; m_Value = 0.0;
m_Border = 0; m_Border = 0;
m_Flip = false; m_Flip = false;
m_ImageWidthString = L"ImageW";
m_ImageWidthString = L"ImageH";
} }
/* /*
@ -50,7 +54,7 @@ CMeterBar::CMeterBar(CMeterWindow* meterWindow) : CMeter(meterWindow)
*/ */
CMeterBar::~CMeterBar() CMeterBar::~CMeterBar()
{ {
if(m_Bitmap != NULL) delete m_Bitmap;
} }
/* /*
@ -67,21 +71,15 @@ void CMeterBar::Initialize()
// Load the bitmaps if defined // Load the bitmaps if defined
if(!m_ImageName.empty()) if(!m_ImageName.empty())
{ {
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; LoadImage(false);
m_Bitmap = NULL;
} if(m_Bitmap)
else
{ {
m_W = m_Bitmap->GetWidth(); m_W = m_Bitmap->GetWidth();
m_H = m_Bitmap->GetHeight(); m_H = m_Bitmap->GetHeight();
} }
} }
else else
{ {
@ -107,7 +105,7 @@ void CMeterBar::ReadConfig(const WCHAR* section)
int oldH = m_H; int oldH = m_H;
// Read common configs // Read common configs
CMeter::ReadConfig(section); CMeterImage::ReadConfig(section);
CConfigParser& parser = m_MeterWindow->GetParser(); CConfigParser& parser = m_MeterWindow->GetParser();
@ -180,41 +178,43 @@ bool CMeterBar::Draw(Graphics& graphics)
int x = GetX(); int x = GetX();
int y = GetY(); int y = GetY();
Bitmap* drawBitmap = (m_BitmapTint) ? m_BitmapTint : m_Bitmap;
if(m_Orientation == VERTICAL) if(m_Orientation == VERTICAL)
{ {
int size = (int)((m_H - 2 * m_Border) * m_Value); int size = (int)((m_H - 2 * m_Border) * m_Value);
size = min(m_H - 2 * m_Border, size); size = min(m_H - 2 * m_Border, size);
size = max(0, size); size = max(0, size);
if (m_Bitmap) if (drawBitmap)
{ {
if (m_Flip) if (m_Flip)
{ {
if (m_Border > 0) if (m_Border > 0)
{ {
Rect r2(x, y, m_W, m_Border); Rect r2(x, y, m_W, m_Border);
graphics.DrawImage(m_Bitmap, r2, 0, 0, m_W, m_Border, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, 0, m_W, m_Border, UnitPixel);
r2.Y = y + size + m_Border; r2.Y = y + size + m_Border;
graphics.DrawImage(m_Bitmap, r2, 0, m_H - m_Border, m_W, m_Border, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, m_H - m_Border, m_W, m_Border, UnitPixel);
} }
// Blit the image // Blit the image
Rect r(x, y + m_Border, m_W, size); Rect r(x, y + m_Border, m_W, size);
graphics.DrawImage(m_Bitmap, r, 0, m_Border, m_W, size, UnitPixel); graphics.DrawImage(drawBitmap, r, 0, m_Border, m_W, size, UnitPixel);
} }
else else
{ {
if (m_Border > 0) if (m_Border > 0)
{ {
Rect r2(x, y + m_H - size - 2 * m_Border, m_W, m_Border); Rect r2(x, y + m_H - size - 2 * m_Border, m_W, m_Border);
graphics.DrawImage(m_Bitmap, r2, 0, 0, m_W, m_Border, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, 0, m_W, m_Border, UnitPixel);
r2.Y = y + m_H - m_Border; r2.Y = y + m_H - m_Border;
graphics.DrawImage(m_Bitmap, r2, 0, m_H - m_Border, m_W, m_Border, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, m_H - m_Border, m_W, m_Border, UnitPixel);
} }
// Blit the image // Blit the image
Rect r(x, y + m_H - size - m_Border, m_W, size); Rect r(x, y + m_H - size - m_Border, m_W, size);
graphics.DrawImage(m_Bitmap, r, 0, m_H - size - m_Border, m_W, size, UnitPixel); graphics.DrawImage(drawBitmap, r, 0, m_H - size - m_Border, m_W, size, UnitPixel);
} }
} }
else else
@ -238,35 +238,35 @@ bool CMeterBar::Draw(Graphics& graphics)
size = min(m_W - 2 * m_Border, size); size = min(m_W - 2 * m_Border, size);
size = max(0, size); size = max(0, size);
if (m_Bitmap) if (drawBitmap)
{ {
if (m_Flip) if (m_Flip)
{ {
if (m_Border > 0) if (m_Border > 0)
{ {
Rect r2(x + m_W - size - 2 * m_Border, y, m_Border, m_H); Rect r2(x + m_W - size - 2 * m_Border, y, m_Border, m_H);
graphics.DrawImage(m_Bitmap, r2, 0, 0, m_Border, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, 0, m_Border, m_H, UnitPixel);
r2.X = x + m_W - m_Border; r2.X = x + m_W - m_Border;
graphics.DrawImage(m_Bitmap, r2, m_W - m_Border, 0, m_Border, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r2, m_W - m_Border, 0, m_Border, m_H, UnitPixel);
} }
// Blit the image // Blit the image
Rect r(x + m_W - size - m_Border, y, size, m_H); Rect r(x + m_W - size - m_Border, y, size, m_H);
graphics.DrawImage(m_Bitmap, r, m_W - size - m_Border, 0, size, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r, m_W - size - m_Border, 0, size, m_H, UnitPixel);
} }
else else
{ {
if (m_Border > 0) if (m_Border > 0)
{ {
Rect r2(x, y, m_Border, m_H); Rect r2(x, y, m_Border, m_H);
graphics.DrawImage(m_Bitmap, r2, 0, 0, m_Border, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r2, 0, 0, m_Border, m_H, UnitPixel);
r2.X = x + size + m_Border; r2.X = x + size + m_Border;
graphics.DrawImage(m_Bitmap, r2, m_W - m_Border, 0, m_Border, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r2, m_W - m_Border, 0, m_Border, m_H, UnitPixel);
} }
// Blit the image // Blit the image
Rect r(x + m_Border, y, size, m_H); Rect r(x + m_Border, y, size, m_H);
graphics.DrawImage(m_Bitmap, r, m_Border, 0, size, m_H, UnitPixel); graphics.DrawImage(drawBitmap, r, m_Border, 0, size, m_H, UnitPixel);
} }
} }
else else

View File

@ -19,10 +19,9 @@
#ifndef __METERBAR_H__ #ifndef __METERBAR_H__
#define __METERBAR_H__ #define __METERBAR_H__
#include "Meter.h" #include "MeterImage.h"
#include "MeterWindow.h"
class CMeterBar : public CMeter class CMeterBar : public CMeterImage
{ {
public: public:
CMeterBar(CMeterWindow* meterWindow); CMeterBar(CMeterWindow* meterWindow);
@ -41,12 +40,12 @@ private:
}; };
Gdiplus::Color m_Color; // Color of the bar Gdiplus::Color m_Color; // Color of the bar
Gdiplus::Bitmap* m_Bitmap; // The bar bitmap
ORIENTATION m_Orientation; // Orientation (i.e. the growth direction) ORIENTATION m_Orientation; // Orientation (i.e. the growth direction)
std::wstring m_ImageName; // Name of the bar-image
double m_Value; double m_Value;
int m_Border; int m_Border;
bool m_Flip; bool m_Flip;
}; };
#endif #endif

View File

@ -69,6 +69,9 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow)
m_ColorMatrix = c_IdentifyMatrix; m_ColorMatrix = c_IdentifyMatrix;
m_Flip = RotateNoneFlipNone; m_Flip = RotateNoneFlipNone;
m_Rotate = 0.0f; m_Rotate = 0.0f;
m_ImageWidthString = L"W";
m_ImageWidthString = L"H";
} }
/* /*
@ -102,7 +105,7 @@ void CMeterImage::Initialize()
} }
/* /*
** ReadConfig ** LoadImage
** **
** Loads the image from disk ** Loads the image from disk
** **
@ -429,11 +432,11 @@ void CMeterImage::ReadConfig(const WCHAR* section)
m_PreserveAspectRatio = 0!=parser.ReadInt(section, L"PreserveAspectRatio", 0); m_PreserveAspectRatio = 0!=parser.ReadInt(section, L"PreserveAspectRatio", 0);
if (-1 != (int)parser.ReadFormula(section, L"W", -1)) if (-1 != (int)parser.ReadFormula(section, m_ImageWidthString.c_str(), -1))
{ {
m_WidthDefined = true; m_WidthDefined = true;
} }
if (-1 != (int)parser.ReadFormula(section, L"H", -1)) if (-1 != (int)parser.ReadFormula(section, m_ImageHeightString.c_str(), -1))
{ {
m_HeightDefined = true; m_HeightDefined = true;
} }

View File

@ -39,7 +39,9 @@ public:
virtual bool Draw(Gdiplus::Graphics& graphics); virtual bool Draw(Gdiplus::Graphics& graphics);
virtual void BindMeasure(std::list<CMeasure*>& measures); virtual void BindMeasure(std::list<CMeasure*>& measures);
private: protected:
std::wstring m_ImageWidthString;
std::wstring m_ImageHeightString;
void LoadImage(bool bLoadAlways); void LoadImage(bool bLoadAlways);
bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b); bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b);
void ApplyTint(); void ApplyTint();

View File

@ -33,7 +33,7 @@ extern CRainmeter* Rainmeter;
** The constructor ** The constructor
** **
*/ */
CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeter(meterWindow) CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeterImage(meterWindow)
{ {
m_Bitmap = NULL; m_Bitmap = NULL;
m_Value = 0.0; m_Value = 0.0;
@ -47,7 +47,6 @@ CMeterRotator::CMeterRotator(CMeterWindow* meterWindow) : CMeter(meterWindow)
*/ */
CMeterRotator::~CMeterRotator() CMeterRotator::~CMeterRotator()
{ {
if(m_Bitmap != NULL) delete m_Bitmap;
} }
/* /*
@ -63,16 +62,16 @@ void CMeterRotator::Initialize()
// Load the bitmaps if defined // Load the bitmaps if defined
if(!m_ImageName.empty()) if(!m_ImageName.empty())
{ {
if (m_Bitmap != NULL) delete m_Bitmap; // Since loading the image redefines the width of the meter we must
m_Bitmap = new Bitmap(m_ImageName.c_str()); // store the width and height that were defined.
Status status = m_Bitmap->GetLastStatus(); int Height, Width;
if(Ok != status) Height = m_H;
{ Width = m_W;
DebugLog(L"Bitmap image not found: %s", m_ImageName.c_str());
delete m_Bitmap; LoadImage(false);
m_Bitmap = NULL;
} m_W = Width;
m_H = Height;
} }
else else
{ {
@ -96,7 +95,7 @@ void CMeterRotator::ReadConfig(const WCHAR* section)
std::wstring oldImageName = m_ImageName; std::wstring oldImageName = m_ImageName;
// Read common configs // Read common configs
CMeter::ReadConfig(section); CMeterImage::ReadConfig(section);
CConfigParser& parser = m_MeterWindow->GetParser(); CConfigParser& parser = m_MeterWindow->GetParser();
@ -171,13 +170,15 @@ bool CMeterRotator::Draw(Graphics& graphics)
graphics.RotateTransform(angle); graphics.RotateTransform(angle);
graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY); graphics.TranslateTransform((REAL)-m_OffsetX, (REAL)-m_OffsetY);
if(m_Bitmap) Bitmap* drawBitmap = (m_BitmapTint) ? m_BitmapTint : m_Bitmap;
if(drawBitmap)
{ {
UINT width = m_Bitmap->GetWidth(); UINT width = drawBitmap->GetWidth();
UINT height = m_Bitmap->GetHeight(); UINT height = drawBitmap->GetHeight();
// Blit the image // Blit the image
graphics.DrawImage(m_Bitmap, 0, 0, width, height); graphics.DrawImage(drawBitmap, 0, 0, width, height);
} }
graphics.ResetTransform(); graphics.ResetTransform();

View File

@ -19,10 +19,9 @@
#ifndef __METERROTATOR_H__ #ifndef __METERROTATOR_H__
#define __METERROTATOR_H__ #define __METERROTATOR_H__
#include "Meter.h" #include "MeterImage.h"
#include "MeterWindow.h"
class CMeterRotator : public CMeter class CMeterRotator : public CMeterImage
{ {
public: public:
CMeterRotator(CMeterWindow* meterWindow); CMeterRotator(CMeterWindow* meterWindow);
@ -34,8 +33,7 @@ public:
virtual bool Draw(Gdiplus::Graphics& graphics); virtual bool Draw(Gdiplus::Graphics& graphics);
private: private:
Gdiplus::Bitmap* m_Bitmap; // The bar bitmap
std::wstring m_ImageName; // Name of the image
double m_OffsetX; double m_OffsetX;
double m_OffsetY; double m_OffsetY;
double m_StartAngle; double m_StartAngle;