CString CBCGPTagManager::WriteBrush (const CString& strTag, const CBCGPBrush& value) { CString strValue; WriteTag (strValue, WriteInt (s_BrushType, value.GetGradientType(), CBCGPBrush::BCGP_NO_GRADIENT)); if (value.GetGradientType() == CBCGPBrush::BCGP_NO_GRADIENT) { WriteTag (strValue, WriteColor (s_BrushColor, value.GetColor())); } else { CString strColors; WriteTag (strColors, WriteColor (s_BrushColor, value.GetColor())); WriteTag (strColors, WriteColor (s_BrushColor, value.GetGradientColor())); WriteItem (strValue, s_BrushColors, strColors); } WriteTag (strValue, WriteInt (s_Opacity, bcg_clamp(bcg_round(value.GetOpacity() * 255.0), 0, 255), 255)); CString str; WriteItem (str, strTag, strValue); return str; }
double bcg_double_precision(double value, int precision) { if (precision < 0) { return value; } if (value == 0.0) { return 0.0; } if (precision > DBL_DIG) { precision = DBL_DIG; } double fract = modf(value, &value); double prec = pow((double)10.0, (int)precision); if (fabs(fract) > DBL_EPSILON / 2.0) { double f = bcg_sign(fract) * DBL_EPSILON / 2.0; fract = bcg_round(fract * prec) / prec + f; } else { fract = 0.0; } return value + fract; }
//******************************************************************************* CBCGPSize CBCGPLinearGaugeImpl::GetTextLabelMaxSize(CBCGPGraphicsManager* pGM) { CBCGPSize sizeMaxLabel (5., 5.); for (int iScale = 0; iScale < m_arScales.GetSize(); iScale++) { CBCGPGaugeScaleObject* pScale = m_arScales[iScale]; ASSERT_VALID(pScale); double dblStep = (pScale->m_dblFinish > pScale->m_dblStart) ? pScale->m_dblStep : -pScale->m_dblStep; int i = 0; 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; } if (bIsMajorTick) { CString strLabel; GetTickMarkLabel(strLabel, pScale->m_strLabelFormat, dblVal, i); if (!strLabel.IsEmpty()) { CBCGPSize sizeText = GetTickMarkTextLabelSize(pGM, strLabel, m_textFormat); sizeMaxLabel.cx = max(sizeMaxLabel.cx, sizeText.cx); sizeMaxLabel.cy = max(sizeMaxLabel.cy, sizeText.cy); } } } } return sizeMaxLabel; }
//**************************************************************************************** void CBCGPEngine3D::FillPolygon(const CBCGPPointsArray& arPoints, const CBCGPBrush& brush) { int nNumPoints = (int)arPoints.GetSize(); if (m_pDefaultGM == NULL || nNumPoints == 0) { return; } ASSERT_VALID(m_pDefaultGM); if (m_pDefaultGM->GetType() == CBCGPGraphicsManager::BCGP_GRAPHICS_MANAGER_GDI) { CBCGPPolygonGeometry g(arPoints); g.SetTemporary(); m_pDefaultGM->FillGeometry(g, brush); } else { LPPOINT arPointsGDI = new POINT[nNumPoints]; for (int i = 0; i < nNumPoints; i++) { arPointsGDI[i] = CPoint(bcg_round(arPoints[i].x), bcg_round(arPoints[i].y)); } HRGN hrgn = ::CreatePolygonRgn(arPointsGDI, nNumPoints, ALTERNATE); UINT nBytesCount = ::GetRegionData(hrgn, sizeof(RGNDATA), NULL); if (nBytesCount == 0) { delete [] arPointsGDI; return; } LPBYTE lpRgnData = new BYTE[nBytesCount]; ZeroMemory( lpRgnData, nBytesCount); if (::GetRegionData(hrgn, nBytesCount, (LPRGNDATA)lpRgnData) != nBytesCount) { delete [] arPointsGDI; delete [] lpRgnData; return; } LPRGNDATA pData = (LPRGNDATA)lpRgnData; LPRECT points = (LPRECT)pData->Buffer; for (DWORD k = 0; k < pData->rdh.nCount; k++) { m_pDefaultGM->FillRectangle(CBCGPRect(points[k]), brush); } delete [] arPointsGDI; delete [] lpRgnData; DeleteObject(hrgn); } }
CString CBCGPTagManager::WriteColor (const CString& strTag, const CBCGPColor& value) { CString strValue; COLORREF clr = value; if (value.a == 1.0) { strValue.Format (_T("%d, %d, %d"), GetRValue (clr), GetGValue (clr), GetBValue (clr)); } else { strValue.Format (_T("%d, %d, %d, %d"), GetRValue (clr), GetGValue (clr), GetBValue (clr), bcg_clamp(bcg_round(value.a * 255.0), 0, 255)); } return WriteString (strTag, strValue); }
//******************************************************************************* 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); } } } }