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

📄 meter.c

📁 飞漫公司的minigui的1.6.8收费增值版本的demon等示例程序
💻 C
字号:
/*** $Id: meter.c,v 1.7 2005/02/18 08:30:52 lihong Exp $**** The gdi demo of minigui**** Copyright (C) 2004 Feynman Software.**** Create date: 2004/07/20*/
#include "english_config.h"#include "meter.h"#include "math.h"extern void GetPinPoint(POINT x1, POINT x2, double alfa, int width, int height, POINT *x3, POINT *x4, POINT *x5);static gal_pixel m_colorTable[4];static PLOGFONT logfont1;	// 显示文字字体///*新增的全局静态变量*/static HDC BackDc_Meter = 0;static HDC BackDc_Sin = 0;#define PT_NUM 45/////////////////////////////////////////////////////////////////////////////////// CMeter message handlers//void DrawMeterBackground(HDC pDC){		int iOnBand = 0;	gal_pixel colorCaption;	int temp1,temp2;	int i;	double dTickAngleRad, dstepTickDeg, dTemp;	POINT m_pointBoundary[22], pointInner[22];	RECT textrect;	    char *text[5] = { "180","135","90","45","0"    };		colorCaption = RGB2Pixel(pDC , 255, 255, 255);    SetBrushColor(pDC, colorCaption);	FillBox(BackDc_Meter, 0, 0, 310, 175);	//绘制圆盘边框	for(iOnBand = 8; iOnBand > 0; iOnBand--)	{			colorCaption = RGB2Pixel(pDC, 			(96 - 255) *((float)iOnBand)/10 +255,			(96 - 255) *((float)iOnBand)/10 +255,			255);		SetPenType(pDC, PT_SOLID);		SetPenCapStyle(pDC, PT_CAP_ROUND);		SetPenColor(pDC, colorCaption);		SetPenWidth(pDC, iOnBand*2);			ArcEx(pDC, 7, 7, 273, 273, 0, 180 * 64);				}	SetPenColor(pDC, PIXEL_black);	// 绘制内圈		SetPenColor(pDC, PIXEL_yellow);	SetPenWidth(pDC, 2);	ArcEx(pDC, 30, 30, 230, 230, 0, 180 * 64);	m_colorTable[0] = RGB2Pixel (pDC, 255, 255, 0);	m_colorTable[1] = RGB2Pixel (pDC, 0, 255,   0);	m_colorTable[2] = RGB2Pixel(pDC, 255,  0,   0);	m_colorTable[3] = RGB2Pixel(pDC, 255,183, 34);	SetPenWidth(pDC, 15);    SetPenCapStyle(pDC, PT_CAP_BUTT);	temp1 = 45 * 64;		for(i = 0; i < TABNUM; i++)	{			SetPenColor(pDC, m_colorTable[i]);		ArcEx(pDC, 22, 22, 244, 244, i * temp1, temp1);	}		dstepTickDeg = 9 * 4.0*atan(1.0)/180.0;	for(i = 0; i <= 20; i++)	{		// 转换成弧度		dTickAngleRad = (double)dstepTickDeg * i;			// 确定外圈坐标		// 确定x坐标		dTemp = 145 + (130) * cos(dTickAngleRad);		m_pointBoundary[i].x = dTemp;		// 确定y坐标		dTemp = 145 - (130) * sin(dTickAngleRad);		m_pointBoundary[i].y = dTemp;				// 确定刻度点(主刻度和子刻度)		//主刻度及文本标注点		if(i % 5 == 0)		{			dTemp = 145 + 120 * cos(dTickAngleRad);			pointInner[i].x = dTemp;			dTemp = 145 - 120 * sin(dTickAngleRad);			pointInner[i].y = dTemp;		}		// 子刻度		else		{			dTemp = 145 + 125*cos(dTickAngleRad);			pointInner[i].x = dTemp;			dTemp = 145 - 125*sin(dTickAngleRad);			pointInner[i].y = dTemp;		}		}		// 绘制刻度    SetPenColor(pDC, PIXEL_black);    SetPenWidth(pDC, 1);		for(i = 0; i <= 20; i++)	{		LineEx(pDC, m_pointBoundary[i].x, m_pointBoundary[i].y,				pointInner[i].x, pointInner[i].y);	}	     	//绘制字体	for(i=0; i<= 4; i++)	{			temp1 = (180 - i * 45);		temp2 = (180 - i * 45) * 4.0 * atan(1.0)/180.0;		if(i == 0)		{			textrect.left = 31;            textrect.top = 136;			textrect.right = textrect.left + 30;            textrect.bottom = textrect.top + 30;			DrawText(pDC, text[i], -1, &textrect, DT_TOP|DT_LEFT);		}				else if(i == 1)		{			textrect.left = 70;            textrect.top = 60;			textrect.right = textrect.left + 30;            textrect.bottom = textrect.top + 30;			DrawText(pDC, text[i], -1, &textrect, DT_TOP|DT_LEFT);		}		else if(i == 2)		{			textrect.left = 142;            textrect.top = 32;			textrect.right = textrect.left + 30;            textrect.bottom = textrect.top + 30;			DrawText(pDC, text[i], -1, &textrect, DT_TOP|DT_LEFT);		}		else if(i == 3)		{			textrect.left = 212;            textrect.top = 62;			textrect.right = textrect.left + 30;            textrect.bottom = textrect.top + 30;			DrawText(pDC, text[i], -1, &textrect, DT_TOP|DT_LEFT);		}				else if(i == 4)		{			textrect.left = 249;            textrect.top = 140;			textrect.right = textrect.left + 30;            textrect.bottom = textrect.top + 30;			DrawText(pDC, text[i], -1, &textrect, DT_TOP|DT_LEFT);		}	}}void DrawNeedle(HDC hdc, int alfa){	double dTemp ;	POINT pt[5] ;	// 指针由四边形组成	int x , y;	dTemp = alfa * 4.0*atan(1.0)/180.0;	x = 155 + 110 * cos(dTemp);	y = 146 - 110 * sin(dTemp);		// 计算角度并限定指针走的角度	pt[0].x = 155;	pt[0].y = 146;	pt[1].x = x;	pt[1].y = y;		GetPinPoint(pt[0], pt[1], alfa, 6, 10, &pt[2], &pt[3], &pt[4]);	SetBrushColor(hdc, PIXEL_lightgray);	FillPolygon(hdc, &pt[1], 4);	//LineEx(hdc, 155,146, x, y);	SetPenColor(hdc, PIXEL_darkgray);	SetPenWidth(hdc, 2);	// 立体感处理	if(alfa > 90)	{				LineEx(hdc, pt[1].x,pt[1].y, pt[2].x, pt[2].y);		LineEx(hdc, pt[2].x,pt[2].y, pt[3].x, pt[3].y);			}	else if(alfa != 90)	{				LineEx(hdc, pt[3].x,pt[3].y, pt[4].x, pt[4].y);		LineEx(hdc, pt[4].x,pt[4].y, pt[1].x, pt[1].y);	}}void DrawNode(HDC hdc){	int i;    gal_pixel colorCaption;	for(i = 4; i > 0; i--)	{		colorCaption = RGB2Pixel(hdc, 			i * 60, i * 60, i * 60);		SetBrushColor(hdc, colorCaption);		FillCircle(hdc, 155, 146, i);	}	}void meter_paint(HDC hdc, int alfa) { 	char str[20];	//绘制仪表盘 	if(BackDc_Meter == 0) 	{ 		//创建背景内存DC	 		BackDc_Meter = CreateCompatibleDCEx(hdc, 310, 175);			DrawMeterBackground(BackDc_Meter);	 	}		 	BitBlt(BackDc_Meter, 0, 0, 310, 175, hdc, 10, 0, 0);
#ifdef MGDEMO_ENGLISH
	sprintf(str, "Current Angle:%d", alfa);
#else		sprintf(str, "当前的角度是:%d", alfa);
#endif    TextOut(hdc, 110, 80, str); 	DrawNeedle(hdc, alfa);	DrawNode(hdc);	}void DrawSinBackground(HDC hdc, int alfa){	int i,j;	char str[5];		SetBrushColor(hdc, PIXEL_black);	FillBox(hdc, 0, 0, 300, 170);		//绘制外框		SetPenColor(hdc, PIXEL_lightwhite);		//绘制坐标	SetPenColor(hdc, PIXEL_red);	//x	LineEx(hdc, 10, 150, 295, 150);	//箭头    LineEx(hdc, 300, 150, 285, 145);    LineEx(hdc, 300, 150, 285, 155);	//y	LineEx(hdc, 10, 10, 10, 150);	//箭头	LineEx(hdc, 10, 10, 5, 25);    LineEx(hdc, 10, 10, 15, 25);	SetBkColor (hdc, PIXEL_black);	SetBkMode (hdc, BM_TRANSPARENT);	SetTextColor (hdc, PIXEL_lightwhite);    TextOut(hdc, 5, 0, "x");	TextOut(hdc, 290, 155, "y");    j = 0;	for(i = 10; i < 295; i+=28)	{		LineEx(hdc, i, 150, i, 155);				if(i < 280)		{			snprintf(str, 5, "%d", j);			TextOut(hdc, i - 2, 155, str);		}				j ++;	}	SetPenColor(hdc, PIXEL_blue);	SetPenDashes(hdc, 0, "\3\2", 2);	SetPenType(hdc, PT_ON_OFF_DASH);	for(i = 0; i < 5; i++)	{		LineEx(hdc, 10, (i * 30) + 10 , 280, (i * 30) + 10);	}}void draw_sin(HDC hdc, int alfa){	int i;	double dTemp, dTemp1;    int rx, ry;	dTemp1 = 4.0*atan(1.0)/180.0;    dTemp = alfa * dTemp1;	//绘制仪表盘	if(BackDc_Sin == 0)	{		//创建背景内存DC			BackDc_Sin = CreateCompatibleDCEx(hdc, 300, 170);		DrawSinBackground(BackDc_Sin, alfa);	}	BitBlt(BackDc_Sin, 0, 0, 300, 170, hdc, 10, 2, 0);	for(i = 10 ; i < 280; i++)	{		rx = i + 10;		ry = 80 + 60 * sin(dTemp);				SetPixel(hdc, rx, ry, PIXEL_green);		dTemp += dTemp1 * 4;	}	}void release_meter(void){	if(BackDc_Meter != 0)	{		DeleteMemDC(BackDc_Meter);		BackDc_Meter = 0;	}}void release_sin(){	if(BackDc_Sin != 0)	{		DeleteMemDC(BackDc_Sin);		BackDc_Sin = 0;	}}

⌨️ 快捷键说明

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