📄 trenddraw.c
字号:
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <minigui/mgext.h>
#include <minigui/mywindows.h>
#include "trend.h"
/***********************************************************************
*** 函数原型:static void DrawDashed(HDC hdc, int x0, int y0, int x1, int y1, int n)
*** 参数说明:(x0, y0)为起点,(x1, y1)为终点,n为虚线的等份数
*** 返回值 :
*** 创建人 :王敏敏
*** 最后修改:
*** 描述 :画一条虚线,从(x0, y0)到(x1, y1)
************************************************************************/
static void DrawDashed(HDC hdc, int x0, int y0, int x1, int y1, int n)
{
int x, y;
signed int DashedXstep=(x1-x0)/n;
signed int DashedYstep=(y1-y0)/n;
int flag=1;
x=x0; y=y0;
MoveTo(hdc, x0, y0);
while( ABS(y-y1)>1 || ABS(x-x1)>1 )
{
if(flag==1)
{MoveTo(hdc, x, y); flag=0;}
else
{LineTo(hdc, x, y); flag=1;}
x=x+DashedXstep;
y=y+DashedYstep;
}
}
/**********************************************************************
**函数名:void DrawRect(HDC hdc,RECT rc,DWORD color)
**功能:画出一个矩形框
**参数:画图的窗口DC,矩形框参数,颜色
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/
void DrawRect(HDC hdc,RECT rc,DWORD color)
{
SetPenColor(hdc,color);
Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
}
/**********************************************************************
**函数名:void DrawLabel(HDC hdc,struct label lb,char driection)
**功能:画出标签,driection为文字方向
**参数:画图的窗口DC,标签类型lb,文字方向driection:'V':垂直;'H':水平;'R':右对齐
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/
void DrawLabel(HDC hdc,struct label lb,char driection)
{
RECT rc;
rc.left=lb.Xorg;
rc.top=lb.Yorg;
rc.right=lb.Xorg+lb.Width;
rc.bottom=lb.Yorg+lb.Height;
SetPenColor(hdc,lb.framcolor);//设置画笔颜色,绘制label边框
Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
SetBkColor(hdc,lb.bkclor); //设置背景色
SetTextColor(hdc,lb.fontcolor); //设置字体颜色
//用背景色覆盖标签中的文字
SetBrushColor(hdc, lb.bkclor);
FillBox (hdc, rc.left+1, rc.top+1, rc.right-rc.left-1, rc.bottom-rc.top-2); // 加1减1目的是为了防止把边框刷掉
switch(driection)
{
case 'H':
DrawText(hdc, lb.text, -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
break;
case 'V':
rc.top+=6;
rc.left+=1;
rc.right-=1;
DrawText(hdc, lb.text, -1, &rc, DT_CENTER | DT_WORDBREAK);
break;
case 'R':
DrawText(hdc, lb.text, -1, &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
break;
default: break;
}
}
/**********************************************************************
**函数名:void DrawShortLine(HDC hdc,struct shortline sl[],int size)
**功能:画出短线
**参数:画图的窗口DC,短线数组sl[],短线数量size
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/
void DrawShortLine(HDC hdc,struct shortline sl[],int size)
{
int i;
for(i=0;i<size;i++)
{
SetPenColor(hdc,sl[i].slcolor);
MoveTo(hdc, sl[i].start.x, sl[i].start.y);
LineTo(hdc, sl[i].end.x, sl[i].end.y);
DrawDashed(hdc, sl[i].Hstart.x, sl[i].Hstart.y, sl[i].Hend.x, sl[i].Hend.y, 60);
}
}
/**********************************************************************
**函数名:void SetCEditText(HWND hWnd, char *s, DWORD color);
**功能:设置彩色文本框的文本和文本颜色
**参数:彩色文本框控件句柄hWnd,字符串 s, 字符串颜色 color
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/
void SetCEditText(HWND hWnd, char *s, DWORD color)
{
SetWindowCaption(hWnd, s);
SendMessage(hWnd, MSG_USER, color, 0); //设置字体颜色
}
/**********************************************************************
**函数名:void TrendAddXY(HDC hdc, RECT rc, int x, int y, DWORD color)
**功能:在曲线方框中添加一个数据点,显示为棒状图
**参数:绘图hdc,曲线方框rc,要添加点的坐标(x,y),添加点的颜色color
**返回值:无
**作者:陈永奎
**时间:2008.03.31
***********************************************************************/
void TrendAddXY(HDC hdc, RECT rc, int x, int y, DWORD color)
{
if(y>RECTH(rc))
y=RECTH(rc);
SetPenColor(hdc,COLOR_black);
MoveTo(hdc, rc.left+x, rc.top);
LineTo(hdc, rc.left+x, rc.bottom);
SetPenColor(hdc,color);
MoveTo(hdc, rc.left+x, rc.bottom-y);
LineTo(hdc, rc.left+x, rc.bottom);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -