Exemple #1
0
int bcg_CS_clip_inv(const CBCGPRect& rect, CBCGPPoint& pt1_1, CBCGPPoint& pt1_2,
					   CBCGPPoint* pt2_1, CBCGPPoint* pt2_2)
{
	if (rect.IsRectEmpty ())
	{
		return 1;
	}

	BOOL bInRect1 = rect.PtInRect (pt1_1);
	BOOL bInRect2 = rect.PtInRect (pt1_2);
	if (bInRect1 && bInRect2)
	{
		return 0;
	}

	if (pt1_1 == pt1_2)
	{
		return bInRect1 ? 0 : 1;
	}

	CBCGPPoint pt1(pt1_1);
	CBCGPPoint pt2(pt1_2);

	if (!bcg_CS_clip(rect, pt1, pt2))
	{
		return 1;
	}

	int count = 0;

 	if (bInRect1)
 	{
		pt1_1 = pt1;
		count = 1;
	}
	else if (bInRect2)
	{
		pt1_2 = pt2;
		count = 1;
	}
	else
	{
		count = 1;

		if (pt2_1 != NULL && pt2_2 != NULL)
		{
 			*pt2_1 = pt1;
 			*pt2_2 = pt1_2;

			count = 2;
		}

		pt1_2 = pt2;
	}

	return count;
}
//*******************************************************************************
CBCGPRect CBCGPChartObject::OnCalcBoundingRect()
{
	if (m_pXAxis == NULL && m_pYAxis == NULL || m_coordinateMode == CM_AXIS_OUTSIDE_MARK || m_coordinateMode == CM_AXIS_INSIDE_MARK ||
		m_pXAxis != NULL && !m_pXAxis->m_bInitialized)
	{
		return m_pParentChart->GetRect();
	}

	CBCGPRect rectXAxis;
	CBCGPRect rectYAxis;

	if (m_pXAxis != NULL)
	{
		rectXAxis = m_pXAxis->GetBoundingRect();
	}

	if (m_pYAxis != NULL)
	{
		rectYAxis = m_pYAxis->GetBoundingRect();
	}

	if (!rectXAxis.IsRectEmpty() && !rectYAxis.IsRectEmpty())
	{
		rectXAxis.IntersectRect(rectYAxis);
		if (rectXAxis.IsRectEmpty())
		{
			return rectYAxis;
		}
	}
	else if (rectXAxis.IsRectEmpty())
	{
		return rectYAxis;
	}

	return rectXAxis;
}
Exemple #3
0
//*****************************************************************************************
void CBCGPTreeMap::OnDraw(CBCGPGraphicsManager* pGM, const CBCGPRect& rectClip, DWORD dwFlags)
{
	if (IsDirty())
	{
		m_Root.RecalcLayout(pGM);
		SetDirty(FALSE);
	}

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

	if (m_Root.m_arSubNodes.GetSize() > 0)
	{
		pGM->FillRectangle(m_rect, m_brFill);
		m_Root.OnDraw(pGM, rectClip.IsRectEmpty() ? m_rect : rectClip, m_brFill);
	}
}
Exemple #4
0
BOOL bcg_CS_clip(const CBCGPRect& rect, CBCGPPoint& point1, CBCGPPoint& point2)
{
	if (rect.IsRectEmpty ())
	{
		return TRUE;
	}

	if (point1 == point2)
	{
		return rect.PtInRect(point1);
	}

	int code1 = bcg_CS_code(rect, point1);
	int code2 = bcg_CS_code(rect, point2);

	double kx = 0.0;
	double ky = 0.0;
	CBCGPSize d(point2.x - point1.x, point2.y - point1.y);
	if (d.cx != 0.0)
	{
		ky = d.cy / d.cx;
	}
	else if (d.cy == 0.0)
	{
		if (code1 == 0 && code2 == 0)
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}

	if (d.cy != 0.0)
	{
		kx = d.cx / d.cy;
	}

	BOOL visible = FALSE;
	CBCGPPoint pt1(point1);
	CBCGPPoint pt2(point2);

	int count_inv = 0;

	for(int i = 0; i < 4; i++)
	{
		if (code1 & code2)
		{
			break;
		}
		else if (code1 == 0 && code2 == 0)
		{
			visible = TRUE;
			break;
		}

		if (code1 == 0)
		{
			int c = code1;
			code1 = code2;
			code2 = c;

			CBCGPPoint p(pt1);
			pt1 = pt2;
			pt2 = p;

			count_inv++;
		}

		if (code1 & 0x01)
		{
			pt1.y += ky * (rect.left - pt1.x);
			pt1.x = rect.left;
		}
		else if (code1 & 0x02)
		{
			pt1.y += ky * (rect.right - pt1.x);
			pt1.x = rect.right;
		}
		else if (code1 & 0x04)
		{
			pt1.x += kx * (rect.top - pt1.y);
			pt1.y = rect.top;
		}
		else if (code1 & 0x08)
		{
			pt1.x += kx * (rect.bottom - pt1.y);
			pt1.y = rect.bottom;
		}

		code1 = bcg_CS_code(rect, pt1);
	}

	if (visible)
	{
		if ((count_inv % 2) != 0)
		{
			point1 = pt1;
			point2 = pt2;
		}
		else
		{
			point1 = pt2;
			point2 = pt1;
		}
	}

	return visible;
}
//*******************************************************************************
void CBCGPLinearGaugeImpl::OnDrawScale(CBCGPGraphicsManager* pGM, int nScale)
{
	CBCGPGaugeScaleObject* pScale = GetScale(nScale);
	if (pScale == NULL)
	{
		ASSERT(FALSE);
		return;
	}

	const double scaleRatio = GetScaleRatioMid();

	const CBCGPBrush& brFill = pScale->m_brFill.IsEmpty() ? m_Colors.m_brScaleFill : pScale->m_brFill;
	const CBCGPBrush& brOutline = pScale->m_brOutline.IsEmpty() ? m_Colors.m_brScaleOutline : pScale->m_brOutline;

	if (!brFill.IsEmpty() || !brOutline.IsEmpty())
	{
		CBCGPRect rectRange;
		CBCGPPolygonGeometry shapeRange;

		if (GetRangeShape(rectRange, shapeRange, 
			pScale->m_dblStart, pScale->m_dblFinish, 
			pScale->m_dblMajorTickMarkSize, pScale->m_dblMajorTickMarkSize,
			0, nScale))
		{
			if (!rectRange.IsRectEmpty())
			{
				pGM->FillRectangle(rectRange, brFill);
				pGM->DrawRectangle(rectRange, brOutline, scaleRatio);
			}
			else
			{
				pGM->FillGeometry(shapeRange, brFill);
				pGM->DrawGeometry(shapeRange, brOutline, scaleRatio);
			}
		}
	}

	int i = 0;
	double dblStep = (pScale->m_dblFinish > pScale->m_dblStart) ? pScale->m_dblStep : -pScale->m_dblStep;

	double dblMinorTickSize = pScale->m_dblMinorTickMarkSize * scaleRatio;
	double dblMajorTickSize = pScale->m_dblMajorTickMarkSize * scaleRatio;
	CBCGPGaugeScaleObject::BCGP_TICKMARK_POSITION position = pScale->m_MinorTickMarkPosition;
	
	for (double dblVal = pScale->m_dblStart; 
		(dblStep > 0. && dblVal <= pScale->m_dblFinish) || (dblStep < 0. && dblVal >= pScale->m_dblFinish); 
		dblVal += dblStep, i++)
	{
		const BOOL bIsLastTick = (pScale->m_dblFinish > pScale->m_dblStart && dblVal + dblStep > pScale->m_dblFinish);
		BOOL bIsMajorTick = pScale->m_dblMajorTickMarkStep != 0. && ((i % bcg_round(pScale->m_dblMajorTickMarkStep)) == 0);

		if (!bIsMajorTick && (i == 0 || bIsLastTick))
		{
			// Always draw first and last ticks
			bIsMajorTick = TRUE;
		}

		double dblCurrTickSize = bIsMajorTick ? dblMajorTickSize : dblMinorTickSize;

		CBCGPPoint ptFrom;
		ValueToPoint(dblVal, ptFrom, nScale);

		if (!bIsMajorTick && position != CBCGPGaugeScaleObject::BCGP_TICKMARK_POSITION_NEAR && 
			dblCurrTickSize < dblMajorTickSize)
		{
			double dblDeltaTick = dblMajorTickSize - dblCurrTickSize;

			if (position == CBCGPGaugeScaleObject::BCGP_TICKMARK_POSITION_CENTER)
			{
				dblDeltaTick /= 2.0;
			}

			if (m_bIsVertical)
			{
				ptFrom.x += dblDeltaTick;
			}
			else
			{
				ptFrom.y += dblDeltaTick;
			}
		}

		CBCGPPoint ptTo = ptFrom;

		if (m_bIsVertical)
		{
			ptTo.x += dblCurrTickSize;
		}
		else
		{
			ptTo.y += dblCurrTickSize;
		}

		if (dblCurrTickSize > 0.)
		{
			OnDrawTickMark(pGM, ptFrom, ptTo, 
				bIsMajorTick ? pScale->m_MajorTickMarkStyle : pScale->m_MinorTickMarkStyle,
				bIsMajorTick, dblVal, nScale,
				bIsMajorTick ? pScale->m_brTickMarkMajor : pScale->m_brTickMarkMinor,
				bIsMajorTick ? pScale->m_brTickMarkMajorOutline : pScale->m_brTickMarkMinorOutline);
		}

		if (bIsMajorTick)
		{
			CString strLabel;
			GetTickMarkLabel(strLabel, pScale->m_strLabelFormat, dblVal, nScale);

			if (!strLabel.IsEmpty())
			{
				double offset = 0;

				if (pScale->m_dblMajorTickMarkSize == 0.)
				{
					offset = m_dblMaxRangeSize;
				}

				CBCGPRect rectText;

				double xLabel = ptTo.x;
				double yLabel = ptTo.y;

				CBCGPSize sizeText = GetTickMarkTextLabelSize(pGM, strLabel, m_textFormat);

				if (m_bIsVertical)
				{
					rectText.left = xLabel + 2 + offset;
					rectText.top = yLabel - sizeText.cy / 2;
				}
				else
				{
					rectText.left = xLabel - sizeText.cx / 2;
					rectText.top = yLabel + offset;
				}

				rectText.right = rectText.left + sizeText.cx;
				rectText.bottom = rectText.top + sizeText.cy;

				OnDrawTickMarkTextLabel(pGM, m_textFormat, rectText, strLabel, dblVal, nScale, 
					pScale->m_brText.IsEmpty() ? m_Colors.m_brText : pScale->m_brText);
			}
		}
	}
}
//*******************************************************************************
void CBCGPLinearGaugeImpl::OnDraw(CBCGPGraphicsManager* pGMSrc, const CBCGPRect& /*rectClip*/, DWORD dwFlags/* = BCGP_DRAW_STATIC | BCGP_DRAW_DYNAMIC*/)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pGMSrc);

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

	BOOL bCacheImage = m_bCacheImage;

	if (pGMSrc->IsOffscreen())
	{
		bCacheImage = FALSE;
	}

	CBCGPGraphicsManager* pGM = pGMSrc;
	CBCGPGraphicsManager* pGMMem = NULL;

	CBCGPRect rectSaved;

	if (bCacheImage)
	{	
		if (m_ImageCache.GetHandle() == NULL)
		{
			SetDirty();
		}

		if (m_ImageCache.GetHandle() != NULL && !IsDirty() && (dwFlags & BCGP_DRAW_STATIC))
		{
			pGMSrc->DrawImage(m_ImageCache, m_rect.TopLeft());
			dwFlags &= ~BCGP_DRAW_STATIC;

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

		if (dwFlags & BCGP_DRAW_STATIC)
		{
			pGMMem = pGM->CreateOffScreenManager(m_rect, &m_ImageCache);

			if (pGMMem != NULL)
			{
				pGM = pGMMem;

				rectSaved = m_rect;
				m_rect = m_rect - m_rect.TopLeft();
			}
		}
	}

	if (IsDirty())
	{
		int i = 0;

		for (i = 0; i < m_arScales.GetSize(); i++)
		{
			CBCGPGaugeScaleObject* pScale = m_arScales[i];
			ASSERT_VALID(pScale);

			pScale->CleanUp();
		}

		SetDirty(FALSE);
	}

	CBCGPRect rect = m_rect;
	rect.DeflateRect(1., 1.);

	const double scaleRatio = GetScaleRatioMid();
	const double nFrameSize = m_nFrameSize * scaleRatio;

	if (dwFlags & BCGP_DRAW_STATIC)
	{
		const CBCGPBrush& brFill = m_nFrameSize <= 2 ? m_Colors.m_brFill : m_Colors.m_brFrameFill;

		pGM->FillRectangle(rect, brFill);
		pGM->DrawRectangle(rect, m_Colors.m_brFrameOutline, scaleRatio);

		if (scaleRatio == 1.0 && !pGM->IsSupported(BCGP_GRAPHICS_MANAGER_ANTIALIAS))
		{
			CBCGPRect rect1 = rect;
			rect1.DeflateRect(1, 1);

			pGM->DrawRectangle(rect1, m_Colors.m_brFrameOutline);
		}

		if (m_nFrameSize > 2)
		{
			CBCGPRect rectInternal = rect;
			rectInternal.DeflateRect(nFrameSize, nFrameSize);

			pGM->FillRectangle(rectInternal, m_Colors.m_brFill);
			pGM->DrawRectangle(rectInternal, m_Colors.m_brFrameOutline, scaleRatio);
		}

		m_sizeMaxLabel = GetTextLabelMaxSize(pGM);

		int i = 0;

		m_dblMaxRangeSize = 0.;

		// Draw colored ranges:
		for (i = 0; i < m_arRanges.GetSize(); i++)
		{
			CBCGPGaugeColoredRangeObject* pRange = m_arRanges[i];
			ASSERT_VALID(pRange);

			CBCGPRect rectRange;
			CBCGPPolygonGeometry shapeRange;

			if (GetRangeShape(rectRange, shapeRange, 
				pRange->m_dblStartValue, pRange->m_dblFinishValue, 
				pRange->m_dblStartWidth, pRange->m_dblFinishWidth,
				pRange->m_dblOffsetFromFrame, pRange->m_nScale))
			{
				if (!rectRange.IsRectEmpty())
				{
					pGM->FillRectangle(rectRange, pRange->m_brFill);
					pGM->DrawRectangle(rectRange, pRange->m_brOutline, scaleRatio);
				}
				else
				{
					pGM->FillGeometry(shapeRange, pRange->m_brFill);
					pGM->DrawGeometry(shapeRange, pRange->m_brOutline, scaleRatio);
				}

				m_dblMaxRangeSize = max(m_dblMaxRangeSize, max(pRange->m_dblStartWidth, pRange->m_dblFinishWidth) * scaleRatio);
			}
		}

		// Draw scales:
		for (i = 0; i < m_arScales.GetSize(); i++)
		{
			OnDrawScale(pGM, i);
		}
	}

	if (pGMMem != NULL)
	{
		delete pGMMem;
		pGM = pGMSrc;

		m_rect = rectSaved;

		pGMSrc->DrawImage(m_ImageCache, m_rect.TopLeft());
	}

	if (dwFlags & BCGP_DRAW_DYNAMIC)
	{
		CBCGPRect rectSaved = m_rect;
		m_rect.OffsetRect(-m_ptScrollOffset);

		int i = 0;

		for (i = 0; i < m_arData.GetSize(); i++)
		{
			CBCGPPointsArray pts;
			CBCGPPointsArray ptsShadow;

			CreatePointerPoints(pts, i, FALSE);

			if (pGM->IsSupported(BCGP_GRAPHICS_MANAGER_COLOR_OPACITY))
			{
				CreatePointerPoints(ptsShadow, i, TRUE);
			}

			OnDrawPointer(pGM, pts, ptsShadow, i);
		}

		m_rect = rectSaved;
	}
}
//***********************************************************************************************************
void CBCGPBaseVisualCtrl::DoPaint(CDC* pDC, CRect rectClip)
{
	CRect rectClient;
	GetClientRect(rectClient);

	m_bInPaint = TRUE;

	pDC->FillRect(rectClient, &globalData.brWindow);

	globalData.DrawParentBackground (this, pDC);

	CBCGPRect rect = GetRect();

	if (m_pGM == NULL)
	{
		m_pGM = CBCGPGraphicsManager::CreateInstance();
	}

	if (m_pGM == NULL)
	{
		m_bInPaint = FALSE;
		return;
	}

	if (rect.IsRectEmpty())
	{
		CRect rectClient;
		GetClientRect(rectClient);

		SetRect(rectClient);
		rect = GetRect();
	}

	m_pGM->BindDC(pDC, rect);

	if (m_dblScale != 0.0 && m_pGM->IsSupported(BCGP_GRAPHICS_MANAGER_SCALING))
	{
		m_pGM->SetScale(m_dblScale);
	}

	if (!m_pGM->BeginDraw())
	{
		return;
	}

	BOOL bSetClipRect = FALSE;

	if (rectClip.IsRectEmpty())
	{
		rectClip = rect;
	}
	else
	{
		bSetClipRect = TRUE;
		m_pGM->SetClipRect(rectClip);
	}

	OnDraw(m_pGM, rectClip);

	if (bSetClipRect)
	{
		m_pGM->ReleaseClipArea();
	}

	SetDirty(FALSE);

	m_pGM->EndDraw();

	m_bInPaint = FALSE;
}