Example #1
0
/*
** 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;
}
Example #2
0
/*
** 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;
}