Esempio n. 1
0
//*******************************************************************************
void CBCGPTextGaugeImpl::OnDraw(CBCGPGraphicsManager* pGM, const CBCGPRect& /*rectClip*/, DWORD dwFlags)
{
	ASSERT_VALID(pGM);

	if (m_rect.IsRectEmpty() || !m_bIsVisible || m_strText.IsEmpty())
	{
		return;
	}

	if ((dwFlags & m_DefaultDrawFlags) == 0)
	{
		return;
	}

	CBCGPRect rect = m_rect;
	if (m_bIsSubGauge)
	{
		rect.OffsetRect(-m_ptScrollOffset);
	}

	pGM->FillRectangle(rect, GetFillBrush ());

	const CBCGPBrush& br = m_bOff ? m_brTextLight : m_brText;

	CreateResources(CBCGPBrush(), FALSE);
	pGM->DrawText(m_strText, rect, m_textFormat, br);

	pGM->DrawRectangle(rect, GetOutlineBrush (), GetScaleRatioMid());
	
	SetDirty(FALSE);
}
Esempio n. 2
0
void CBCGPBaseTreeMapNode::DrawTextWidthShadow(CBCGPGraphicsManager* pGM, const CString& str, const CBCGPRect& rect, const CBCGPBrush& br, const CBCGPTextFormat& tf)
{
	ASSERT_VALID(pGM);

	CBCGPSize sizeText = pGM->GetTextSize(str, tf);

	if (sizeText.cx > rect.Width() || sizeText.cy > rect.Height())
	{
		return;
	}

	CBCGPRect rectShadow = rect;
	rectShadow.OffsetRect(1, 1);

	pGM->DrawText(str, rectShadow, tf, CBCGPBrush(CBCGPColor::Black));
	pGM->DrawText(str, rect, tf, br);
}
//*******************************************************************************
BOOL CBCGPLinearGaugeImpl::HitTestValue(const CBCGPPoint& pt, double& dblValue, int nScale, BOOL bInsideGauge) const
{
	CBCGPGaugeScaleObject* pScale = GetScale(nScale);
	if (pScale == NULL)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	CBCGPRect rect = m_rect;
	rect.OffsetRect(-m_ptScrollOffset);

	if (m_bIsVertical)
	{
		rect.DeflateRect((pScale->m_dblOffsetFromFrame + m_nFrameSize) * m_sizeScaleRatio.cx, m_sizeMaxLabel.cy / 2 + (m_nFrameSize + 1) * m_sizeScaleRatio.cy);
	}
	else
	{
		rect.DeflateRect(m_sizeMaxLabel.cx / 2 + (m_nFrameSize + 1) * m_sizeScaleRatio.cx, (pScale->m_dblOffsetFromFrame + m_nFrameSize) * m_sizeScaleRatio.cy);
	}

	if (bInsideGauge && !rect.PtInRect(pt))
	{
		return FALSE;
	}

	if (m_bIsVertical)
	{
		const double dblTotalSize = rect.Height();
		dblValue = pScale->m_dblStart + (rect.bottom - pt.y) * fabs(pScale->m_dblFinish - pScale->m_dblStart) / dblTotalSize;
	}
	else
	{
		const double dblTotalSize = rect.Width();
		dblValue = pScale->m_dblStart + (pt.x - rect.left) * fabs(pScale->m_dblFinish - pScale->m_dblStart) / dblTotalSize;
	}

	return TRUE;
}
//***************************************************************************************
void CBCGPRadialMenuObject::OnDraw(CBCGPGraphicsManager* pGM, const CBCGPRect& /*rectClip*/, DWORD dwFlags)
{
	if (dwFlags == BCGP_DRAW_STATIC)
	{
		return;
	}

	m_nShadowDepth = pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY) ? GetShadowDepth() : 0;

	CBCGPRect rect = m_rect;
	if (rect.Width() < rect.Height())
	{
		rect.top += (rect.Height() - rect.Width()) / 2;
		rect.bottom = rect.top + rect.Width();
	}
	else if (rect.Height() < rect.Width())
	{
		rect.left += (rect.Width() - rect.Height()) / 2;
		rect.right = rect.left + rect.Height();
	}

	rect.DeflateRect(2., 2.);

	rect.right -= m_nShadowDepth;
	rect.bottom -= m_nShadowDepth;

	const double radius = rect.Width() / 2;
	const double radiusSmall = INTERNAL_PART * rect.Width() + 1.0;
	const CBCGPPoint center = rect.CenterPoint();

	CBCGPSize sizeIcon((double)m_cxIcon, 16);

	if (!m_Icons.IsNull())
	{
		sizeIcon.cy = pGM->GetImageSize(m_Icons).cy;
	}

	const int nItems = (int)m_arItems.GetSize();

	if (IsDirty())
	{
		int nCircleItems = m_bHasCenterButton ? nItems - 1 : nItems;

		double dblDeltaAngle = nCircleItems == 0 ? 0. : 360. / nCircleItems;
		double dblStartAngle = 90. - dblDeltaAngle / 2;

		for (int i = 0; i < nItems; i++)
		{
			CBCGPRadialMenuItem* pItem = m_arItems[i];
			ASSERT_VALID(pItem);

			pItem->m_bIsCenter = i == nItems -1 && m_bHasCenterButton;

			pItem->m_Shape.Destroy();
			pItem->m_Shape.Clear();

			if (!pItem->m_bIsCenter)
			{
				double dblFinishAngle = dblStartAngle + dblDeltaAngle;

				const double dblStartAngleRad = bcg_deg2rad(dblStartAngle);
				const double dblFinishAngleRad = bcg_deg2rad(dblFinishAngle);
				const double dblMiddleAngleRad = bcg_deg2rad(dblStartAngle + dblDeltaAngle / 2);

				double angleStartCos = cos(dblStartAngleRad);
				double angleStartSin = sin(dblStartAngleRad);
				double angleFinishCos = cos(dblFinishAngleRad);
				double angleFinishSin = sin(dblFinishAngleRad);

				pItem->m_Shape.SetStart(
					CBCGPPoint(center.x + angleStartCos * radius, center.y - angleStartSin * radius));
				pItem->m_Shape.AddArc(
					CBCGPPoint(center.x + angleFinishCos * radius, center.y - angleFinishSin * radius),
					CBCGPSize(radius, radius), dblStartAngle > dblFinishAngle, FALSE);
				pItem->m_Shape.AddLine(
					CBCGPPoint(center.x + angleFinishCos * radiusSmall, center.y - angleFinishSin * radiusSmall));
				pItem->m_Shape.AddArc(
					CBCGPPoint(center.x + angleStartCos * radiusSmall, center.y - angleStartSin * radiusSmall),
					CBCGPSize(radiusSmall, radiusSmall), dblStartAngle < dblFinishAngle, FALSE);

				pItem->m_ptCenter = CBCGPPoint(
					center.x + cos(dblMiddleAngleRad) * 2 * radius / 3,
					center.y - sin(dblMiddleAngleRad) * 2 * radius / 3);

				dblStartAngle = dblFinishAngle;
			}
			else
			{
				pItem->m_Shape.SetStart(center);
				pItem->m_Shape.AddLine(center);
				pGM->CombineGeometry(pItem->m_Shape, pItem->m_Shape, CBCGPEllipseGeometry(CBCGPEllipse(center, radiusSmall, radiusSmall)), RGN_OR);

				pItem->m_ptCenter = center;
			}
		}
	}

	CBCGPEllipse ellipseInt(center, radiusSmall, radiusSmall);

	CBCGPRect rectShadow = rect;
	rectShadow.OffsetRect(m_nShadowDepth, m_nShadowDepth);

	if (!m_bHasCenterButton && m_pCtrl->GetSafeHwnd() != NULL && (m_pCtrl->GetExStyle() & WS_EX_LAYERED))
	{
		if (m_nShadowDepth > 0)
		{
			CBCGPEllipseGeometry egShadow(rectShadow);

			CBCGPPoint centerShadow = center;
			centerShadow.x += m_nShadowDepth;
			centerShadow.y += m_nShadowDepth;

			CBCGPEllipse ellipseIntShadow(centerShadow, radiusSmall, radiusSmall);
			CBCGPEllipseGeometry egInternalShadow(ellipseIntShadow);

			CBCGPComplexGeometry shapeShadow;
			pGM->CombineGeometry(shapeShadow, egShadow, egInternalShadow, RGN_DIFF);

			pGM->FillGeometry(shapeShadow, m_brShadow);
		}

		CBCGPEllipseGeometry eg(rect);
		CBCGPEllipseGeometry egInternal(ellipseInt);

		CBCGPComplexGeometry shape;
		pGM->CombineGeometry(shape, eg, egInternal, RGN_DIFF);

		pGM->FillGeometry(shape, m_brFill);

	}
	else
	{
		if (m_nShadowDepth > 0)
		{
			pGM->FillEllipse(rectShadow, m_brShadow);
		}

		pGM->FillEllipse(rect, m_brFill);
	}

	pGM->DrawEllipse(rect, m_brBorder);

	if (!pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY))
	{
		CBCGPRect rect1 = rect;
		rect1.DeflateRect(1, 1);

		pGM->DrawEllipse(rect1, m_brFill);
	}

	BOOL bIsCtrlDisabled = m_pCtrl->GetSafeHwnd() != NULL && !m_pCtrl->IsWindowEnabled();

	for (int i = 0; i < nItems; i++)
	{
		CBCGPRadialMenuItem* pItem = m_arItems[i];
		ASSERT_VALID(pItem);

		if (i == m_nHighlighted)
		{
			pGM->FillGeometry(pItem->m_Shape, m_nHighlighted == m_nPressed ? m_brPressed : 
				m_brHighlighted.IsEmpty() ? m_brFill : m_brHighlighted);
		}

		pItem->OnDrawIcon(pGM, bIsCtrlDisabled, m_Icons, sizeIcon);

		pGM->DrawGeometry(pItem->m_Shape, m_brBorder);
	}

	pGM->DrawEllipse(ellipseInt, m_brBorder);

	if (!pGM->IsSupported(BCGP_GRAPHICS_MANAGER_ANTIALIAS))
	{
		rect.InflateRect(1, 1);
		pGM->DrawEllipse(rect, m_brBorder);
	}

	if (m_pCtrl->GetSafeHwnd() != NULL && m_pCtrl->IsFocused() && !m_pCtrl->IsPopup())
	{
		rect.InflateRect(1, 1);
		pGM->DrawEllipse(rect, m_brFocusedBorder);
	}
}
//*******************************************************************************
void CBCGPChartObject::OnDrawShape(CBCGPGraphicsManager* pGM, const CBCGPRect& /*rectDiagram*/)
{
	ASSERT_VALID(this);

	if (m_rectScreen.IsRectNull() || m_rectScreen.IsRectEmpty())
	{
		return;
	}

	CBCGPRect rectShape = m_rectScreen;
	rectShape.Normalize();

	if (!m_format.m_brFillColor.IsEmpty())
	{
		if (m_dblShadowDepth > 0. && pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY))
		{
			CBCGPRect rectShadow = rectShape;
			rectShadow.OffsetRect(m_dblShadowDepth, m_dblShadowDepth);

			CBCGPGeometry geometryShadow;

			if (!m_szCornerRadius.IsNull())
			{
				pGM->CombineGeometry(geometryShadow, 
					CBCGPRoundedRectangleGeometry(CBCGPRoundedRect(rectShadow, m_szCornerRadius.cx, m_szCornerRadius.cy)), 
					CBCGPRoundedRectangleGeometry(CBCGPRoundedRect(rectShape, m_szCornerRadius.cx, m_szCornerRadius.cy)), 
					RGN_DIFF);
			}
			else
			{
				pGM->CombineGeometry(geometryShadow, 
					CBCGPRectangleGeometry(rectShadow), 
					CBCGPRectangleGeometry(rectShape), 
					RGN_DIFF);
			}

			pGM->FillGeometry(geometryShadow, m_brShadow);
		}

		if (!m_szCornerRadius.IsNull())
		{
			pGM->FillRoundedRectangle(CBCGPRoundedRect(rectShape, m_szCornerRadius.cx, m_szCornerRadius.cy), m_format.m_brFillColor);
		}
		else
		{
			pGM->FillRectangle(rectShape, m_format.m_brFillColor);
		}
	}
	
	if (!m_format.m_outlineFormat.m_brLineColor.IsEmpty())
	{
		if (!m_szCornerRadius.IsNull())
		{
			pGM->DrawRoundedRectangle(CBCGPRoundedRect(rectShape, m_szCornerRadius.cx, m_szCornerRadius.cy), m_format.m_outlineFormat.m_brLineColor, 
							m_format.m_outlineFormat.GetLineWidth(TRUE), 
							&m_format.m_outlineFormat.m_strokeStyle);
		}
		else
		{
			pGM->DrawRectangle(rectShape, m_format.m_outlineFormat.m_brLineColor, 
							m_format.m_outlineFormat.GetLineWidth(TRUE), 
							&m_format.m_outlineFormat.m_strokeStyle);
		}
	}
}
Esempio n. 6
0
//*******************************************************************************
void CBCGPKnob::CreatePointerPoints(double dblRadius,
                                    CBCGPPointsArray& arPoints,
                                    int nPointerIndex, BOOL bShadow)
{
    if (m_rect.IsRectEmpty())
    {
        return;
    }

    CBCGPRect rect = m_rect;

    CBCGPKnobPointer* pData = DYNAMIC_DOWNCAST(CBCGPKnobPointer, m_arData[nPointerIndex]);
    if (pData == NULL)
    {
        ASSERT(FALSE);
        return;
    }

    CBCGPCircularGaugeScale* pScale = GetScale(pData->GetScale());
    if (pScale == NULL)
    {
        ASSERT(FALSE);
        return;
    }

    const double scaleRatio = GetScaleRatioMid();

    double dblValue = pData->IsAnimated() ? pData->GetAnimatedValue() : pData->GetValue();

    double dblOffset = bcg_clamp(pData->GetOffsetFromCenter(), 0.0, 1.0);
    if (dblOffset == 0.0)
    {
        dblOffset = dblRadius * .5;
    }
    else
    {
        dblOffset = dblRadius * bcg_clamp(dblOffset, 0.5, 1.0);
    }

    double dblAngle = bcg_deg2rad(pScale->GetStartAngle()) - bcg_deg2rad(pScale->GetStartAngle() - pScale->GetFinishAngle()) * (dblValue - pScale->GetStart()) / (pScale->GetFinish() - pScale->GetStart());
    dblAngle = bcg_normalize_rad (dblAngle);

    if (bShadow)
    {
        rect.OffsetRect(2 * m_sizeScaleRatio.cx, 2 * m_sizeScaleRatio.cy);
    }

    CBCGPPoint center((rect.left + rect.right) / 2.0, (rect.top + rect.bottom) / 2.0);

    const double angleCos  = cos(dblAngle);
    const double angleSin  = sin(dblAngle);

    double dblWidth = bcg_clamp(pData->GetWidth(), 0.0, dblRadius / 10.0);
    const double dblPointerAngle = dblAngle - M_PI_2;

    switch (pData->GetStyle())
    {
    case CBCGPKnobPointer::BCGP_KNOB_POINTER_HANDLE:
    {
        dblRadius -= .2 * scaleRatio;
        double dblExtend = (dblRadius * .9);
        double dblSize = dblRadius + dblExtend;
        center.x -= angleCos * dblExtend;
        center.y += angleSin * dblExtend;

        if (dblWidth == 0.0)
        {
            dblWidth = dblRadius / 3.0;
        }

        dblWidth *= 0.5;

        if (dblWidth < 1.0)
        {
            arPoints.Add(center);

            arPoints.Add(CBCGPPoint(
                             center.x + angleCos * dblSize,
                             center.y - angleSin * dblSize));
        }
        else
        {
            double dblArrowLen = max(2.0 * dblWidth, 10.0 * scaleRatio);
            dblSize -= dblArrowLen;

            const double dx = cos(dblPointerAngle) * dblWidth;
            const double dy = -sin(dblPointerAngle) * dblWidth;

            arPoints.Add(CBCGPPoint(center.x + dx, center.y + dy));

            arPoints.Add(CBCGPPoint(center.x - dx, center.y - dy));

            const CBCGPPoint pt1(
                center.x + angleCos * dblSize - dx,
                center.y - angleSin * dblSize - dy);

            const CBCGPPoint pt2(
                center.x + angleCos * dblSize + dx,
                center.y - angleSin * dblSize + dy);

            arPoints.Add(pt1);

            arPoints.Add(CBCGPPoint(
                             center.x + angleCos * (dblSize + dblArrowLen),
                             center.y - angleSin * (dblSize + dblArrowLen)));

            arPoints.Add(pt2);
        }
    }
    break;

    case CBCGPKnobPointer::BCGP_KNOB_POINTER_LINE:
    {
        if (bShadow)
        {
            return;
        }

        if (dblWidth == 0.0)
        {
            dblWidth = 2. * scaleRatio;
        }

        const double dx = cos(dblPointerAngle) * dblWidth;
        const double dy = -sin(dblPointerAngle) * dblWidth;

        arPoints.Add(CBCGPPoint(center.x + angleCos * dblOffset - dx, center.y - angleSin * dblOffset - dy));
        arPoints.Add(CBCGPPoint(center.x + angleCos * dblOffset + dx, center.y - angleSin * dblOffset + dy));

        dblOffset = dblRadius - 4. * scaleRatio;

        arPoints.Add(CBCGPPoint(center.x + angleCos * dblOffset + dx, center.y - angleSin * dblOffset + dy));
        arPoints.Add(CBCGPPoint(center.x + angleCos * dblOffset - dx, center.y - angleSin * dblOffset - dy));
    }
    break;

    case CBCGPKnobPointer::BCGP_KNOB_POINTER_CIRCLE:
    {
        if (bShadow)
        {
            return;
        }

        if (dblWidth == 0.0)
        {
            dblWidth = max(2. * scaleRatio, dblRadius / 8);
        }

        dblOffset = dblRadius - 6. * scaleRatio - dblWidth;

        arPoints.Add(CBCGPPoint(center.x + angleCos * dblOffset, center.y - angleSin * dblOffset));
        arPoints.Add(CBCGPPoint(dblWidth, dblWidth));
    }
    break;
    }
}