📄 2dscale.cpp
字号:
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
void C2DScale::_DrawTickMarks() {
double dStepX(m_dXMin);
double dStepY(m_dYMin);
int nBottom, nTop;
int nOffset;
if ((m_dwXStyle&TICK_OUTSIDE)||(m_dwXStyle&TICK_INSIDE)) {
if (m_dwXStyle&TICK_OUTSIDE)
nBottom = m_dwXStyle&AXIS_BOTTOM?m_pRect->bottom+TICK_LENGTH:m_pRect->top-TICK_LENGTH;
else
nBottom = m_dwXStyle&AXIS_BOTTOM?m_pRect->bottom:m_pRect->top;
if (m_dwXStyle&TICK_INSIDE)
nTop = m_dwXStyle&AXIS_BOTTOM?m_pRect->bottom-TICK_LENGTH:m_pRect->top+TICK_LENGTH;
else
nTop = m_dwXStyle&AXIS_BOTTOM?m_pRect->bottom:m_pRect->top;
nOffset = (int)(m_yDepth*sin(D2R(m_dHorzRotation)));
if (m_dwXStyle&AXIS_BOTTOM)
nOffset = 0;
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) {
if (!((long)dStepX%5)||(m_dwXStyle&TICK_MINOR))
break;
dStepX += 1;
}
}
//now start drawing the grats...
while (m_dwXStyle&TICK_TEXT&&dStepX<=m_dXMax) {
m_pDC->MoveTo(_XValueToPixel(m_dXMin)+nOffset, nBottom);
m_pDC->LineTo(_XValueToPixel(m_dXMin)+nOffset, nTop);
if ((long)dStepX%5&&!(m_dwXStyle&TICK_MINOR)) {
dStepX += 1;
continue;
}
m_pDC->MoveTo(_XValueToPixel(dStepX)+nOffset, nBottom);
m_pDC->LineTo(_XValueToPixel(dStepX)+nOffset, nTop);
dStepX += 1;
}
m_pDC->MoveTo(_XValueToPixel(m_dXMax)+nOffset, nBottom);
m_pDC->LineTo(_XValueToPixel(m_dXMax)+nOffset, nTop);
}
else {
while (dStepX<=m_dXMax) {
m_pDC->MoveTo(_XValueToPixel(dStepX)+nOffset, nBottom);
m_pDC->LineTo(_XValueToPixel(dStepX)+nOffset, nTop);
if (m_dwXStyle&TICK_MINOR)
dStepX += m_dMinorStepX;
else if (m_dwXStyle&TICK_MAJOR)
dStepX += m_dMajorStepX;
else
break;
}
}
}
if ((m_dwYStyle&TICK_OUTSIDE)||(m_dwYStyle&TICK_INSIDE)) {
if (m_dwYStyle&TICK_OUTSIDE)
nBottom = m_dwYStyle&AXIS_LEFT?m_pRect->left-TICK_LENGTH:m_pRect->right+TICK_LENGTH;
else
nBottom = m_dwYStyle&AXIS_LEFT?m_pRect->left:m_pRect->right;
if (m_dwYStyle&TICK_INSIDE)
nTop = m_dwYStyle&AXIS_LEFT?m_pRect->left+TICK_LENGTH:m_pRect->right-TICK_LENGTH;
else
nTop = m_dwYStyle&AXIS_LEFT?m_pRect->left:m_pRect->right;
nOffset = (int)(m_yDepth*sin(D2R(m_dVertRotation)));
if (m_dwYStyle&AXIS_LEFT)
nOffset = 0;
while (dStepY<=m_dYMax) {
m_pDC->MoveTo(nBottom, _YValueToPixel(dStepY)-nOffset);
m_pDC->LineTo(nTop, _YValueToPixel(dStepY)-nOffset);
if (m_dwYStyle&TICK_MINOR)
dStepY += m_dMinorStepY;
else if (m_dwYStyle&TICK_MAJOR)
dStepY += m_dMajorStepY;
else
break;
}
}
return;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_XValueToPixel() */
/* */
/* Purpose : converts a data point to an X pixel point */
/* */
/* Inputs : double dValue -> the data point to convert */
/* */
/* Outputs : int <- converted data point */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
int C2DScale::_XValueToPixel(double dValue) {
double dX = m_yDepth*sin(D2R(m_dHorzRotation));
double dRes = (m_pRect->Width()-dX)/(m_dXMax-m_dXMin);
return (int) ((dValue - m_dXMin) * dRes) + m_pRect->left;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_YValueToPixel() */
/* */
/* Purpose : converts a data point to a Y pixel point */
/* */
/* Inputs : double dValue -> the data point to convert */
/* */
/* Outputs : int <- converted data point */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
int C2DScale::_YValueToPixel(double dValue) {
double dY = m_yDepth*sin(D2R(m_dVertRotation));
double dRes = (m_pRect->Height()-dY)/(m_dYMin-m_dYMax);
return (int) (((dValue - m_dYMin) * dRes) + m_pRect->bottom);
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_XPixelToValue() */
/* */
/* Purpose : converts an X pixel point to a data point */
/* */
/* Inputs : double nPixel -> the pixel point to convert */
/* */
/* Outputs : int <- converted pixel point */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
double C2DScale::_XPixelToValue(int nPixel) {
double dRes = m_pRect->Width()/(m_dXMax-m_dXMin);
return (nPixel - m_pRect->left) / dRes + m_dXMin;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::_YPixelToValue() */
/* */
/* Purpose : converts a Y pixel point to a data point */
/* */
/* Inputs : double nPixel -> the pixel point to convert */
/* */
/* Outputs : int <- converted pixel point */
/* */
/* Author : Scott Pelger Date Created: 29JAN02 */
/* */
/* Revisions */
/* */
/* Engineer Date Description */
/* */
/* Scott Pelger 29JAN02 initial version */
/* */
/************************************************************************************************/
double C2DScale::_YPixelToValue(int nPixel) {
double dRes = m_pRect->Height()/(m_dYMax-m_dYMin);
return (nPixel - m_pRect->top) / dRes + m_dYMin;
}
/************************************************************************************************/
/* */
/* Function: C2DScale::SetAxisScale() */
/* */
/* Purpose : sets the scales of a axis based on the first arg */
/* */
/* Inputs : enum AXIS eAxis -> determines which axis these scales are for */
/* double dMin -> min scale */
/* double dMax -> max scale */
/* */
/* Outputs : NONE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -