//******************************************************************************* CBCGPChartTextObject::CBCGPChartTextObject(CBCGPChartVisualObject* pParentChart, const CString& strText, double dblValX, double dblValY, const CBCGPBrush& brTextColor, const CBCGPBrush& brFill, const CBCGPBrush& brOutline, double dblDistanceFromPoint, double dblAngle, BOOL bDrawConnector) { m_pParentChart = pParentChart; m_strText = strText; if (dblDistanceFromPoint == _EmptyCoordinate || dblAngle == _EmptyCoordinate) { m_bDrawConnector = FALSE; SetCoordinates(CBCGPPoint(dblValX, dblValY), CBCGPPoint(CBCGPChartObject::_EmptyCoordinate, CBCGPChartObject::_EmptyCoordinate), CM_CHART_VALUES); } else { m_bDrawConnector = bDrawConnector; if (m_bDrawConnector) { m_ptAnchor = CBCGPPoint(dblValX, dblValY); } SetCoordinates(dblValX, dblValY, dblDistanceFromPoint, dblAngle, CM_CHART_VALUE_DIST_ANGLE); } m_format.m_brTextColor = brTextColor; m_format.m_brFillColor = brFill; m_format.m_outlineFormat.m_brLineColor = brOutline; }
bool bcg_pointInPie (const CBCGPRect& rect, double dblAngleStart, double dblAngleFinish, const CBCGPPoint& ptTestIn, double dblDoughnutPercent) { if (!rect.PtInRect(ptTestIn)) { return false; } CBCGPPoint ptTest = ptTestIn; CBCGPPoint ptCenter = rect.CenterPoint(); double dblRadiusX = 0.5 * rect.Width(); double dblRadiusY = 0.5 * rect.Height(); if (dblRadiusX > dblRadiusY && dblRadiusX != 0.) { ptTest.Scale(CBCGPPoint(dblRadiusY / dblRadiusX, 1.0), ptCenter); } else if (dblRadiusY > dblRadiusX && dblRadiusY != 0.) { ptTest.Scale(CBCGPPoint(1.0, dblRadiusX / dblRadiusY, 1.0), ptCenter); } double dblAngle = bcg_normalize_rad(bcg_angle(ptCenter, ptTest)); dblAngleStart = bcg_normalize_rad(dblAngleStart); dblAngleFinish = bcg_normalize_rad(dblAngleFinish); BOOL bIn = FALSE; const BOOL bIsFullEllipse = bcg_IsFullEllipse(bcg_rad2deg(dblAngleStart), bcg_rad2deg(dblAngleFinish), TRUE, 0.1f); if (bIsFullEllipse) { bIn = TRUE; } else { if (dblAngleStart > dblAngleFinish) { bIn = (dblAngle <= dblAngleFinish) || (dblAngleStart <= dblAngle); } else { bIn = (dblAngle >= dblAngleStart) && (dblAngle <= dblAngleFinish); } } if (bIn) { double angleCos = cos(dblAngle); double angleSin = sin(dblAngle); CBCGPPoint ptEdge(ptCenter.x + angleCos * .5 * rect.Width(), ptCenter.y + angleSin * .5 * rect.Height()); double r = bcg_distance(ptEdge, ptCenter); double distToCenter = bcg_distance(ptTestIn, ptCenter); return (distToCenter <= r && distToCenter > r * dblDoughnutPercent); } return false; }
//******************************************************************************* void CBCGPDiagramVisualContainer::OnMouseUp(int nButton, const CBCGPPoint& pt) { if (m_bIsEditAnchorMode && m_nDragMode != HTNOWHERE) { m_bIsEditAnchorMode = FALSE; for (POSITION pos = m_lstSel.GetHeadPosition(); pos != NULL;) { CBCGPDiagramConnector* pObject = DYNAMIC_DOWNCAST(CBCGPDiagramConnector, m_lstSel.GetNext(pos)); if (pObject == NULL) { continue; } if (pObject->IsTrackingAnchorPoints ()) { pObject->EndTrackAnchorPoint (); pObject->Redraw (); } } m_ptDragStart = m_ptDragFinish = CBCGPPoint(-1, -1); Redraw(); return; } CBCGPVisualContainer::OnMouseUp (nButton, pt); }
//******************************************************************************* void CBCGPKnob::OnDrawTickMarkTextLabel(CBCGPGraphicsManager* pGM, const CBCGPTextFormat& tf, const CBCGPRect& rectText, const CString& strLabel, double dblVal, int nScale, const CBCGPBrush& br) { if (m_sizeIcon.cx == 0) { CBCGPCircularGaugeImpl::OnDrawTickMarkTextLabel(pGM, tf, rectText, strLabel, dblVal, nScale, br); return; } if (m_sizeIcon.cy == 0) { m_sizeIcon.cy = pGM->GetImageSize(m_Icons).cy; } CBCGPSize sizeIcon(m_sizeIcon.cx * m_sizeScaleRatio.cx, m_sizeIcon.cy * m_sizeScaleRatio.cy); double cx = 0.; double cy = 0.; double angle = 0.; if (ValueToAngle(dblVal, angle, nScale)) { cx = sizeIcon.cx * cos(bcg_deg2rad(angle)) / 2; } CBCGPPoint ptImage( rectText.left + max(0., .5 * (rectText.Width() - sizeIcon.cx)) + cx, rectText.top + max(0., .5 * (rectText.Height() - sizeIcon.cy)) + cy); pGM->DrawImage(m_Icons, ptImage, sizeIcon, 1., CBCGPImage::BCGP_IMAGE_INTERPOLATION_MODE_LINEAR, CBCGPRect(CBCGPPoint(m_sizeIcon.cx * m_nCurrLabelIndex, 0), m_sizeIcon)); }
//****************************************************************************** void CBCGPRadialMenuItem::CommonInit() { m_nID = 0; m_hIcon = NULL; m_bIsLargeIcon = FALSE; m_nImageIndex = -1; m_ptCenter = CBCGPPoint(-1, -1); m_bIsDisabled = FALSE; m_bIsChecked = FALSE; m_bDestroyIcon = FALSE; m_bIsCenter = FALSE; }
//******************************************************************************* CBCGPChartRangeObject::CBCGPChartRangeObject(CBCGPChartVisualObject* pParentChart, double dblVal1, double dblVal2, BOOL bHorz, const CBCGPBrush& brFill) { m_pParentChart = pParentChart; m_bIsForeground = FALSE; if (bHorz) { SetCoordinates( CBCGPPoint(CBCGPChartObject::_EmptyCoordinate, dblVal1), CBCGPPoint(CBCGPChartObject::_EmptyCoordinate, dblVal2), CM_CHART_VALUES); } else { SetCoordinates( CBCGPPoint(dblVal1, CBCGPChartObject::_EmptyCoordinate), CBCGPPoint(dblVal2, CBCGPChartObject::_EmptyCoordinate), CM_CHART_VALUES); } m_format.m_brFillColor = brFill; m_format.m_outlineFormat.m_brLineColor.Empty(); }
//******************************************************************************* CBCGPChartLineObject::CBCGPChartLineObject(CBCGPChartVisualObject* pParentChart, double dblVal, BOOL bHorz, const CBCGPBrush& brLine, double dblLineWidth, CBCGPStrokeStyle* pStrokeStyle) { m_pParentChart = pParentChart; if (bHorz) { SetCoordinates(CBCGPPoint(CBCGPChartObject::_EmptyCoordinate, dblVal), CBCGPPoint(CBCGPChartObject::_EmptyCoordinate, dblVal), CM_CHART_VALUES); } else { SetCoordinates(CBCGPPoint(dblVal, CBCGPChartObject::_EmptyCoordinate), CBCGPPoint(dblVal, CBCGPChartObject::_EmptyCoordinate), CM_CHART_VALUES); } m_format.m_outlineFormat.m_brLineColor = brLine; m_format.m_outlineFormat.m_dblWidth = dblLineWidth; if (pStrokeStyle != NULL) { m_format.m_outlineFormat.m_strokeStyle = *pStrokeStyle; } }
//******************************************************************************* void CBCGPAnalogClock::EnableDate(BOOL bEnable, BCGP_SUB_GAUGE_POS pos) { if (bEnable) { if (m_pDate != NULL) { return; } m_pDate = new CBCGPNumericIndicatorImpl; m_pDate->SetCells(2); m_pDate->SetDecimals(0); m_pDate->SetSeparatorWidth(0); CBCGPNumericIndicatorColors colors; colors.m_brFill = CBCGPBrush(CBCGPColor::White, CBCGPColor::LightGray, CBCGPBrush::BCGP_GRADIENT_HORIZONTAL); colors.m_brDigit = CBCGPBrush(CBCGPColor::Gray); m_pDate->SetColors(colors); AddSubGauge(m_pDate, pos, CBCGPSize(20, 15), CBCGPPoint(-5, 0)); } else { if (m_pDate == NULL) { return; } ASSERT_VALID(m_pDate); RemoveSubGauge(m_pDate); m_pDate = NULL; } OnSetClockTime(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 CBCGPRadialMenuItem::OnDrawIcon(CBCGPGraphicsManager* pGM, BOOL bIsCtrlDisabled, CBCGPImage& icons, CBCGPSize sizeIcon) { ASSERT_VALID(pGM); if (m_ptCenter == CBCGPPoint(-1, -1)) { return; } BOOL bIsDisabled = bIsCtrlDisabled || m_bIsDisabled; HICON hIcon = NULL; if (m_hIcon != NULL) { hIcon = m_hIcon; } else if (m_nImageIndex >= 0) { CBCGPPoint ptImage = m_ptCenter; ptImage.x -= .5 * sizeIcon.cx; ptImage.y -= .5 * sizeIcon.cy; pGM->DrawImage(icons, ptImage, sizeIcon, bIsDisabled ? .4 : 1., CBCGPImage::BCGP_IMAGE_INTERPOLATION_MODE_LINEAR, CBCGPRect(CBCGPPoint(sizeIcon.cx * m_nImageIndex, 0), sizeIcon)); } else { // Try to obtain icon from ribbon/toolbars: #ifndef _BCGSUITE_ #ifndef BCGP_EXCLUDE_RIBBON CFrameWnd* pParentFrame = DYNAMIC_DOWNCAST (CFrameWnd, AfxGetMainWnd()); CBCGPRibbonBar* pRibbonBar = NULL; CBCGPMDIFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, pParentFrame); if (pMainFrame != NULL) { pRibbonBar = pMainFrame->GetRibbonBar(); } else // Maybe, SDI frame... { CBCGPFrameWnd* pFrame = DYNAMIC_DOWNCAST (CBCGPFrameWnd, pParentFrame); if (pFrame != NULL) { pRibbonBar = pFrame->GetRibbonBar(); } } if (pRibbonBar != NULL) { ASSERT_VALID(pRibbonBar); hIcon = pRibbonBar->ExportImageToIcon(m_nID, FALSE); } else #endif #endif { #ifndef _BCGSUITE_ int nImage = CImageHash::GetImageOfCommand(m_nID, FALSE); #else int nImage = GetCmdMgr ()->GetCmdImage(m_nID, FALSE); #endif CBCGPToolBarImages* pImages = CBCGPToolBar::GetImages(); if (pImages != NULL && nImage >= 0) { hIcon = pImages->ExtractIcon(nImage); } } if (hIcon != NULL) { m_hIcon = hIcon; m_bDestroyIcon = TRUE; } } if (hIcon != NULL) { CBCGPImage image(hIcon); sizeIcon = pGM->GetImageSize(image); CBCGPPoint ptImage = m_ptCenter; ptImage.x -= .5 * sizeIcon.cx; ptImage.y -= .5 * sizeIcon.cy; pGM->DrawImage(image, ptImage, CBCGPSize(), bIsDisabled ? .4 : 1); } }
//******************************************************************************* 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; } }
//*********************************************************************************************************** BOOL CBCGPBaseVisualCtrl::DoPrint(CDC* pDCIn, CPrintInfo* pInfo) { CObject* pBaseVisual = GetVisualBaseObject(); if (pBaseVisual == NULL) { return FALSE; } CBCGPBaseVisualObject* pVisualObject = DYNAMIC_DOWNCAST(CBCGPBaseVisualObject, pBaseVisual); CBCGPVisualContainer* pVisualContainer = DYNAMIC_DOWNCAST(CBCGPVisualContainer, pBaseVisual); if (pVisualObject == NULL && pVisualContainer == NULL) { return FALSE; } CBCGPGraphicsManager* pGM = GetGraphicsManager(); if (pGM == NULL) { return FALSE; } ASSERT_VALID(pGM); CDC* pDC = pDCIn; CPrintDialog* pPrintDlg = NULL; if (pDC == NULL) { pPrintDlg = new CPrintDialog(FALSE); if (pPrintDlg->DoModal() == IDCANCEL) { delete pPrintDlg; return FALSE; } pDC = CDC::FromHandle(pPrintDlg->GetPrinterDC()); pDC->m_bPrinting = TRUE; CString strTitle; strTitle.LoadString(AFX_IDS_APP_TITLE); DOCINFO di; ZeroMemory(&di, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = strTitle; if (!pDC->StartDoc(&di)) { pDC->AbortDoc(); delete pPrintDlg; return FALSE; } pInfo = new CPrintInfo(); pInfo->m_rectDraw.SetRect(0,0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES)); } CSize size(pInfo->m_rectDraw.Size()); CBCGPRect rect(CBCGPPoint(), size); CBCGPRect rectControl(pVisualObject != NULL ? pVisualObject->GetRect() : pVisualContainer->GetRect()); CBCGPSize sizeScaleRatio((double)size.cx / rectControl.Width(), (double)size.cy / rectControl.Height()); double dAspect = min(sizeScaleRatio.cx, sizeScaleRatio.cy); sizeScaleRatio.cx = sizeScaleRatio.cy = dAspect; size.cx = bcg_clamp((int)(rectControl.Width() * dAspect), 0, size.cx); size.cy = bcg_clamp((int)(rectControl.Height() * dAspect), 0, size.cy); rect.SetSize(size); CDC dcPrint; CBitmap bmpPrint; CBitmap* pBmpPrintOld = NULL; CDC* pDCOut = NULL; CBrush brWhite(RGB(255, 255, 255)); if (DYNAMIC_DOWNCAST(CBCGPGraphicsManagerGDI, pGM) != NULL) { dcPrint.CreateCompatibleDC(NULL); bmpPrint.Attach(CBCGPDrawManager::CreateBitmap_32(size, NULL)); pBmpPrintOld = dcPrint.SelectObject (&bmpPrint); ASSERT(pBmpPrintOld != NULL); pDCOut = &dcPrint; } else { pGM->SetPrintInfo(pInfo); pDCOut = pDC; } pDCOut->FillRect((CRect)rect, &brWhite); pGM->BindDC(pDCOut); if (pGM->IsBindDCFailed()) { pDCOut->FillRect((CRect)rect, &brWhite); pDCOut->TextOut(0, 0, _T("Out of memory")); } else { pGM->BeginDraw(); CBCGPSize sizeScaleRatioOld; if (pVisualObject != NULL) { sizeScaleRatioOld = pVisualObject->GetScaleRatio(); pVisualObject->SetScaleRatio(sizeScaleRatio); pVisualObject->SetRect(rect); } else { sizeScaleRatioOld = pVisualContainer->GetScaleRatio(); pVisualContainer->SetScaleRatio(sizeScaleRatio); pVisualContainer->SetRect(rect); } pGM->Clear(); if (pVisualObject != NULL) { pVisualObject->OnDraw (pGM, rect); } else { pVisualContainer->OnDraw (pGM, rect); } pGM->EndDraw(); pGM->BindDC(NULL); if (pVisualObject != NULL) { pVisualObject->SetScaleRatio(sizeScaleRatioOld); } else { pVisualContainer->SetScaleRatio(sizeScaleRatioOld); } if (dcPrint.GetSafeHdc() != NULL) { CBCGPDrawManager::FillAlpha (rect, (HBITMAP)bmpPrint.GetSafeHandle (), 255); } } if (pVisualObject != NULL) { pVisualObject->SetRect(rectControl); pVisualObject->SetDirty (); } else { pVisualContainer->SetRect(rectControl); pVisualContainer->SetDirty (); } if (dcPrint.GetSafeHdc() != NULL) { BITMAP bmp = {0}; bmpPrint.GetBitmap (&bmp); CRect rectOut(pInfo->m_rectDraw.TopLeft (), CSize(bmp.bmWidth, bmp.bmHeight)); int mode = pDC->SetStretchBltMode(HALFTONE); pDC->BitBlt (rectOut.left, rectOut.top, rectOut.Width(), rectOut.Height(), &dcPrint, 0, 0, SRCCOPY); pDC->SetStretchBltMode(mode); dcPrint.SelectObject(pBmpPrintOld); } else { pGM->SetPrintInfo(NULL); } if (pPrintDlg != NULL) { pDC->EndDoc(); delete pPrintDlg; delete pInfo; } return TRUE; }
//******************************************************************************* 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; } }