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

View File

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

View File

@ -69,6 +69,9 @@ CMeterImage::CMeterImage(CMeterWindow* meterWindow) : CMeter(meterWindow)
m_ColorMatrix = c_IdentifyMatrix;
m_Flip = RotateNoneFlipNone;
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
**
@ -429,11 +432,11 @@ void CMeterImage::ReadConfig(const WCHAR* section)
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;
}
if (-1 != (int)parser.ReadFormula(section, L"H", -1))
if (-1 != (int)parser.ReadFormula(section, m_ImageHeightString.c_str(), -1))
{
m_HeightDefined = true;
}

View File

@ -39,13 +39,15 @@ public:
virtual bool Draw(Gdiplus::Graphics& graphics);
virtual void BindMeasure(std::list<CMeasure*>& measures);
private:
protected:
std::wstring m_ImageWidthString;
std::wstring m_ImageHeightString;
void LoadImage(bool bLoadAlways);
bool CompareColorMatrix(const Gdiplus::ColorMatrix& a, const Gdiplus::ColorMatrix& b);
void ApplyTint();
Gdiplus::Bitmap* TurnGreyscale();
void ApplyTransform();
Gdiplus::Bitmap* m_Bitmap; // The bitmap
Gdiplus::Bitmap* m_BitmapTint; // The bitmap
std::wstring m_ImageName; // Name of the image

View File

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

View File

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