Added "Padding" option to meters.

Usage: Padding = left, top, right, bottom
This commit is contained in:
Brian Ferguson 2013-07-20 10:07:51 -06:00
parent 8f2f65c1fc
commit d67db33ecf
9 changed files with 178 additions and 151 deletions

View File

@ -59,6 +59,7 @@ Meter::Meter(MeterWindow* meterWindow, const WCHAR* name) : Section(meterWindow,
m_RelativeY(POSITION_ABSOLUTE),
m_SolidBevel(BEVELTYPE_NONE),
m_SolidAngle(),
m_Padding(),
m_AntiAlias(false),
m_Initialized(false)
{
@ -166,6 +167,22 @@ RECT Meter::GetMeterRect()
return meterRect;
}
/*
** Returns a Rect containing the adjusted meter location with SolidColorPadding
**
*/
Gdiplus::Rect Meter::GetMeterRectPadding()
{
Gdiplus::Rect meterRect;
meterRect.X = GetX() + m_Padding.X;
meterRect.Y = GetY() + m_Padding.Y;
meterRect.Width = m_W - m_Padding.X - m_Padding.Width;
meterRect.Height = m_H - m_Padding.Y - m_Padding.Height;
return meterRect;
}
/*
** Checks if the given point is inside the meter.
** This function doesn't check Hidden state, so check it before calling this function if needed.
@ -288,10 +305,13 @@ void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section)
m_RelativeY = POSITION_ABSOLUTE;
}
static const Gdiplus::Rect defPadding;
m_Padding = parser.ReadRect(section, L"Padding", defPadding);
bool oldWDefined = m_WDefined;
int w = parser.ReadInt(section, L"W", m_W);
m_WDefined = parser.GetLastValueDefined();
if (IsFixedSize(true)) m_W = w;
if (IsFixedSize(true)) m_W = w + GetWidthPadding();
if (!m_WDefined && oldWDefined && IsFixedSize())
{
m_W = 0;
@ -300,7 +320,7 @@ void Meter::ReadOptions(ConfigParser& parser, const WCHAR* section)
bool oldHDefined = m_HDefined;
int h = parser.ReadInt(section, L"H", m_H);
m_HDefined = parser.GetLastValueDefined();
if (IsFixedSize(true)) m_H = h;
if (IsFixedSize(true)) m_H = h + GetHeightPadding();
if (!m_HDefined && oldHDefined && IsFixedSize())
{
m_H = 0;

View File

@ -49,6 +49,10 @@ public:
virtual int GetY(bool abs = false);
RECT GetMeterRect();
Gdiplus::Rect GetMeterRectPadding();
int GetWidthPadding() { return m_Padding.X + m_Padding.Width; }
int GetHeightPadding() { return m_Padding.Y + m_Padding.Height; }
void SetW(int w) { m_W = w; }
void SetH(int h) { m_H = h; }
void SetX(int x);
@ -122,7 +126,7 @@ protected:
bool m_Hidden;
bool m_WDefined;
bool m_HDefined;
Meter* m_RelativeMeter;
Meter* m_RelativeMeter;
Gdiplus::Matrix* m_Transformation;
@ -146,6 +150,7 @@ protected:
Gdiplus::Color m_SolidColor;
Gdiplus::Color m_SolidColor2;
Gdiplus::REAL m_SolidAngle;
Gdiplus::Rect m_Padding;
bool m_AntiAlias;
bool m_Initialized;
};

View File

@ -67,8 +67,8 @@ void MeterBar::Initialize()
{
Bitmap* bitmap = m_Image.GetImage();
m_W = bitmap->GetWidth();
m_H = bitmap->GetHeight();
m_W = bitmap->GetWidth() + GetWidthPadding();
m_H = bitmap->GetHeight() + GetHeightPadding();
}
}
else if (m_Image.IsLoaded())
@ -161,14 +161,13 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (!Meter::Draw(canvas)) return false;
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
Bitmap* drawBitmap = m_Image.GetImage();
if (m_Orientation == VERTICAL)
{
int barSize = m_H - 2 * m_Border;
int barSize = meterRect.Height - 2 * m_Border;
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
@ -179,27 +178,27 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (m_Border > 0)
{
Rect r2(x, y, m_W, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_W, m_Border));
r2.Y = y + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, m_H - m_Border, m_W, m_Border));
Rect r2(meterRect.X, meterRect.Y, meterRect.Width, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, meterRect.Width, m_Border));
r2.Y = meterRect.Y + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, meterRect.Height - m_Border, meterRect.Width, m_Border));
}
Rect r(x, y + m_Border, m_W, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m_Border, m_W, size));
Rect r(meterRect.X, meterRect.Y + m_Border, meterRect.Width, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m_Border, meterRect.Width, size));
}
else
{
if (m_Border > 0)
{
Rect r2(x, y + m_H - size - 2 * m_Border, m_W, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_W, m_Border));
r2.Y = y + m_H - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, m_H - m_Border, m_W, m_Border));
Rect r2(meterRect.X, meterRect.Y + meterRect.Height - size - 2 * m_Border, meterRect.Width, m_Border);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, meterRect.Width, m_Border));
r2.Y = meterRect.Y + meterRect.Height - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(0, meterRect.Height - m_Border, meterRect.Width, m_Border));
}
Rect r(x, y + m_H - size - m_Border, m_W, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m_H - size - m_Border, m_W, size));
Rect r(meterRect.X, meterRect.Y + meterRect.Height - size - m_Border, meterRect.Width, size);
canvas.DrawBitmap(drawBitmap, r, Rect(0, meterRect.Height - size - m_Border, meterRect.Width, size));
}
}
else
@ -207,19 +206,19 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
SolidBrush brush(m_Color);
if (m_Flip)
{
Rect r(x, y, m_W, size);
Rect r(meterRect.X, meterRect.Y, meterRect.Width, size);
canvas.FillRectangle(r, brush);
}
else
{
Rect r(x, y + m_H - size, m_W, size);
Rect r(meterRect.X, meterRect.Y + meterRect.Height - size, meterRect.Width, size);
canvas.FillRectangle(r, brush);
}
}
}
else
{
int barSize = m_W - 2 * m_Border;
int barSize = meterRect.Width - 2 * m_Border;
int size = (int)(barSize * m_Value);
size = min(barSize, size);
size = max(0, size);
@ -230,27 +229,27 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
{
if (m_Border > 0)
{
Rect r2(x + m_W - size - 2 * m_Border, y, m_Border, m_H);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, m_H));
r2.X = x + m_W - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(m_W - m_Border, 0, m_Border, m_H));
Rect r2(meterRect.X + meterRect.Width - size - 2 * m_Border, meterRect.Y, m_Border, meterRect.Height);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, meterRect.Height));
r2.X = meterRect.X + meterRect.Width - m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(meterRect.Width - m_Border, 0, m_Border, meterRect.Height));
}
Rect r(x + m_W - size - m_Border, y, size, m_H);
canvas.DrawBitmap(drawBitmap, r, Rect(m_W - size - m_Border, 0, size, m_H));
Rect r(meterRect.X + meterRect.Width - size - m_Border, meterRect.Y, size, meterRect.Height);
canvas.DrawBitmap(drawBitmap, r, Rect(meterRect.Width - size - m_Border, 0, size, meterRect.Height));
}
else
{
if (m_Border > 0)
{
Rect r2(x, y, m_Border, m_H);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, m_H));
r2.X = x + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(m_W - m_Border, 0, m_Border, m_H));
Rect r2(meterRect.X, meterRect.Y, m_Border, meterRect.Height);
canvas.DrawBitmap(drawBitmap, r2, Rect(0, 0, m_Border, meterRect.Height));
r2.X = meterRect.X + size + m_Border;
canvas.DrawBitmap(drawBitmap, r2, Rect(meterRect.Width - m_Border, 0, m_Border, meterRect.Height));
}
Rect r(x + m_Border, y, size, m_H);
canvas.DrawBitmap(drawBitmap, r, Rect(m_Border, 0, size, m_H));
Rect r(meterRect.X + m_Border, meterRect.Y, size, meterRect.Height);
canvas.DrawBitmap(drawBitmap, r, Rect(m_Border, 0, size, meterRect.Height));
}
}
else
@ -258,12 +257,12 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
SolidBrush brush(m_Color);
if (m_Flip)
{
Rect r(x + m_W - size, y, size, m_H);
Rect r(meterRect.X + meterRect.Width - size, meterRect.Y, size, meterRect.Height);
canvas.FillRectangle(r, brush);
}
else
{
Rect r(x, y, size, m_H);
Rect r(meterRect.X, meterRect.Y, size, meterRect.Height);
canvas.FillRectangle(r, brush);
}
}
@ -271,4 +270,3 @@ bool MeterBar::Draw(Gfx::Canvas& canvas)
return true;
}

View File

@ -82,6 +82,9 @@ void MeterBitmap::Initialize()
{
m_W = m_W / m_FrameCount;
}
m_W += GetWidthPadding();
m_H += GetHeightPadding();
}
}
else if (m_Image.IsLoaded())
@ -277,8 +280,7 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas)
Bitmap* bitmap = m_Image.GetImage();
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
if (m_Extend)
{
@ -322,16 +324,16 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas)
}
else if (m_Align == ALIGN_CENTER)
{
offset = numOfNums * (m_W + m_Separation) / 2;
offset = numOfNums * (meterRect.Width + m_Separation) / 2;
}
else
{
offset = numOfNums * (m_W + m_Separation);
offset = numOfNums * (meterRect.Width + m_Separation);
}
do
{
offset = offset - (m_W + m_Separation);
offset = offset - (meterRect.Width + m_Separation);
int realFrames = (m_FrameCount / (m_TransitionFrameCount + 1));
int frame = (value % realFrames) * (m_TransitionFrameCount + 1);
@ -364,15 +366,15 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas)
if (bitmap->GetHeight() > bitmap->GetWidth())
{
newX = 0;
newY = m_H * frame;
newY = meterRect.Height * frame;
}
else
{
newX = m_W * frame;
newX = meterRect.Width * frame;
newY = 0;
}
canvas.DrawBitmap(bitmap, Rect(x + offset, y, m_W, m_H), Rect(newX, newY, m_W, m_H));
canvas.DrawBitmap(bitmap, Rect(meterRect.X + offset, meterRect.Y, meterRect.Width, meterRect.Height), Rect(newX, newY, meterRect.Width, meterRect.Height));
if (m_FrameCount == 1)
{
value /= 2;
@ -433,17 +435,16 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas)
if (bitmap->GetHeight() > bitmap->GetWidth())
{
newX = 0;
newY = frame * m_H;
newY = frame * meterRect.Height;
}
else
{
newX = frame * m_W;
newX = frame * meterRect.Width;
newY = 0;
}
canvas.DrawBitmap(bitmap, Rect(x, y, m_W, m_H), Rect(newX, newY, m_W, m_H));
canvas.DrawBitmap(bitmap, Rect(meterRect.X, meterRect.Y, meterRect.Width, meterRect.Height), Rect(newX, newY, meterRect.Width, m_H));
}
return true;
}

View File

@ -113,6 +113,9 @@ void MeterButton::Initialize()
}
m_Bitmaps[i] = new CachedBitmap(&bitmapPart, &graphics);
}
m_W += GetWidthPadding();
m_H += GetHeightPadding();
}
}
else if (m_Image.IsLoaded())
@ -186,11 +189,10 @@ bool MeterButton::Draw(Gfx::Canvas& canvas)
Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext();
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
// Blit the image
graphics.DrawCachedBitmap(m_Bitmaps[m_State], x, y);
graphics.DrawCachedBitmap(m_Bitmaps[m_State], meterRect.X, meterRect.Y);
canvas.EndGdiplusContext();
@ -317,4 +319,4 @@ bool MeterButton::MouseMove(POINT pos)
}
}
return false;
}
}

View File

@ -145,6 +145,9 @@ void MeterHistogram::Initialize()
{
m_SizeChanged = true;
}
m_W += GetWidthPadding();
m_H += GetHeightPadding();
}
}
else if (m_PrimaryImage.IsLoaded())
@ -421,14 +424,13 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
Bitmap* secondaryBitmap = m_SecondaryImage.GetImage();
Bitmap* bothBitmap = m_OverlapImage.GetImage();
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
// Default values (GraphStart=Right, GraphOrientation=Vertical)
int i;
int startValue = 0;
int* endValueLHS = &i;
int* endValueRHS = &m_W;
int* endValueRHS = &meterRect.Width;
int step = 1;
int endValue = -1; //(should be 0, but need to simulate <=)
@ -437,7 +439,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
{
if (m_GraphStartLeft)
{
startValue = m_W - 1;
startValue = meterRect.Width - 1;
endValueLHS = &endValue;
endValueRHS = &i;
step = -1;
@ -447,11 +449,11 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
{
if (!m_Flip)
{
endValueRHS = &m_H;
endValueRHS = &meterRect.Height;
}
else
{
startValue = m_H - 1;
startValue = meterRect.Height - 1;
endValueLHS = &endValue;
endValueRHS = &i;
step = -1;
@ -465,20 +467,20 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
{
double value = (m_MaxPrimaryValue == 0.0) ?
0.0
: m_PrimaryValues[(i + (m_MeterPos % m_H)) % m_H] / m_MaxPrimaryValue;
: m_PrimaryValues[(i + (m_MeterPos % meterRect.Height)) % meterRect.Height] / m_MaxPrimaryValue;
value -= m_MinPrimaryValue;
int primaryBarHeight = (int)(m_W * value);
primaryBarHeight = min(m_W, primaryBarHeight);
int primaryBarHeight = (int)(meterRect.Width * value);
primaryBarHeight = min(meterRect.Width, primaryBarHeight);
primaryBarHeight = max(0, primaryBarHeight);
if (secondaryMeasure)
{
value = (m_MaxSecondaryValue == 0.0) ?
0.0
: m_SecondaryValues[(i + m_MeterPos) % m_H] / m_MaxSecondaryValue;
: m_SecondaryValues[(i + m_MeterPos) % meterRect.Height] / m_MaxSecondaryValue;
value -= m_MinSecondaryValue;
int secondaryBarHeight = (int)(m_W * value);
secondaryBarHeight = min(m_W, secondaryBarHeight);
int secondaryBarHeight = (int)(meterRect.Width * value);
secondaryBarHeight = min(meterRect.Width, secondaryBarHeight);
secondaryBarHeight = max(0, secondaryBarHeight);
// Check which measured value is higher
@ -487,8 +489,8 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
// Cache image/color rectangle for the both lines
{
Rect& r = m_GraphStartLeft ?
Rect(x, y + startValue + (step * i), bothBarHeight, 1)
: Rect(x + m_W - bothBarHeight, y + startValue + (step * i), bothBarHeight, 1);
Rect(meterRect.X, meterRect.Y + startValue + (step * i), bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - bothBarHeight, meterRect.Y + startValue + (step * i), bothBarHeight, 1);
bothPath.AddRectangle(r); // cache
}
@ -497,16 +499,16 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
if (secondaryBarHeight > primaryBarHeight)
{
Rect& r = m_GraphStartLeft ?
Rect(x + bothBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1)
: Rect(x + m_W - secondaryBarHeight, y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1);
Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - secondaryBarHeight, meterRect.Y + startValue + (step * i), secondaryBarHeight - bothBarHeight, 1);
secondaryPath.AddRectangle(r); // cache
}
else
{
Rect& r = m_GraphStartLeft ?
Rect(x + bothBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1)
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1);
Rect(meterRect.X + bothBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight - bothBarHeight, 1);
primaryPath.AddRectangle(r); // cache
}
@ -514,8 +516,8 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
else
{
Rect& r = m_GraphStartLeft ?
Rect(x, y + startValue + (step * i), primaryBarHeight, 1)
: Rect(x + m_W - primaryBarHeight, y + startValue + (step * i), primaryBarHeight, 1);
Rect(meterRect.X, meterRect.Y + startValue + (step * i), primaryBarHeight, 1)
: Rect(meterRect.X + meterRect.Width - primaryBarHeight, meterRect.Y + startValue + (step * i), primaryBarHeight, 1);
primaryPath.AddRectangle(r); // cache
}
@ -527,20 +529,20 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
{
double value = (m_MaxPrimaryValue == 0.0) ?
0.0
: m_PrimaryValues[(i + m_MeterPos) % m_W] / m_MaxPrimaryValue;
: m_PrimaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxPrimaryValue;
value -= m_MinPrimaryValue;
int primaryBarHeight = (int)(m_H * value);
primaryBarHeight = min(m_H, primaryBarHeight);
int primaryBarHeight = (int)(meterRect.Height * value);
primaryBarHeight = min(meterRect.Height, primaryBarHeight);
primaryBarHeight = max(0, primaryBarHeight);
if (secondaryMeasure)
{
value = (m_MaxSecondaryValue == 0.0) ?
0.0
: m_SecondaryValues[(i + m_MeterPos) % m_W] / m_MaxSecondaryValue;
: m_SecondaryValues[(i + m_MeterPos) % meterRect.Width] / m_MaxSecondaryValue;
value -= m_MinSecondaryValue;
int secondaryBarHeight = (int)(m_H * value);
secondaryBarHeight = min(m_H, secondaryBarHeight);
int secondaryBarHeight = (int)(meterRect.Height * value);
secondaryBarHeight = min(meterRect.Height, secondaryBarHeight);
secondaryBarHeight = max(0, secondaryBarHeight);
// Check which measured value is higher
@ -549,8 +551,8 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
// Cache image/color rectangle for the both lines
{
Rect& r = m_Flip ?
Rect(x + startValue + (step * i), y, 1, bothBarHeight)
: Rect(x + startValue + (step * i), y + m_H - bothBarHeight, 1, bothBarHeight);
Rect(meterRect.X + startValue + (step * i), meterRect.Y, 1, bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - bothBarHeight, 1, bothBarHeight);
bothPath.AddRectangle(r); // cache
}
@ -559,16 +561,16 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
if (secondaryBarHeight > primaryBarHeight)
{
Rect& r = m_Flip ?
Rect(x + startValue + (step * i), y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
: Rect(x + startValue + (step * i), y + m_H - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, secondaryBarHeight - bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - secondaryBarHeight, 1, secondaryBarHeight - bothBarHeight);
secondaryPath.AddRectangle(r); // cache
}
else
{
Rect& r = m_Flip ?
Rect(x + startValue + (step * i), y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
Rect(meterRect.X + startValue + (step * i), meterRect.Y + bothBarHeight, 1, primaryBarHeight - bothBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight - bothBarHeight);
primaryPath.AddRectangle(r); // cache
}
@ -576,8 +578,8 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
else
{
Rect& r = m_Flip ?
Rect(x + startValue + (step * i), y, 1, primaryBarHeight)
: Rect(x + startValue + (step * i), y + m_H - primaryBarHeight, 1, primaryBarHeight);
Rect(meterRect.X + startValue + (step * i), meterRect.Y, 1, primaryBarHeight)
: Rect(meterRect.X + startValue + (step * i), meterRect.Y + meterRect.Height - primaryBarHeight, 1, primaryBarHeight);
primaryPath.AddRectangle(r); // cache
}
@ -587,7 +589,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
// Draw cached rectangles
if (primaryBitmap)
{
Rect r(x, y, primaryBitmap->GetWidth(), primaryBitmap->GetHeight());
Rect r(meterRect.X, meterRect.Y, primaryBitmap->GetWidth(), primaryBitmap->GetHeight());
graphics.SetClip(&primaryPath);
graphics.DrawImage(primaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
@ -602,7 +604,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
{
if (secondaryBitmap)
{
Rect r(x, y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight());
Rect r(meterRect.X, meterRect.Y, secondaryBitmap->GetWidth(), secondaryBitmap->GetHeight());
graphics.SetClip(&secondaryPath);
graphics.DrawImage(secondaryBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);
@ -615,7 +617,7 @@ bool MeterHistogram::Draw(Gfx::Canvas& canvas)
}
if (bothBitmap)
{
Rect r(x, y, bothBitmap->GetWidth(), bothBitmap->GetHeight());
Rect r(meterRect.X, meterRect.Y, bothBitmap->GetWidth(), bothBitmap->GetHeight());
graphics.SetClip(&bothPath);
graphics.DrawImage(bothBitmap, r, 0, 0, r.Width, r.Height, UnitPixel);

View File

@ -83,6 +83,7 @@ void MeterImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
if (!m_HDefined)
{
m_H = (imageW == 0) ? 0 : (m_DrawMode == DRAWMODE_TILE) ? imageH : m_W * imageH / imageW;
m_H += GetHeightPadding();
}
}
else
@ -90,11 +91,12 @@ void MeterImage::LoadImage(const std::wstring& imageName, bool bLoadAlways)
if (m_HDefined)
{
m_W = (imageH == 0) ? 0 : (m_DrawMode == DRAWMODE_TILE) ? imageW : m_H * imageW / imageH;
m_W += GetWidthPadding();
}
else
{
m_W = imageW;
m_H = imageH;
m_W = imageW + GetWidthPadding();
m_H = imageH + GetHeightPadding();
}
}
}
@ -214,16 +216,15 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
if (imageW == 0 || imageH == 0 || m_W == 0 || m_H == 0) return true;
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
int drawW = m_W;
int drawH = m_H;
int drawW = meterRect.Width;
int drawH = meterRect.Height;
if (drawW == imageW && drawH == imageH &&
m_ScaleMargins.left == 0 && m_ScaleMargins.top == 0 && m_ScaleMargins.right == 0 && m_ScaleMargins.bottom == 0)
{
canvas.DrawBitmap(drawBitmap, Rect(x, y, drawW, drawH), Rect(0, 0, imageW, imageH));
canvas.DrawBitmap(drawBitmap, Rect(meterRect.X, meterRect.Y, drawW, drawH), Rect(0, 0, imageW, imageH));
}
else if (m_DrawMode == DRAWMODE_TILE)
{
@ -232,7 +233,7 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
ImageAttributes imgAttr;
imgAttr.SetWrapMode(WrapModeTile);
Rect r(x, y, drawW, drawH);
Rect r(meterRect.X, meterRect.Y, drawW, drawH);
graphics.DrawImage(drawBitmap, r, 0, 0, drawW, drawH, UnitPixel, &imgAttr);
canvas.EndGdiplusContext();
@ -247,7 +248,7 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
if (m_WDefined && m_HDefined)
{
REAL imageRatio = imageW / (REAL)imageH;
REAL meterRatio = m_W / (REAL)m_H;
REAL meterRatio = meterRect.Width / (REAL)meterRect.Height;
if (imageRatio != meterRatio)
{
@ -255,13 +256,13 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
{
if (imageRatio > meterRatio)
{
drawH = m_W * imageH / imageW;
y += (m_H - drawH) / 2;
drawH = meterRect.Width * imageH / imageW;
meterRect.Y += (meterRect.Height - drawH) / 2;
}
else
{
drawW = m_H * imageW / imageH;
x += (m_W - drawW) / 2;
drawW = meterRect.Height * imageW / imageH;
meterRect.X += (meterRect.Width - drawW) / 2;
}
}
else
@ -280,7 +281,7 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
}
}
Rect r(x, y, drawW, drawH);
Rect r(meterRect.X, meterRect.Y, drawW, drawH);
canvas.DrawBitmap(drawBitmap, r, Rect(cropX, cropY, cropW, cropH));
}
else
@ -292,18 +293,18 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
if (m.left > 0)
{
// Top-Left
Rect r(x, y, m.left, m.top);
Rect r(meterRect.X, meterRect.Y, m.left, m.top);
canvas.DrawBitmap(drawBitmap, r, Rect(0, 0, m.left, m.top));
}
// Top
Rect r(x + m.left, y, drawW - m.left - m.right, m.top);
Rect r(meterRect.X + m.left, meterRect.Y, drawW - m.left - m.right, m.top);
canvas.DrawBitmap(drawBitmap, r, Rect(m.left, 0, imageW - m.left - m.right, m.top));
if (m.right > 0)
{
// Top-Right
Rect r(x + drawW - m.right, y, m.right, m.top);
Rect r(meterRect.X + drawW - m.right, meterRect.Y, m.right, m.top);
canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, 0, m.right, m.top));
}
}
@ -311,18 +312,18 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
if (m.left > 0)
{
// Left
Rect r(x, y + m.top, m.left, drawH - m.top - m.bottom);
Rect r(meterRect.X, meterRect.Y + m.top, m.left, drawH - m.top - m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(0, m.top, m.left, imageH - m.top - m.bottom));
}
// Center
Rect r(x + m.left, y + m.top, drawW - m.left - m.right, drawH - m.top - m.bottom);
Rect r(meterRect.X + m.left, meterRect.Y + m.top, drawW - m.left - m.right, drawH - m.top - m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(m.left, m.top, imageW - m.left - m.right, imageH - m.top - m.bottom));
if (m.right > 0)
{
// Right
Rect r(x + drawW - m.right, y + m.top, m.right, drawH - m.top - m.bottom);
Rect r(meterRect.X + drawW - m.right, meterRect.Y + m.top, m.right, drawH - m.top - m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, m.top, m.right, imageH - m.top - m.bottom));
}
@ -331,18 +332,18 @@ bool MeterImage::Draw(Gfx::Canvas& canvas)
if (m.left > 0)
{
// Bottom-Left
Rect r(x, y + drawH - m.bottom, m.left, m.bottom);
Rect r(meterRect.X, meterRect.Y + drawH - m.bottom, m.left, m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(0, imageH - m.bottom, m.left, m.bottom));
}
// Bottom
Rect r(x + m.left, y + drawH - m.bottom, drawW - m.left - m.right, m.bottom);
Rect r(meterRect.X + m.left, meterRect.Y + drawH - m.bottom, drawW - m.left - m.right, m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(m.left, imageH - m.bottom, imageW - m.left - m.right, m.bottom));
if (m.right > 0)
{
// Bottom-Right
Rect r(x + drawW - m.right, y + drawH - m.bottom, m.right, m.bottom);
Rect r(meterRect.X + drawW - m.right, meterRect.Y + drawH - m.bottom, m.right, m.bottom);
canvas.DrawBitmap(drawBitmap, r, Rect(imageW - m.right, imageH - m.bottom, m.right, m.bottom));
}
}

View File

@ -273,14 +273,13 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
}
}
int x = GetX();
int y = GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
// Draw the horizontal lines
if (m_HorizontalLines)
{
// Calc the max number of lines we should draw
int maxLines = m_H / 4; // one line per 4 pixels is max
int maxLines = meterRect.Height / 4; // one line per 4 pixels is max
int numOfLines;
// Check the highest power of 2 that fits in maxLines
@ -297,9 +296,9 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
REAL Y;
for (int j = 0; j < numOfLines; ++j)
{
Y = (REAL)((j + 1) * m_H / (numOfLines + 1));
Y = y + m_H - Y - 1;
graphics.DrawLine(&pen, (REAL)x, Y, (REAL)(x + m_W - 1), Y); // GDI+
Y = (REAL)((j + 1) * meterRect.Height / (numOfLines + 1));
Y = meterRect.Y + meterRect.Height - Y - 1;
graphics.DrawLine(&pen, (REAL)meterRect.X, Y, (REAL)(meterRect.X + meterRect.Width - 1), Y); // GDI+
}
}
@ -307,7 +306,7 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
if (m_GraphHorizontalOrientation)
{
const REAL W = m_W - 1.0f;
const REAL W = meterRect.Width - 1.0f;
counter = 0;
for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
{
@ -323,7 +322,7 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
_x = (REAL)((*i)[pos] * scale);
_x = min(_x, W);
_x = max(_x, 0.0f);
_x = x + (m_GraphStartLeft ? _x : W - _x);
_x = meterRect.X + (m_GraphStartLeft ? _x : W - _x);
};
calcX(oldX);
@ -333,10 +332,10 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
if (!m_Flip)
{
for (int j = y + 1, R = y + m_H; j < R; ++j)
for (int j = meterRect.Y + 1, R = meterRect.Y + meterRect.Height; j < R; ++j)
{
++pos;
pos %= m_H;
pos %= meterRect.Height;
calcX(X);
@ -347,10 +346,10 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
}
else
{
for (int j = y + m_H, R = y + 1; j > R; --j)
for (int j = meterRect.Y + meterRect.Height, R = meterRect.Y + 1; j > R; --j)
{
++pos;
pos %= m_H;
pos %= meterRect.Height;
calcX(X);
@ -370,7 +369,7 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
}
else
{
const REAL H = m_H - 1.0f;
const REAL H = meterRect.Height - 1.0f;
counter = 0;
for (auto i = m_AllValues.cbegin(); i != m_AllValues.cend(); ++i)
{
@ -386,7 +385,7 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
_y = (REAL)((*i)[pos] * scale);
_y = min(_y, H);
_y = max(_y, 0.0f);
_y = y + (m_Flip ? _y : H - _y);
_y = meterRect.Y + (m_Flip ? _y : H - _y);
};
calcY(oldY);
@ -396,10 +395,10 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
if (!m_GraphStartLeft)
{
for (int j = x + 1, R = x + m_W; j < R; ++j)
for (int j = meterRect.X + 1, R = meterRect.X + meterRect.Width; j < R; ++j)
{
++pos;
pos %= m_W;
pos %= meterRect.Width;
calcY(Y);
@ -410,10 +409,10 @@ bool MeterLine::Draw(Gfx::Canvas& canvas)
}
else
{
for (int j = x + m_W, R = x + 1; j > R; --j)
for (int j = meterRect.X + meterRect.Width, R = meterRect.X + 1; j > R; --j)
{
++pos;
pos %= m_W;
pos %= meterRect.Width;
calcY(Y);

View File

@ -393,13 +393,13 @@ bool MeterString::Update()
RectF rect;
if (DrawString(m_MeterWindow->GetCanvas(), &rect))
{
m_W = (int)rect.Width;
m_H = (int)rect.Height;
m_W = (int)rect.Width + GetWidthPadding();
m_H = (int)rect.Height + GetHeightPadding();
}
else
{
m_W = 1;
m_H = 1;
m_W = GetWidthPadding() + 1;
m_H = GetHeightPadding() + 1;
}
}
@ -436,13 +436,12 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
m_ClipType == CLIP_ON ||
(m_ClipType == CLIP_AUTO && (m_NeedsClipping || (m_WDefined && m_HDefined))));
const REAL x = (REAL)GetX();
const REAL y = (REAL)GetY();
Gdiplus::Rect meterRect = GetMeterRectPadding();
if (rect)
{
rect->X = x;
rect->Y = y;;
rect->X = (REAL)meterRect.X;
rect->Y = (REAL)meterRect.Y;
if (canvas.MeasureTextW(string, stringLen, *m_TextFormat, *rect) &&
m_ClipType == CLIP_AUTO)
{
@ -454,7 +453,7 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
if (m_WDefined)
{
w = (REAL)m_W;
w = (REAL)meterRect.Width;
h = rect->Height;
m_NeedsClipping = true;
}
@ -463,18 +462,18 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
if (m_ClipStringW == -1)
{
// Text does not fit in defined height, clip it
if (rect->Height > (REAL)m_H)
if (rect->Height > (REAL)meterRect.Height)
{
m_NeedsClipping = true;
}
rect->Height = (REAL)m_H;
rect->Height = (REAL)meterRect.Height;
updateSize = false;
}
else
{
if (rect->Width > m_ClipStringW)
if (rect->Width > (REAL)m_ClipStringW)
{
w = (REAL)m_ClipStringW;
m_NeedsClipping = true;
@ -484,7 +483,7 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
w = rect->Width;
}
h = (REAL)m_H;
h = (REAL)meterRect.Height;
}
}
else
@ -502,7 +501,7 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
}
else
{
if (rect->Width > m_ClipStringW)
if (rect->Width > (REAL)m_ClipStringW)
{
w = (REAL)m_ClipStringW;
m_NeedsClipping = true;
@ -519,16 +518,16 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
if (updateSize)
{
UINT lines = 0;
RectF layout(x, y, w, h);
RectF layout((REAL)meterRect.X, (REAL)meterRect.Y, w, h);
if (canvas.MeasureTextLinesW(string, stringLen, *m_TextFormat, layout, lines) &&
lines != 0)
{
rect->Width = w;
rect->Height = layout.Height;
if (m_HDefined || (m_ClipStringH != -1 && rect->Height > m_ClipStringH))
if (m_HDefined || (m_ClipStringH != -1 && rect->Height > (REAL)m_ClipStringH))
{
rect->Height = (REAL)(m_HDefined ? m_H : m_ClipStringH);
rect->Height = m_HDefined ? (REAL)meterRect.Height : (REAL)m_ClipStringH;
}
}
}
@ -536,13 +535,13 @@ bool MeterString::DrawString(Gfx::Canvas& canvas, RectF* rect)
}
else
{
RectF rcDest(x, y, (REAL)m_W, (REAL)m_H);
RectF rcDest((REAL)meterRect.X, (REAL)meterRect.Y, (REAL)meterRect.Width, (REAL)meterRect.Height);
m_Rect = rcDest;
if (m_Angle != 0.0f)
{
const float baseX = (float)Meter::GetX();
canvas.RotateTransform(CONVERT_TO_DEGREES(m_Angle), baseX, y, -baseX, -y);
canvas.RotateTransform(CONVERT_TO_DEGREES(m_Angle), baseX, (REAL)meterRect.Y, -baseX, -(REAL)meterRect.Y);
}
if (m_Effect != EFFECT_NONE)