📄 2dscale.cpp
字号:
else
m_dMajorStepXDraw = m_dMajorStepX;
while (wMaxWidthXAxis*nLabels>_XValueToPixel(m_dXMax)-_XValueToPixel(m_dXMin)&&nLabels>0) {
m_dMajorStepXDraw = m_dMajorStepXDraw*2;
nLabels = (int)((m_dXMax-m_dXMin)/m_dMajorStepXDraw);
}
nLabels = (int)((m_dYMax-m_dYMin)/m_dMajorStepY);
m_dMajorStepYDraw = m_dMajorStepY;
while (pTickRectY->Height()*1.5*nLabels>_YValueToPixel(m_dYMin)-_YValueToPixel(m_dYMax)&&nLabels>0) {
m_dMajorStepYDraw = m_dMajorStepYDraw*2;
nLabels = (int)((m_dYMax-m_dYMin)/m_dMajorStepYDraw);
}
return;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_PrintXAxisLabelText() */
/* */
/* Purpose : draws the text for each axis, resizes the confining rect to further confine the data */
/* */
/* Inputs : CRect* pTickRectX -> bounding rect to draw in */
/* double dStepX -> value to print */
/* int nOffset -> anount ot offset due to axis text */
/* WORD wVertOffset -> anount ot offset due to axis text */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
void C2DScale::_PrintXAxisLabelText(CRect* pTickRectX, double dStepX, int nOffset, WORD wVertOffset) {
CString TickText;
TickText.Format(m_sXAxisFormat, dStepX);
int nRight(pTickRectX->right);
pTickRectX->SetRectEmpty();
m_pDC->DrawText(TickText, pTickRectX, DT_CALCRECT);
pTickRectX->OffsetRect(_XValueToPixel(dStepX)-pTickRectX->Width()/2+nOffset, wVertOffset);
if (nRight+10>=pTickRectX->left) {
pTickRectX->SetRectEmpty();
return;
}
m_pDC->DrawText(TickText, pTickRectX, DT_CENTER|DT_VCENTER);
return;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_DrawTickText() */
/* */
/* Purpose : draws the text for each axis, resizes the confining rect to further confine the data */
/* */
/* Inputs : WORD wMaxWidthXAxis -> max width of the X axis text */
/* WORD wMaxWidthYAxis -> max width of the X axis text */
/* int nXAxisOffset -> offset due to axis text */
/* int nYAxisOffset -> offset due to axis text */
/* CRect* pTickRectX -> bounding rect to draw in */
/* CRect* pTickRectY -> bounding rect to draw in */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
void C2DScale::_DrawTickText(WORD wMaxWidthXAxis, WORD wMaxWidthYAxis, int nXAxisOffset, int nYAxisOffset, CRect* pTickRectX, CRect* pTickRectY) {
if (m_dwXStyle&TICK_TEXT||m_dwYStyle&TICK_TEXT) {
double dStepX(m_dXMin);
double dStepY(m_dYMin);
CTime TTime;
CString TickText;
/****print the x axis labels****/
WORD wVertOffset(m_dwXStyle&AXIS_BOTTOM?m_pRect->bottom+pTickRectX->Height()/2+3:m_pRect->top-3*pTickRectX->Height()/2-3);
int nOffset((int)(m_yDepth*sin(D2R(m_dHorzRotation))));
if (m_dwXStyle&AXIS_BOTTOM)
nOffset = 0;
int nStep(1);
while (m_dMajorStepXDraw>nStep) {
nStep += 1;
}
if (TYPE_STRIP_CHART&m_dwGenericStyle||
TYPE_STRIP_CHART_FILLED&m_dwGenericStyle) {
if (m_bRemoved) {
//find out where we are supposed to start...
while (m_dwXStyle&TICK_TEXT&&dStepX<=m_dXMax+DBL_EPSILON) {
if (!((long)dStepX%nStep))
break;
dStepX += 1;
}
//now start printing the labels...
while (m_dwXStyle&TICK_TEXT&&dStepX<=m_dXMax+DBL_EPSILON) {
if ((long)dStepX%nStep) {
dStepX += 1;
continue;
}
_PrintXAxisLabelText(pTickRectX, dStepX, nOffset, wVertOffset);
dStepX += nStep;
}
}
else {
//print the first label
pTickRectX->SetRectEmpty();
_PrintXAxisLabelText(pTickRectX, dStepX, nOffset, wVertOffset);
//find out where we are supposed to start...
while (m_dwXStyle&TICK_TEXT && dStepX<=m_dXMax+DBL_EPSILON) {
if (!((long)dStepX%nStep))
break;
dStepX += 1;
}
if ((pTickRectX->right+pTickRectX->Width())>(_XValueToPixel(dStepX)-pTickRectX->Width()/2+nOffset))
dStepX += nStep;
//now start printing the labels...
while (m_dwXStyle&TICK_TEXT&&((dStepX<=m_dXMax+DBL_EPSILON))) {
if ((_XValueToPixel(dStepX)+pTickRectX->Width()-nOffset)<(_XValueToPixel(m_dXMax)-pTickRectX->Width()/2+nOffset))
_PrintXAxisLabelText(pTickRectX, dStepX, nOffset, wVertOffset);
dStepX += nStep;
}
if (m_dXMin+DBL_EPSILON>=m_dXMax) {
int dX = (int)(m_yDepth*sin(D2R(m_dHorzRotation)));
pTickRectX->SetRectEmpty();
TTime = (long)m_dXMax;
TickText = TTime.Format(m_sXAxisFormat);
m_pDC->DrawText(TickText, pTickRectX, DT_CALCRECT);
nOffset = (int)(m_pRect->right-dX-pTickRectX->Width()*1.5);
}
//print the last label
_PrintXAxisLabelText(pTickRectX, m_dXMax, nOffset, wVertOffset);
}
}
else {
pTickRectX->SetRectEmpty();
while (m_dwXStyle&TICK_TEXT && dStepX<=m_dXMax) {
_PrintXAxisLabelText(pTickRectX, dStepX, nOffset, wVertOffset);
dStepX += m_dMajorStepXDraw;
}
}
/****print the x axis labels****/
/****print the y axis labels****/
WORD wHorzOffset(m_dwYStyle&AXIS_LEFT?pTickRectY->Height()/2+3+nYAxisOffset-5:m_pRect->right+wMaxWidthYAxis/2-3);
nOffset = (int)(m_yDepth*sin(D2R(m_dVertRotation)));
if (m_dwYStyle&AXIS_LEFT)
nOffset = 0;
int nWidth(wMaxWidthYAxis);
while (m_dwYStyle&TICK_TEXT&&dStepY<=m_dYMax) {
pTickRectY->SetRectEmpty();
TickText.Format(m_sYAxisFormat, dStepY);
m_pDC->DrawText(TickText, pTickRectY, DT_CALCRECT);
pTickRectY->OffsetRect(wHorzOffset, _YValueToPixel(dStepY)-pTickRectY->Height()/2-nOffset);
pTickRectY->right = pTickRectY->left + nWidth;
m_pDC->DrawText(TickText, pTickRectY, DT_RIGHT|DT_VCENTER);
dStepY += m_dMajorStepYDraw;
}
/****print the y axis labels****/
}
else {
//adjust the top/bottom
if (m_dwXStyle&AXIS_BOTTOM)
m_pRect->bottom -= 10;
else
m_pRect->top += 10;
}
return;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_PrintAxisText() */
/* */
/* Purpose : prints the axis text in exists */
/* */
/* Inputs : int& nXAxisOffset -> amount of offset due to the x axis text */
/* int& nYAxisOffset -> amount of offset due to the y axis text */
/* */
/* Outputs : NONE */
/* */
/* Author : Scott Pelger Date Created: 15FEB02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 15FEB02 initial version */
/* */
/************************************************************************************************/
void C2DScale::_PrintAxisText(int& nXAxisOffset, int& nYAxisOffset) {
//the y axis text
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -