📄 drawsample.cpp
字号:
{
DRAWPOLYSHAPE drawpolyshape;
drawpolyshape.x1 = 0 ;
drawpolyshape.x2 = 0 ;
drawpolyshape.y1 = 0 ;
drawpolyshape.y2 = 0 ;
drawpolyshape.brushColor = 0 ;
drawpolyshape.brushStyle = 0 ;
drawpolyshape.brushHatch = 0 ;
drawpolyshape.fillStyle = 0 ;
drawpolyshape.fromColor = 0 ;
drawpolyshape.toColor = 0 ;
drawpolyshape.penColor = 0 ;
drawpolyshape.penStyle = 0 ;
drawpolyshape.penWidth = 1 ;
drawpolyshape.nSize = 7 ;
POINT array[ 7 ] ;
array[ 0 ].x = int( 32 * fact ) ;
array[ 0 ].y = int( 38 * fact ) ;
array[ 1 ].x = int( 32 * fact ) + int( int( 3 * fact ) * sin( PI / 12 ) ) ;
array[ 1 ].y = int( 38 * fact ) - int( int( 3 * fact ) * cos( PI / 12 ) ) ;
array[ 2 ].x = int( 32 * fact ) - int( int( 3 * fact ) * sin( PI / 4 ) ) ;
array[ 2 ].y = int( 38 * fact ) - int( int( 3 * fact ) * cos( PI / 4 ) ) ;
array[ 3 ].x = int( 32 * fact ) ;
array[ 3 ].y = int( 38 * fact ) ;
array[ 4 ].x = int( 32 * fact ) - int( int( 3 * fact ) * sin( PI / 12 ) ) ;
array[ 4 ].y = int( 38 * fact ) + int( int( 3 * fact ) * cos( PI / 12 ) ) ;
array[ 5 ].x = int( 32 * fact ) + int( int( 3 * fact ) * sin( PI / 4 ) ) ;
array[ 5 ].y = int( 38 * fact ) + int( int( 3 * fact ) * cos( PI / 4 ) ) ;
array[ 6 ].x = int( 32 * fact ) ;
array[ 6 ].y = int( 38 * fact ) ;
drawpolyshape.pArray = array ;
KVDrawPolyshape( &drawpolyshape ) ;
}
/* 绘制底座上的钜形(右) */
for ( int j = 0 ; j < 6 ; j ++ )
{
/* 绘制矩形框 */
{
DRAWRECT graphic;
graphic.x1 = int( 61 * fact ) - int( 3 * fact ) * ( j + 1 ) - int( fact ) * j ;
graphic.x2 = int( 61 * fact ) - int( 3 * fact ) * j - int( fact ) * j ;
graphic.y1 = int( 35 * fact ) ;
graphic.y2 = int( 41 * fact ) ;
graphic.brushColor = 8421504;
graphic.brushStyle = 0;
graphic.brushHatch = 0;
graphic.fillStyle = 0;
graphic.fromColor = 16777215;
graphic.toColor = 0;
graphic.penColor = 0;
graphic.penStyle = 0;
graphic.penWidth = 1;
KVDrawRoundRect( &graphic );
}
/* 绘制直线 */
{
DRAWRECT graphic;
graphic.x1 = int( 61 * fact ) - int( 3 * fact ) * ( j + 1 ) - int( fact ) * j ;
graphic.x2 = int( 61 * fact ) - int( 3 * fact ) * ( j + 1 ) - int( fact ) * j ;
graphic.y1 = int( 35 * fact ) ;
graphic.y2 = int( 41 * fact ) ;
graphic.brushColor = 16777215;
graphic.brushStyle = 0;
graphic.brushHatch = 0;
graphic.penColor = 16777215;
graphic.penStyle = 0;
graphic.penWidth = 1;
KVDrawLine( &graphic );
}
/* 绘制直线 */
{
DRAWRECT graphic;
graphic.x1 = int( 61 * fact ) - int( 3 * fact ) * ( j + 1 ) - int( fact ) * j ;
graphic.x2 = int( 61 * fact ) - int( 3 * fact ) * j - int( fact ) * j;
graphic.y1 = int( 35 * fact ) ;
graphic.y2 = int( 35 * fact ) ;
graphic.brushColor = 16777215;
graphic.brushStyle = 0;
graphic.brushHatch = 0;
graphic.penColor = 16777215;
graphic.penStyle = 0;
graphic.penWidth = 1;
KVDrawLine( &graphic );
}
}
return TRUE ;
}
/*
** 功 能:画表盘刻度
** 返 回 值:无
** 输入参数:
** rcMeterScale : 圆外切矩形 \ | /
** nStartAngle : 刻度线的起始角 ->\|/<-
** nEndAngle : 刻度线的结束角 nStartAngle ( | ) nEndAngle
** pScale : 刻度线结构指针,不能为 NULL |
** pLabel : 标签结构指针,为 NULL 不画标签
** bMarkInside : 刻度在内( TRUE ),刻度在外( FALSE )
*/
void DrawMeterScale( CRect & rcMeterScale,
int nStartAngle, int nEndAngle,
METERSCALE * pScale,
METERSCALELABEL * pLabel,
BOOL bMarkInside )
{
ASSERT( pScale != NULL ) ;
int nSign = bMarkInside ? -1 : 1 ;
// 计算圆心位置,圆的半径
long lRadius ;
if ( rcMeterScale.Width() < rcMeterScale.Height() )
lRadius = rcMeterScale.Width() / 2 ;
else
lRadius = rcMeterScale.Height() / 2 ;
CPoint ptCenter = rcMeterScale.CenterPoint() ;
lRadius += nSign * 2 ;
// 计算主刻度总角度,每一主刻度角度,每一副刻度角度
double dblScaleAngle = ( 360 - nStartAngle - nEndAngle ) * PI / 180 ;
double dblEveryPrimeScaleAngle = dblScaleAngle / ( pScale->nPrimeScale - 1 ) ;
double dblEverySlaveScaleAngle = dblEveryPrimeScaleAngle / ( pScale->nSlaveScale + 1 ) ;
// 画主,副刻度,主刻度标签
CPoint ptScaleFrom , ptScaleTo ;
for ( int i = 0 ; i < pScale->nPrimeScale ; i ++ )
{
// 画主刻度线
double dblPrimeScaleAngle = ( 270 - nStartAngle ) * PI / 180 - dblEveryPrimeScaleAngle * i ;
if ( fabs( dblPrimeScaleAngle ) >= 2 * PI )
dblPrimeScaleAngle = fmod( dblPrimeScaleAngle , 2 * PI ) ;
ptScaleFrom.x = ptCenter.x + long( lRadius * cos( dblPrimeScaleAngle ) ) ;
ptScaleFrom.y = ptCenter.y - long( lRadius * sin( dblPrimeScaleAngle ) ) ;
ptScaleTo.x = ptCenter.x + long( ( lRadius + nSign * pScale->nPrimeScaleLen ) * cos( dblPrimeScaleAngle ) ) ;
ptScaleTo.y = ptCenter.y - long( ( lRadius + nSign * pScale->nPrimeScaleLen ) * sin( dblPrimeScaleAngle ) ) ;
{
DRAWRECT drawrect ;
drawrect.x1 = ptScaleFrom.x ;
drawrect.y1 = ptScaleFrom.y ;
drawrect.x2 = ptScaleTo.x ;
drawrect.y2 = ptScaleTo.y ;
drawrect.brushColor = 16777215 ;
drawrect.brushStyle = 0 ;
drawrect.brushHatch = 0 ;
drawrect.penColor = pScale->clrPrimeScale ;
drawrect.penStyle = 0 ;
drawrect.penWidth = pScale->nPrimeScaleWidth ;
KVDrawLine( &drawrect ) ;
}
// 画主刻度标签
if ( pLabel != NULL && ( i % pLabel->nMainDiff == 0 || i == pScale->nPrimeScale - 1 ) )
{
LABELMETRIC labelmetric ;
labelmetric.textPenFontIndex = pLabel->nPenFontIndex ;
labelmetric.textPenFontHeight = pLabel->nPenFontHeight ;
labelmetric.textPenFontWidth = pLabel->nPenFontWidth ;
labelmetric.textPenFontStyle = pLabel->nPenFontStyle ;
CString strScale ;
double dblCurrScale = pLabel->fltMinScale + i * ( pLabel->fltMaxScale - pLabel->fltMinScale ) / ( pScale->nPrimeScale - 1 ) ;
if ( i == pScale->nPrimeScale - 1 )
dblCurrScale = pLabel->fltMaxScale ;
int nDecimalLen = pLabel->nLabelDecimalLen ;
strScale = GetScaleLabelText( dblCurrScale, nDecimalLen ) ;
TCHAR * pLabelText = new TCHAR[ strScale.GetLength() + 1 ] ;
_tcscpy( pLabelText , strScale ) ;
labelmetric.pLabel = pLabelText ;
CSize sizeLabel = KVGetLabelMetric( &labelmetric ) ;
CPoint ptLabelCenter ;
ptLabelCenter.x = ptCenter.x + long( ( lRadius + nSign * ( sizeLabel.cy * sqrt( 2 ) / 2 + pScale->nPrimeScaleLen + pLabel->nLabelOffset ) ) * cos( dblPrimeScaleAngle ) ) ;
ptLabelCenter.y = ptCenter.y - long( ( lRadius + nSign * ( sizeLabel.cy * sqrt( 2 ) / 2 + pScale->nPrimeScaleLen + pLabel->nLabelOffset ) ) * sin( dblPrimeScaleAngle ) ) ;
CPoint ptLabelTopLeft( 0, 0 ) ;
if ( fabs( dblPrimeScaleAngle ) < VERY_LITTLE )
{
ptLabelTopLeft.x = ptLabelCenter.x - sizeLabel.cy / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( fabs( dblPrimeScaleAngle - PI / 2 ) < VERY_LITTLE )
{
ptLabelTopLeft.x = ptLabelCenter.x - sizeLabel.cx / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( fabs( dblPrimeScaleAngle - PI ) < VERY_LITTLE )
{
ptLabelTopLeft.x = nSign == 1 ? ptLabelCenter.x + sizeLabel.cy / 2 - sizeLabel.cx : ptLabelCenter.x - sizeLabel.cy / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( fabs( dblPrimeScaleAngle - 3 * PI / 2 ) < VERY_LITTLE
|| fabs( dblPrimeScaleAngle - ( - PI / 2 ) ) < VERY_LITTLE )
{
ptLabelTopLeft.x = ptLabelCenter.x - sizeLabel.cy / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( dblPrimeScaleAngle > 0 && dblPrimeScaleAngle < PI / 2 )
{
ptLabelTopLeft.x = nSign == 1 ? ptLabelCenter.x - sizeLabel.cy / 2 : ptLabelCenter.x + sizeLabel.cy / 2 - sizeLabel.cx ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( dblPrimeScaleAngle > PI / 2 && dblPrimeScaleAngle < PI )
{
ptLabelTopLeft.x = nSign == 1 ? ptLabelCenter.x - sizeLabel.cx + sizeLabel.cy / 2 : ptLabelCenter.x - sizeLabel.cy / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( dblPrimeScaleAngle > PI && dblPrimeScaleAngle < 3 * PI / 2 )
{
ptLabelTopLeft.x = nSign == 1 ? ptLabelCenter.x - sizeLabel.cx + sizeLabel.cy / 2 : ptLabelCenter.x - sizeLabel.cy / 2 ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
else if ( dblPrimeScaleAngle < 0 && dblPrimeScaleAngle > - PI / 2 )
{
ptLabelTopLeft.x = nSign == 1 ? ptLabelCenter.x - sizeLabel.cy / 2 : ptLabelCenter.x + sizeLabel.cy / 2 - sizeLabel.cx ;
ptLabelTopLeft.y = ptLabelCenter.y - sizeLabel.cy / 2 ;
}
{
DRAWLABEL drawlabel ;
drawlabel.x1 = ptLabelTopLeft.x ;
drawlabel.y1 = ptLabelTopLeft.y ;
drawlabel.x2 = ptLabelTopLeft.x + sizeLabel.cx ;
drawlabel.y2 = ptLabelTopLeft.y + sizeLabel.cy ;
drawlabel.brushColor = 16777215 ;
drawlabel.brushStyle = 0 ;
drawlabel.brushHatch = 0 ;
drawlabel.penColor = 0 ;
drawlabel.penStyle = 0 ;
drawlabel.penWidth = 0 ;
drawlabel.textPenFontStyle = pLabel->nPenFontStyle ;
drawlabel.textPenFontHeight = pLabel->nPenFontHeight ;
drawlabel.textPenFontWidth = pLabel->nPenFontWidth ;
drawlabel.textPenFontIndex = pLabel->nPenFontIndex ;
drawlabel.textPenColor = pLabel->clrLabelColor ;
drawlabel.pText = pLabelText ;
KVDrawLabel( &drawlabel );
delete pLabelText ;
}
} // if pLabel
// 画副刻度线
if ( i == pScale->nPrimeScale - 1 )
break ;
for ( int j = 1 ; j <= pScale->nSlaveScale ; j ++ )
{
double dblSlaveScaleAngle = dblPrimeScaleAngle - dblEverySlaveScaleAngle * j ;
ptScaleFrom.x = ptCenter.x + long( lRadius * cos( dblSlaveScaleAngle ) ) ;
ptScaleFrom.y = ptCenter.y - long( lRadius * sin( dblSlaveScaleAngle ) ) ;
ptScaleTo.x = ptCenter.x + long( ( lRadius + nSign * pScale->nSlaveScaleLen ) * cos( dblSlaveScaleAngle ) ) ;
ptScaleTo.y = ptCenter.y - long( ( lRadius + nSign * pScale->nSlaveScaleLen ) * sin( dblSlaveScaleAngle ) ) ;
{
DRAWRECT drawrect ;
drawrect.x1 = ptScaleFrom.x ;
drawrect.y1 = ptScaleFrom.y ;
drawrect.x2 = ptScaleTo.x ;
drawrect.y2 = ptScaleTo.y ;
drawrect.brushColor = 16777215 ;
drawrect.brushStyle = 0 ;
drawrect.brushHatch = 0 ;
drawrect.penColor = pScale->clrSlaveScale ;
drawrect.penStyle = 0 ;
drawrect.penWidth = pScale->nSlaveScaleWidth ;
KVDrawLine( &drawrect ) ;
}
} // for j
} // for i
}
/*
** 功 能:绘制表盘标签,限制在边界之内
** 参 数:
** graphic 标签结构
*/
void DrawMeterLabel( DRAWLABEL & graphic )
{
// 调整矩形
if ( graphic.x2 < graphic.x1 )
{
int nTemp = graphic.x1 ;
graphic.x1 = graphic.x2 ;
graphic.x2 = nTemp ;
}
if ( graphic.y2 < graphic.y1 )
{
int nTemp = graphic.y1 ;
graphic.y1 = graphic.y2 ;
graphic.y2 = nTemp ;
}
// 剪裁字符串以适应标签结构中的矩形
CString strLabel = MakeShortString( graphic, 0 );
// 绘制标签
TCHAR szLabel[ MAX_PATH ] ;
_tcscpy( szLabel, strLabel ) ;
LABELMETRIC labelmetric ;
labelmetric.textPenFontIndex = graphic.textPenFontIndex ;
labelmetric.textPenFontHeight = graphic.textPenFontHeight ;
labelmetric.textPenFontWidth = 0 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -