BOOL AddPointInPolygon(CBCGPPointsArray& arPoly, const CBCGPPoint& pt) { if (FindPointInPolygon (arPoly, pt) != -1) { return FALSE; } arPoly.Add (pt); return TRUE; }
//******************************************************************************* CBCGPGeometry* CBCGPChartInterLineColoringEffect::CreateGeometry(const CBCGPPointsArray& arOrgPoints, const CBCGPRect& rectBounds, BCGPChartFormatSeries::ChartCurveType curveType, BOOL bClip) { CBCGPChartAxis* pXAxis = m_pSeries1->GetRelatedAxis(CBCGPChartSeries::AI_X); ASSERT_VALID(pXAxis); BOOL bIsVertical = pXAxis->IsVertical(); CBCGPGeometry* pGeometry = NULL; CBCGPPointsArray arPoints; arPoints.Append(arOrgPoints); CBCGPPoint ptStart = arPoints[0]; CBCGPPoint ptEnd = arPoints[arPoints.GetSize() - 1]; CBCGPPoint ptClipCorrectionStart = ptStart; CBCGPPoint ptClipCorrectionEnd = ptEnd; if (bIsVertical) { if (bClip) { if (pXAxis->m_bReverseOrder) { ptClipCorrectionStart.y -= 1.; ptClipCorrectionEnd.y += 1.; } else { ptClipCorrectionStart.y += 1.; ptClipCorrectionEnd.y -= 1.; } ptStart = CBCGPPoint(rectBounds.left, ptClipCorrectionStart.y); ptEnd = CBCGPPoint(rectBounds.left, ptClipCorrectionEnd.y); } else { ptStart = CBCGPPoint(rectBounds.left, ptStart.y); ptEnd = CBCGPPoint(rectBounds.left, ptEnd.y); } } else { if (bClip) { if (pXAxis->m_bReverseOrder) { ptClipCorrectionStart.x += 1.; ptClipCorrectionEnd.x -= 1.; } else { ptClipCorrectionStart.x -= 1.; ptClipCorrectionEnd.x += 1.; } ptStart = CBCGPPoint(ptClipCorrectionStart.x, rectBounds.bottom); ptEnd = CBCGPPoint(ptClipCorrectionEnd.x, rectBounds.bottom); } else { ptStart = CBCGPPoint(ptStart.x, rectBounds.bottom); ptEnd = CBCGPPoint(ptEnd.x, rectBounds.bottom); } } if (curveType == BCGPChartFormatSeries::CCT_SPLINE || curveType == BCGPChartFormatSeries::CCT_SPLINE_HERMITE) { CBCGPSplineGeometry::BCGP_SPLINE_TYPE splineType = CBCGPSplineGeometry::BCGP_SPLINE_TYPE_KB; if (curveType == BCGPChartFormatSeries::CCT_SPLINE_HERMITE) { splineType = CBCGPSplineGeometry::BCGP_SPLINE_TYPE_HERMITE; } CBCGPComplexGeometry* pComplex = new CBCGPComplexGeometry() ; CBCGPSplineGeometry geometryTop(arOrgPoints, splineType, FALSE); pComplex->AddPoints(geometryTop.GetPoints(), CBCGPPolygonGeometry::BCGP_CURVE_TYPE_BEZIER); if (bClip) { pComplex->AddLine(ptClipCorrectionEnd); } pComplex->AddLine(ptEnd); pComplex->AddLine(ptStart); if (bClip) { pComplex->AddLine(ptClipCorrectionStart); } pComplex->SetClosed(TRUE); pGeometry = pComplex; } else { if (bClip) { arPoints.Add(ptClipCorrectionEnd); } arPoints.Add(ptEnd); arPoints.Add(ptStart); if (bClip) { arPoints.Add(ptClipCorrectionStart); } pGeometry = new CBCGPPolygonGeometry(arPoints); } return pGeometry; }
//******************************************************************************* BOOL CBCGPLinearGaugeImpl::GetRangeShape(CBCGPRect& rect, CBCGPPolygonGeometry& shape, double dblStartValue, double dblFinishValue, double dblStartWidth, double dblFinishWidth, double dblOffsetFromFrame, int nScale) { rect.SetRectEmpty(); shape.Clear(); CBCGPPoint pt1; if (!ValueToPoint(dblStartValue, pt1, nScale)) { return FALSE; } CBCGPPoint pt2; if (!ValueToPoint(dblFinishValue, pt2, nScale)) { return FALSE; } const double scaleRatio = GetScaleRatioMid(); if (dblStartWidth == 0.) { CBCGPGaugeScaleObject* pScale = GetScale(nScale); if (pScale != NULL) { dblStartWidth = pScale->m_dblMajorTickMarkSize + pScale->m_dblOffsetFromFrame; } } if (dblFinishWidth == 0.) { dblFinishWidth = dblStartWidth; } dblStartWidth *= scaleRatio; dblFinishWidth *= scaleRatio; dblOffsetFromFrame *= scaleRatio; if (dblFinishWidth == dblStartWidth) { if (m_bIsVertical) { rect.left = pt1.x + dblOffsetFromFrame; rect.top = pt1.y; rect.right = pt1.x + dblStartWidth + dblOffsetFromFrame; rect.bottom = pt2.y; } else { rect.left = pt1.x; rect.top = pt1.y + dblOffsetFromFrame; rect.right = pt2.x; rect.bottom = pt1.y + dblStartWidth + dblOffsetFromFrame; } } else { CBCGPPointsArray arPoints; if (m_bIsVertical) { arPoints.Add(CBCGPPoint(pt1.x + dblOffsetFromFrame, pt1.y)); arPoints.Add(CBCGPPoint(pt2.x + dblOffsetFromFrame, pt2.y)); arPoints.Add(CBCGPPoint(pt2.x + dblOffsetFromFrame + dblFinishWidth, pt2.y)); arPoints.Add(CBCGPPoint(pt1.x + dblOffsetFromFrame + dblStartWidth, pt1.y)); } else { arPoints.Add(CBCGPPoint(pt1.x, pt1.y + dblOffsetFromFrame)); arPoints.Add(CBCGPPoint(pt2.x, pt2.y + dblOffsetFromFrame)); arPoints.Add(CBCGPPoint(pt2.x, pt2.y + dblOffsetFromFrame + dblFinishWidth)); arPoints.Add(CBCGPPoint(pt1.x, pt1.y + dblOffsetFromFrame + dblStartWidth)); } shape.SetPoints(arPoints); } return TRUE; }
//******************************************************************************* void CBCGPLinearGaugeImpl::CreatePointerPoints(CBCGPPointsArray& arPoints, int nPointerIndex, BOOL bShadow) { if (m_rect.IsRectEmpty()) { return; } CBCGPLinearGaugePointer* pData = DYNAMIC_DOWNCAST(CBCGPLinearGaugePointer, m_arData[nPointerIndex]); if (pData == NULL) { ASSERT(FALSE); return; } CBCGPGaugeScaleObject* pScale = GetScale(pData->GetScale()); if (pScale == NULL) { ASSERT(FALSE); return; } const double scaleRatio = GetScaleRatioMid(); double dblValue = pData->m_nAnimTimerID != 0 ? pData->m_dblAnimatedValue : pData->m_dblValue; double dblSizeMax = max(pScale->m_dblMajorTickMarkSize, 2. * pScale->m_dblMinorTickMarkSize) * scaleRatio; double dblSize = dblSizeMax; if (dblSize == 0) { dblSize = 8. * scaleRatio; } double dblSizePerc = bcg_clamp(pData->m_dblSize, 0.0, 1.0); if (dblSizePerc != 0.0) { dblSize = max(dblSize * dblSizePerc, 2.0); } CBCGPPoint point; if (!ValueToPoint(dblValue, point, pData->GetScale())) { return; } double offset = max(pScale->m_dblMajorTickMarkSize, pScale->m_dblMinorTickMarkSize) * scaleRatio; offset = max(offset, m_dblMaxRangeSize); double x = point.x; double y = point.y; if (dblSize < dblSizeMax && pData->GetPosition() != CBCGPLinearGaugePointer::BCGP_GAUGE_POSITION_NEAR) { double dblSizeDelta = dblSizeMax - dblSize; if (pData->GetPosition() == CBCGPLinearGaugePointer::BCGP_GAUGE_POSITION_CENTER) { dblSizeDelta /= 2.0; } if (m_bIsVertical) { x += dblSizeDelta; } else { y += dblSizeDelta; } } if (bShadow) { x += 2. * m_sizeScaleRatio.cx; y += 2. * m_sizeScaleRatio.cy; } const double delta = pData->m_dblWidth == 0 ? dblSize / 2 : (pData->m_dblWidth * scaleRatio) / 2; switch (pData->GetStyle()) { case CBCGPLinearGaugePointer::BCGP_GAUGE_NEEDLE_TRIANGLE: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x, y - delta)); arPoints.Add(CBCGPPoint(x, y + delta)); arPoints.Add(CBCGPPoint(x + dblSize, y)); } else { arPoints.Add(CBCGPPoint(x + delta, y)); arPoints.Add(CBCGPPoint(x - delta, y)); arPoints.Add(CBCGPPoint(x, y + dblSize)); } break; case CBCGPLinearGaugePointer::BCGP_GAUGE_NEEDLE_TRIANGLE_INV: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x + dblSize, y - delta)); arPoints.Add(CBCGPPoint(x + dblSize, y + delta)); arPoints.Add(CBCGPPoint(x, y)); } else { arPoints.Add(CBCGPPoint(x + delta, y + dblSize)); arPoints.Add(CBCGPPoint(x - delta, y + dblSize)); arPoints.Add(CBCGPPoint(x, y)); } break; case CBCGPLinearGaugePointer::BCGP_GAUGE_NEEDLE_RECT: case CBCGPLinearGaugePointer::BCGP_GAUGE_NEEDLE_CIRCLE: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x, y + delta)); arPoints.Add(CBCGPPoint(x, y - delta)); arPoints.Add(CBCGPPoint(x + dblSize, y - delta)); arPoints.Add(CBCGPPoint(x + dblSize, y + delta)); } else { arPoints.Add(CBCGPPoint(x + delta, y + dblSize)); arPoints.Add(CBCGPPoint(x - delta, y + dblSize)); arPoints.Add(CBCGPPoint(x - delta, y)); arPoints.Add(CBCGPPoint(x + delta, y)); } break; case CBCGPLinearGaugePointer::BCGP_GAUGE_NEEDLE_DIAMOND: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x + .5 * dblSize, y + delta)); arPoints.Add(CBCGPPoint(x, y)); arPoints.Add(CBCGPPoint(x + .5 * dblSize, y - delta)); arPoints.Add(CBCGPPoint(x + dblSize, y)); } else { arPoints.Add(CBCGPPoint(x, y + dblSize)); arPoints.Add(CBCGPPoint(x - delta, y + .5 * dblSize)); arPoints.Add(CBCGPPoint(x, y)); arPoints.Add(CBCGPPoint(x + delta, y + .5 * dblSize)); } } }
//********************************************************************************************************** void CBCGPLinearGaugeImpl::OnDrawTickMark(CBCGPGraphicsManager* pGM, const CBCGPPoint& ptFrom, const CBCGPPoint& ptTo, CBCGPGaugeScaleObject::BCGP_TICKMARK_STYLE style, BOOL bMajor, double dblVal, int nScale, const CBCGPBrush& brFillIn, const CBCGPBrush& brOutlineIn) { ASSERT_VALID(pGM); CBCGPGaugeScaleObject* pScale = GetScale(nScale); if (pScale == NULL) { ASSERT(FALSE); return; } const double scaleRatio = GetScaleRatioMid(); const double dblSize = (bMajor ? pScale->m_dblMajorTickMarkSize : pScale->m_dblMinorTickMarkSize) * scaleRatio; const CBCGPGaugeColoredRangeObject* pRange = GetColoredRangeByValue(dblVal, nScale, BCGP_GAUGE_RANGE_TICKMARK_COLOR); const CBCGPBrush& brFill = (pRange != NULL && !pRange->m_brTickMarkFill.IsEmpty()) ? pRange->m_brTickMarkFill : (brFillIn.IsEmpty() ? m_Colors.m_brTickMarkFill : brFillIn); const CBCGPBrush& brOutline = (pRange != NULL && !pRange->m_brTickMarkOutline.IsEmpty()) ? pRange->m_brTickMarkOutline : (brOutlineIn.IsEmpty() ? m_Colors.m_brTickMarkOutline : brOutlineIn); switch (style) { case CBCGPGaugeScaleObject::BCGP_TICKMARK_LINE: pGM->DrawLine(ptFrom, ptTo, brOutline, scaleRatio); break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE: case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE_INV: case CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX: { CBCGPPointsArray arPoints; const double dblWidth = (style == CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX) ? (dblSize / 4.) : (bMajor ? (dblSize * 2. / 3.) : (dblSize / 2.)); const double dx = m_bIsVertical ? dblSize : max(dblWidth * .5, 3); const double dy = m_bIsVertical ? max(dblWidth * .5, 3) : dblSize; double x = ptTo.x; double y = ptTo.y; switch (style) { case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y + dy)); arPoints.Add(CBCGPPoint(x, y)); } else { arPoints.Add(CBCGPPoint(x + dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x, y)); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE_INV: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x, y - dy)); arPoints.Add(CBCGPPoint(x, y + dy)); arPoints.Add(CBCGPPoint(x - dx, y)); } else { arPoints.Add(CBCGPPoint(x + dx, y)); arPoints.Add(CBCGPPoint(x - dx, y)); arPoints.Add(CBCGPPoint(x, y - dy)); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y + dy)); arPoints.Add(CBCGPPoint(x, y + dy)); arPoints.Add(CBCGPPoint(x, y - dy)); } else { arPoints.Add(CBCGPPoint(x + dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y)); arPoints.Add(CBCGPPoint(x + dx, y)); } break; } CBCGPPolygonGeometry rgn(arPoints); pGM->FillGeometry(rgn, brFill); pGM->DrawGeometry(rgn, brOutline, scaleRatio); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_CIRCLE: { CBCGPPoint ptCenter( .5 * (ptFrom.x + ptTo.x), .5 * (ptFrom.y + ptTo.y)); const double dblRadius = bMajor ? (dblSize / 2.) : (dblSize / 4.); CBCGPEllipse ellipse(ptCenter, dblRadius, dblRadius); pGM->FillEllipse(ellipse, brFill); pGM->DrawEllipse(ellipse, brOutline, scaleRatio); if (scaleRatio == 1.0 && !pGM->IsSupported(BCGP_GRAPHICS_MANAGER_ANTIALIAS)) { CBCGPEllipse ellipse1(ptCenter, dblRadius - 1., dblRadius - 1.); pGM->DrawEllipse(ellipse1, brOutline); } } break; } }
//******************************************************************************* 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; } }