⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawsample.cpp

📁 组态王图库开发包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// DrawSample.cpp: implementation of the DrawSample 
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <Math.h>
#include "Sample.h"
#include "MeterConfigDlg1.h"
#include "DrawSample.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

BOOL DrawSample( void * pConfig , float fact ,float x_fact , float y_fact , int nAction )
{
	switch ( nAction )
	{
	case WIZARD_CREATE2 :
		{
			_tcscpy( ((METER1*)pConfig)->szValName    , DEFAULT_VARNAME ) ;
			::LoadString( AfxGetResourceHandle(), IDS_DEFAULT_FACE_LABEL, ((METER1*)pConfig)->szFaceLabel, FACE_LABEL_LEN ) ; 
			((METER1*)pConfig)->dwFaceFillColor = 15718630 ;
			((METER1*)pConfig)->dwFaceTextColor = 0 ;
			((METER1*)pConfig)->nLabelDecimalLen = 0 ;
			((METER1*)pConfig)->dwLabelTextColor = 0 ;
			((METER1*)pConfig)->nLabelMainDiff = 1 ;
			((METER1*)pConfig)->fltMaxScale = 60 ;
			((METER1*)pConfig)->fltMinScale = 0 ;
			((METER1*)pConfig)->nPrimeScale = 7 ;
			((METER1*)pConfig)->nSlaveScale = 3 ;
			break ;
		}
	case WIZARD_EDIT2 :
		{
			CMeterConfigDlg1 dlg ;
			dlg.m_strFaceLabel   = ((METER1*)pConfig)->szFaceLabel  ;
			dlg.m_strValName     = ((METER1*)pConfig)->szValName ;
			dlg.m_dwFaceFillColor = ((METER1*)pConfig)->dwFaceFillColor ;
			dlg.m_dwFaceTextColor = ((METER1*)pConfig)->dwFaceTextColor ;
			dlg.m_nLabelDecimalLen= ((METER1*)pConfig)->nLabelDecimalLen ;
			dlg.m_dwLabelTextColor= ((METER1*)pConfig)->dwLabelTextColor;
			dlg.m_nLabelMainDiff  = ((METER1*)pConfig)->nLabelMainDiff ;
			dlg.m_fltMaxScale       = ((METER1*)pConfig)->fltMaxScale  ;
			dlg.m_fltMinScale       = ((METER1*)pConfig)->fltMinScale ;
			dlg.m_nPrimeScale     = ((METER1*)pConfig)->nPrimeScale ;
			dlg.m_nSlaveScale     = ((METER1*)pConfig)->nSlaveScale ;

			if ( dlg.DoModal() != IDOK )
				return FALSE ;
			else
			{
				_tcscpy( ((METER1*)pConfig)->szFaceLabel  , dlg.m_strFaceLabel ) ;
				_tcscpy( ((METER1*)pConfig)->szValName    , dlg.m_strValName ) ;
				((METER1*)pConfig)->dwFaceFillColor = dlg.m_dwFaceFillColor ;
				((METER1*)pConfig)->dwFaceTextColor = dlg.m_dwFaceTextColor ;
				((METER1*)pConfig)->nLabelDecimalLen = dlg.m_nLabelDecimalLen  ;
				((METER1*)pConfig)->dwLabelTextColor = dlg.m_dwLabelTextColor ;
				((METER1*)pConfig)->nLabelMainDiff = dlg.m_nLabelMainDiff ;
				((METER1*)pConfig)->fltMaxScale = dlg.m_fltMaxScale ;
				((METER1*)pConfig)->fltMinScale = dlg.m_fltMinScale ;
				((METER1*)pConfig)->nPrimeScale = dlg.m_nPrimeScale ;
				((METER1*)pConfig)->nSlaveScale = dlg.m_nSlaveScale ;
			}	
			break ;
		}
	case WIZARD_RESIZE2 :
		{
			break ;
		}
	default :
		ASSERT( FALSE ) ;
	}

	/* 获得表盘刻度标签外切矩形 */
	CRect rcScaleLabel ;
	int nOffset = 0 ;
	CRect rcScale( long( 6 * fact ), long( 9 * fact ), long( 58 * fact ), long( 61 * fact ) ) ;
	METERSCALE scale ;
	scale.nPrimeScale = ((METER1*)pConfig)->nPrimeScale ; // 主刻度线数目
	scale.nPrimeScaleLen = int( 3 * fact ) ;             // 主刻度线长度
	scale.nPrimeScaleWidth = 1 ;                         // 主刻度线宽度
	scale.clrPrimeScale = RGB( 0, 0, 0 ) ;               // 主刻度线颜色
	scale.nSlaveScale = ((METER1*)pConfig)->nSlaveScale ; // 副刻度线数目
	scale.nSlaveScaleLen = int( 1 * fact ) ;             // 副刻度线长度
	scale.nSlaveScaleWidth = 1 ;                         // 副刻度线宽度
	scale.clrSlaveScale = RGB( 0, 0, 0 ) ;               // 副刻度线颜色
	METERSCALELABEL label ;
	label.fltMinScale = ((METER1*)pConfig)->fltMinScale ; // 标签最小刻度
	label.fltMaxScale = ((METER1*)pConfig)->fltMaxScale ; // 标签最大刻度
	label.nLabelOffset = 1 ;                              // 标签距主刻度长度
	label.nPenFontIndex = FONT_INDEX ;                    // 标签字体索引
	label.nPenFontHeight = SCALE_FONT_HEIGHT ;            // 标签字体高度
	label.nPenFontWidth = 0 ;                             // 标签字体宽度
	label.nPenFontStyle = 0 ;	                     	  // 标签字体类型
	label.nLabelDecimalLen = ((METER1*)pConfig)->nLabelDecimalLen ; // 标签小数位数
    label.clrLabelColor = ((METER1*)pConfig)->dwLabelTextColor ;    // 标签颜色
	label.nMainDiff = ((METER1*)pConfig)->nLabelMainDiff; // 主刻度标签主偏差
	rcScaleLabel = GetMeterScaleLabelRect( rcScale, 130, 130, &scale, &label, FALSE ) ;
	if ( rcScaleLabel.left < int( 0 * fact ) )
	{
		nOffset = int( 0 * fact ) - rcScaleLabel.left + 1 ;
	}
	if( rcScaleLabel.right > int( 64 * fact ) )
	{
		if ( ( rcScaleLabel.right - int( 64 * fact ) ) > nOffset )
		{
			nOffset = rcScaleLabel.right - int( 64 * fact ) + 1 ;
		}

	}

	/* 绘制矩形外框 */
	{
	DRAWRECT graphic;
	graphic.x1 = int( 0  * fact ) - nOffset ;
	graphic.x2 = int( 64 * fact ) + nOffset ;
	graphic.y1 = int( 0  * fact );
	graphic.y2 = int( 42 * fact ) ;
	graphic.brushColor = ((METER1*)pConfig)->dwFaceFillColor;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.fillStyle = 0;
	graphic.fromColor = ((METER1*)pConfig)->dwFaceFillColor;
	graphic.toColor = 0;
	graphic.penColor = 0;
	graphic.penStyle = 0;
	graphic.penWidth = 1;
	KVDrawRoundRect( &graphic );
	}

	/* 绘制仪表指针 */
	{
	DRAWRECT graphic;
	graphic.x1 = int( 32 * fact ) ;
	graphic.x2 = int( 32 * fact ) ;
	graphic.y1 = int( 5  * fact ) ;
	graphic.y2 = int( 34 * fact ) ;
	graphic.brushColor = 16777215;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.penColor = 255;
	graphic.penStyle = 0;
	graphic.penWidth = 1;
	KVDrawLine( &graphic );
	}
	/* 设置仪表指针旋转动画连接 */
	if ( _tcslen( ((METER1*)pConfig)->szValName ) > 0 )
	{
	LINKROTATE links;
	links.minVal = ((METER1*)pConfig)->fltMinScale;
	links.maxVal = ((METER1*)pConfig)->fltMaxScale;
	links.minAngle = 50 ;
	links.maxAngle = 50 ;
	links.CenterPt.x = 0 ;
	links.CenterPt.y = long( 35 * fact ) - ( int( 5 * fact ) + int( 34 * fact ) ) /  2 ;
	links.pExpress = ((METER1*)pConfig)->szValName ;
	KVLinkRotate( &links );
	}

	/* 绘制表盘中心椭圆 */
	{
	DRAWRECT graphic;
	graphic.x1 = int( 26 * fact ) ;
	graphic.x2 = int( 39 * fact ) ;
	graphic.y1 = int( 28 * fact ) ;
	graphic.y2 = int( 38 * fact ) ;
	graphic.brushColor = 16777215;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.fillStyle = 1;
	graphic.fromColor = 16777215;
	graphic.toColor = 0;
	graphic.penColor = 0;
	graphic.penStyle = 5;
	graphic.penWidth = 1;
	KVDrawEllipse( &graphic );
	}
	
	/* 绘制底座矩形框 */
	{
	DRAWRECT graphic;
	graphic.x1 = int( 0  * fact ) - nOffset ;
	graphic.x2 = int( 64 * fact ) + nOffset ;
	graphic.y1 = int( 33 * fact ) ;
	graphic.y2 = int( 43 * fact ) ;
	graphic.brushColor = 8421504;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.fillStyle = 0;
	graphic.fromColor = 8421504;
	graphic.toColor = 0;
	graphic.penColor = 0;
	graphic.penStyle = 0;
	graphic.penWidth = 2;
	KVDrawRoundRect( &graphic );
	}
		
	/* 绘制刻度 */
	DrawMeterScale( rcScale,       // 圆外切矩形
					130, 130,      // 刻度线的起始角和结束角
					&scale,        // 刻度结构指针
					&label,        // 仪表结构指针
					FALSE ) ;      // 刻度外标

	/* 绘制表盘标签 */
	{
	DRAWLABEL graphic;
	graphic.x1 = int( 9  * fact ) ;
	graphic.y1 = int( 23 * fact ) ;
	graphic.x2 = int( 55 * fact ) ;
	graphic.y2 = int( 27 * fact ) ;
	graphic.brushColor = 0 ;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.penColor = 0;
	graphic.penStyle = 0;
	graphic.penWidth = 0;
	graphic.textPenFontStyle = 0;
	graphic.textPenFontHeight = SCALE_FONT_HEIGHT ;
	graphic.textPenFontWidth = 0;
	graphic.textPenFontIndex = FONT_INDEX ;
	graphic.textPenColor = ((METER1*)pConfig)->dwFaceTextColor;
	graphic.pText = ((METER1*)pConfig)->szFaceLabel ;
	DrawMeterLabel( graphic );
	}

	/* 绘制底座上的钜形(左) */
	for ( int i = 0 ; i < 6 ; i ++ )
	{
		/* 绘制矩形框 */
		{
		DRAWRECT graphic;
		graphic.x1 = int( 3 * fact ) * ( i + 1 ) + int( fact ) * i;
		graphic.x2 = int( 3 * fact ) * ( i + 1 ) + int( fact ) * i + int( 3 * fact );
		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( 3 * fact ) * ( i + 1 ) + int( fact ) * i;
		graphic.x2 = int( 3 * fact ) * ( i + 1 ) + int( fact ) * i;
		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( 3 * fact ) * ( i + 1 ) + int( fact ) * i ;
		graphic.x2 = int( 3 * fact ) * ( i + 1 ) + int( fact ) * i + int( 3 * fact ) ;
		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 );
		}
	}

	/* 绘制底座上的调谐椭圆 */
	{
	DRAWRECT graphic;
	graphic.x1 = int( 32 * fact ) - int( 3 * fact ) ;
	graphic.x2 = int( 32 * fact ) + int( 3 * fact ) + 1 ;
	graphic.y1 = int( 38 * fact ) - int( 3 * fact ) ;
	graphic.y2 = int( 38 * fact ) + int( 3 * fact ) + 1 ;
	graphic.brushColor = 255;
	graphic.brushStyle = 0;
	graphic.brushHatch = 0;
	graphic.fillStyle = 1;
	graphic.fromColor = 255;
	graphic.toColor = 0;
	graphic.penColor = 0;
	graphic.penStyle = 5;
	graphic.penWidth = 1;
	KVDrawEllipse( &graphic );
	}
	/* 绘制调谐椭圆中的多边形 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -