- Reduced memory usage on BackgroundMode=2.

- Code cleanup.
This commit is contained in:
spx 2010-12-08 09:04:36 +00:00
parent 1d5490aa98
commit 9c24727749
3 changed files with 50 additions and 42 deletions

View File

@ -817,14 +817,15 @@ bool CMeter::Draw(Graphics& graphics)
int x = GetX(); int x = GetX();
int y = GetY(); int y = GetY();
Rect r(x, y, m_W, m_H);
if (m_SolidColor.GetValue() == m_SolidColor2.GetValue()) if (m_SolidColor.GetValue() == m_SolidColor2.GetValue())
{ {
SolidBrush solid(m_SolidColor); SolidBrush solid(m_SolidColor);
graphics.FillRectangle(&solid, x, y, m_W, m_H); graphics.FillRectangle(&solid, r);
} }
else else
{ {
Rect r(x, y, m_W, m_H);
LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE); LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE);
graphics.FillRectangle(&gradient, r); graphics.FillRectangle(&gradient, r);
} }
@ -835,15 +836,18 @@ bool CMeter::Draw(Graphics& graphics)
int x = GetX(); int x = GetX();
int y = GetY(); int y = GetY();
Pen light(Color(255, 255, 255, 255)); Color lightColor(255, 255, 255, 255);
Pen dark(Color(255, 0, 0, 0)); Color darkColor(255, 0, 0, 0);
if (m_SolidBevel == BEVELTYPE_DOWN) if (m_SolidBevel == BEVELTYPE_DOWN)
{ {
light.SetColor(Color(255, 0, 0, 0)); lightColor.SetValue(Color::MakeARGB(255, 0, 0, 0));
dark.SetColor(Color(255, 255, 255, 255)); darkColor.SetValue(Color::MakeARGB(255, 255, 255, 255));
} }
Pen light(lightColor);
Pen dark(darkColor);
// The bevel is drawn outside the meter // The bevel is drawn outside the meter
Rect rect(x - 2, y - 2, m_W + 4, m_H + 4); Rect rect(x - 2, y - 2, m_W + 4, m_H + 4);
DrawBevel(graphics, rect, light, dark); DrawBevel(graphics, rect, light, dark);
@ -857,7 +861,7 @@ bool CMeter::Draw(Graphics& graphics)
** **
** Draws a bevel inside the given area ** Draws a bevel inside the given area
*/ */
void CMeter::DrawBevel(Graphics& graphics, Rect& rect, Pen& light, Pen& dark) void CMeter::DrawBevel(Graphics& graphics, const Rect& rect, const Pen& light, const Pen& dark)
{ {
int l = rect.GetLeft(); int l = rect.GetLeft();
int r = rect.GetRight() - 1; int r = rect.GetRight() - 1;

View File

@ -94,7 +94,7 @@ public:
static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow); static CMeter* Create(const WCHAR* meter, CMeterWindow* meterWindow);
static void DrawBevel(Gdiplus::Graphics& graphics, Gdiplus::Rect& rect, Gdiplus::Pen& light, Gdiplus::Pen& dark); static void DrawBevel(Gdiplus::Graphics& graphics, const Gdiplus::Rect& rect, const Gdiplus::Pen& light, const Gdiplus::Pen& dark);
protected: protected:

View File

@ -2258,40 +2258,6 @@ bool CMeterWindow::ResizeWindow(bool reset)
m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH); m_Background = GrabDesktop(m_ScreenX, m_ScreenY, m_WindowW, m_WindowH);
} }
} }
else
{
if (m_WindowW != 0 && m_WindowH != 0)
{
// Create a solid color bitmap for the background
m_Background = new Bitmap(m_WindowW, m_WindowH, PixelFormat32bppARGB);
Graphics graphics(m_Background);
if (m_SolidColor.GetValue() == m_SolidColor2.GetValue())
{
graphics.Clear(m_SolidColor);
}
else
{
Rect r(0, 0, m_WindowW, m_WindowH);
LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE);
graphics.FillRectangle(&gradient, r);
}
if (m_SolidBevel != BEVELTYPE_NONE)
{
Pen light(Color(255, 255, 255, 255));
Pen dark(Color(255, 0, 0, 0));
if (m_SolidBevel == BEVELTYPE_DOWN)
{
light.SetColor(Color(255, 0, 0, 0));
dark.SetColor(Color(255, 255, 255, 255));
}
Rect rect(0, 0, m_WindowW, m_WindowH);
CMeter::DrawBevel(graphics, rect, light, dark);
}
}
}
} }
return true; return true;
@ -2379,6 +2345,44 @@ void CMeterWindow::Redraw()
Rect r(0, 0, m_WindowW, m_WindowH); Rect r(0, 0, m_WindowW, m_WindowH);
graphics.DrawImage(m_Background, r, 0, 0, m_Background->GetWidth(), m_Background->GetHeight(), UnitPixel); graphics.DrawImage(m_Background, r, 0, 0, m_Background->GetWidth(), m_Background->GetHeight(), UnitPixel);
} }
else if (m_BackgroundMode == BGMODE_SOLID)
{
// Draw the solid color background
if (m_WindowW != 0 && m_WindowH != 0)
{
Rect r(0, 0, m_WindowW, m_WindowH);
if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0)
{
if (m_SolidColor.GetValue() == m_SolidColor2.GetValue())
{
graphics.Clear(m_SolidColor);
}
else
{
LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE);
graphics.FillRectangle(&gradient, r);
}
}
if (m_SolidBevel != BEVELTYPE_NONE)
{
Color lightColor(255, 255, 255, 255);
Color darkColor(255, 0, 0, 0);
if (m_SolidBevel == BEVELTYPE_DOWN)
{
lightColor.SetValue(Color::MakeARGB(255, 0, 0, 0));
darkColor.SetValue(Color::MakeARGB(255, 255, 255, 255));
}
Pen light(lightColor);
Pen dark(darkColor);
CMeter::DrawBevel(graphics, r, light, dark);
}
}
}
// Draw the meters // Draw the meters
std::list<CMeter*>::const_iterator j = m_Meters.begin(); std::list<CMeter*>::const_iterator j = m_Meters.begin();