/* ** Draws the solid background & bevel if such are defined */ bool Meter::Draw(Gfx::Canvas& canvas) { if (IsHidden()) return false; canvas.SetAntiAliasing(m_AntiAlias); if (m_SolidColor.a != 0.0f || m_SolidColor2.a != 0.0f) { const FLOAT x = (FLOAT)GetX(); const FLOAT y = (FLOAT)GetY(); const D2D1_RECT_F r = D2D1::RectF(x, y, x + (FLOAT)m_W, y + (FLOAT)m_H); if (m_SolidColor.r == m_SolidColor2.r && m_SolidColor.g == m_SolidColor2.g && m_SolidColor.b == m_SolidColor2.b && m_SolidColor.a == m_SolidColor2.a) { canvas.FillRectangle(r, m_SolidColor); } else { canvas.FillGradientRectangle(r, m_SolidColor, m_SolidColor2, (FLOAT)m_SolidAngle); } } if (m_SolidBevel != BEVELTYPE_NONE) { D2D1_COLOR_F lightColor = D2D1::ColorF(D2D1::ColorF::White); D2D1_COLOR_F darkColor = D2D1::ColorF(D2D1::ColorF::Black); if (m_SolidBevel == BEVELTYPE_DOWN) { lightColor = D2D1::ColorF(D2D1::ColorF::Black); darkColor = D2D1::ColorF(D2D1::ColorF::White); } // The bevel is drawn outside the meter const FLOAT x = (FLOAT)GetX(); const FLOAT y = (FLOAT)GetY(); const D2D1_RECT_F rect = D2D1::RectF(x - 2.0f, y - 2.0f, x + (FLOAT)m_W + 2.0f, y + (FLOAT)m_H + 2.0f); DrawBevel(canvas, rect, lightColor, darkColor); } return true; }
/* ** Draws the solid background & bevel if such are defined */ bool Meter::Draw(Gfx::Canvas& canvas) { if (IsHidden()) return false; canvas.SetAntiAliasing(m_AntiAlias); if (m_SolidColor.GetA() != 0 || m_SolidColor2.GetA() != 0) { int x = GetX(); int y = GetY(); Rect r(x, y, m_W, m_H); if (m_SolidColor.GetValue() == m_SolidColor2.GetValue()) { SolidBrush solid(m_SolidColor); canvas.FillRectangle(r, solid); } else { Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext(); if (!m_AntiAlias) { // Fix the tiling issue in some GradientAngle values graphics.SetPixelOffsetMode(PixelOffsetModeHalf); } LinearGradientBrush gradient(r, m_SolidColor, m_SolidColor2, m_SolidAngle, TRUE); graphics.FillRectangle(&gradient, r); if (!m_AntiAlias) { graphics.SetPixelOffsetMode(PixelOffsetModeDefault); } canvas.EndGdiplusContext(); } } if (m_SolidBevel != BEVELTYPE_NONE) { Gdiplus::Graphics& graphics = canvas.BeginGdiplusContext(); int x = GetX(); int y = GetY(); 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); // The bevel is drawn outside the meter Rect rect(x - 2, y - 2, m_W + 4, m_H + 4); DrawBevel(graphics, rect, light, dark); canvas.EndGdiplusContext(); } return true; }
/* ** Draws the meter on the double buffer ** */ bool MeterBar::Draw(Gfx::Canvas& canvas) { if (!Meter::Draw(canvas)) return false; const D2D1_RECT_F rect = GetMeterRectPadding(); const FLOAT width = rect.right - rect.left; const FLOAT height = rect.bottom - rect.top; const FLOAT border = (FLOAT)m_Border; Gfx::D2DBitmap* drawBitmap = m_Image.GetImage(); if (m_Orientation == VERTICAL) { const FLOAT barSize = height - 2.0f * border; FLOAT size = barSize * (FLOAT)m_Value; size = min(barSize, size); size = max(0.0f, size); if (drawBitmap) { if (m_Flip) { if (border > 0.0f) { const auto d = Gfx::Util::ToRectF(rect.left, rect.top, width, border); const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, width, border); canvas.DrawBitmap(drawBitmap, d, s); const auto d2 = Gfx::Util::ToRectF(rect.left, rect.top + size + border, width, border); const auto s2 = Gfx::Util::ToRectF(0.0f, height - border, width, border); canvas.DrawBitmap(drawBitmap, d2, s2); } const auto d = Gfx::Util::ToRectF(rect.left, rect.top + border, width, size); const auto s = Gfx::Util::ToRectF(0.0f, border, width, size); canvas.DrawBitmap(drawBitmap, d, s); } else { if (border > 0.0f) { const auto d = Gfx::Util::ToRectF(rect.left, rect.bottom - size - 2.0f * border, width, border); const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, width, border); canvas.DrawBitmap(drawBitmap, d, s); const auto d2 = Gfx::Util::ToRectF(rect.left, rect.bottom - border, width, border); const auto s2 = Gfx::Util::ToRectF(0.0f, height - border, width, border); canvas.DrawBitmap(drawBitmap, d2, s2); } const auto d = Gfx::Util::ToRectF(rect.left, rect.bottom - size - border, width, size); const auto s = Gfx::Util::ToRectF(0.0f, height - size - border, width, size); canvas.DrawBitmap(drawBitmap, d, s); } } else { if (m_Flip) { const auto r = Gfx::Util::ToRectF(rect.left, rect.top, width, size); canvas.FillRectangle(r, m_Color); } else { const auto r = Gfx::Util::ToRectF(rect.left, rect.bottom - size, width, size); canvas.FillRectangle(r, m_Color); } } } else { const FLOAT barSize = width - 2.0f * border; FLOAT size = barSize * (FLOAT)m_Value; size = min(barSize, size); size = max(0.0f, size); if (drawBitmap) { if (m_Flip) { if (border > 0.0f) { const auto d = Gfx::Util::ToRectF(rect.right - size - 2.0f * border, rect.top, border, height); const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, border, height); canvas.DrawBitmap(drawBitmap, d, s); const auto d2 = Gfx::Util::ToRectF(rect.right - border, rect.top, border, height); const auto s2 = Gfx::Util::ToRectF(width - border, 0.0f, border, height); canvas.DrawBitmap(drawBitmap, d2, s2); } const auto d = Gfx::Util::ToRectF(rect.right - size - border, rect.top, size, height); const auto s = Gfx::Util::ToRectF(width - size - border, 0.0f, size, height); canvas.DrawBitmap(drawBitmap, d, s); } else { if (border > 0.0f) { const auto d = Gfx::Util::ToRectF(rect.left, rect.top, border, height); const auto s = Gfx::Util::ToRectF(0.0f, 0.0f, border, height); canvas.DrawBitmap(drawBitmap, d, s); const auto d2 = Gfx::Util::ToRectF(rect.left + size + border, rect.top, border, height); const auto s2 = Gfx::Util::ToRectF(width - border, 0.0f, border, height); canvas.DrawBitmap(drawBitmap, d2, s2); } const auto d = Gfx::Util::ToRectF(rect.left + border, rect.top, size, height); const auto s = Gfx::Util::ToRectF(border, 0.0f, size, height); canvas.DrawBitmap(drawBitmap, d, s); } } else { if (m_Flip) { const auto r = Gfx::Util::ToRectF(rect.right - size, rect.top, size, height); canvas.FillRectangle(r, m_Color); } else { const auto r = Gfx::Util::ToRectF(rect.left, rect.top, size, height); canvas.FillRectangle(r, m_Color); } } } return true; }
/* ** Draws the meter on the double buffer ** */ bool CMeterBar::Draw(Gfx::Canvas& canvas) { if (!CMeter::Draw(canvas)) return false; int x = GetX(); int y = GetY(); Bitmap* drawBitmap = m_Image.GetImage(); if (m_Orientation == VERTICAL) { int barSize = m_H - 2 * m_Border; int size = (int)(barSize * m_Value); size = min(barSize, size); size = max(0, size); if (drawBitmap) { if (m_Flip) { 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 r(x, y + m_Border, m_W, size); canvas.DrawBitmap(drawBitmap, r, Rect(0, m_Border, m_W, 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 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)); } } else { SolidBrush brush(m_Color); if (m_Flip) { Rect r(x, y, m_W, size); canvas.FillRectangle(r, brush); } else { Rect r(x, y + m_H - size, m_W, size); canvas.FillRectangle(r, brush); } } } else { int barSize = m_W - 2 * m_Border; int size = (int)(barSize * m_Value); size = min(barSize, size); size = max(0, size); if (drawBitmap) { if (m_Flip) { 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 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)); } 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 r(x + m_Border, y, size, m_H); canvas.DrawBitmap(drawBitmap, r, Rect(m_Border, 0, size, m_H)); } } else { SolidBrush brush(m_Color); if (m_Flip) { Rect r(x + m_W - size, y, size, m_H); canvas.FillRectangle(r, brush); } else { Rect r(x, y, size, m_H); canvas.FillRectangle(r, brush); } } } return true; }