//******************************************************************************* void CBCGPChartTextObject::OnDrawShape(CBCGPGraphicsManager* pGM, const CBCGPRect& rectDiagram) { if (m_bDrawConnector && !m_format.m_outlineFormat.m_brLineColor.IsEmpty()) { CBCGPRect rectShape = m_rectScreen; rectShape.Normalize(); if (!rectShape.PtInRect(m_ptAnchor)) { CBCGPPoint pt; if (bcg_CS_intersect(rectShape, m_ptAnchor, rectShape.CenterPoint(), pt)) { pGM->DrawLine(m_ptAnchor, pt, m_format.m_outlineFormat.m_brLineColor, m_format.m_outlineFormat.GetLineWidth(TRUE), &m_format.m_outlineFormat.m_strokeStyle); } CBCGPEllipse ellipse(m_ptAnchor, 2 * m_format.GetScaleRatio().cx, 2 * m_format.GetScaleRatio().cy); pGM->FillEllipse(ellipse, m_format.m_brFillColor); pGM->DrawEllipse(ellipse, m_format.m_outlineFormat.m_brLineColor); } } CBCGPChartObject::OnDrawShape(pGM, rectDiagram); }
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; }
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; }
//******************************************************************************* BOOL CBCGPLinearGaugeImpl::OnSetMouseCursor(const CBCGPPoint& pt) { if (m_bIsInteractiveMode) { CBCGPRect rect = m_rect; rect.DeflateRect(m_nFrameSize, m_nFrameSize); if (rect.PtInRect(pt)) { ::SetCursor (globalData.GetHandCursor()); return TRUE; } } return CBCGPGaugeImpl::OnSetMouseCursor(pt); }
//******************************************************************************* BOOL CBCGPChartLineObject::HitTest(const CBCGPPoint& pt) const { double dblWidth = m_format.m_outlineFormat.GetLineWidth(TRUE) / 2; CBCGPPoint ptTopLeft = m_rectScreen.TopLeft(); CBCGPPoint ptBottomRight = m_rectScreen.BottomRight(); if (ptTopLeft.x == ptBottomRight.x) { CBCGPRect r = m_rectScreen.NormalizedRect(); r.InflateRect(dblWidth, dblWidth); return r.PtInRect(pt); } double dblACoef = (ptBottomRight.y - ptTopLeft.y) / (ptBottomRight.x - ptTopLeft.x); double dblBCoef = ptBottomRight.y - dblACoef * ptBottomRight.x; double dblY = dblACoef * pt.x + dblBCoef; return pt.y > dblY - dblWidth && pt.y < dblY + dblWidth; }
//******************************************************************************* 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; }
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; }