以后可能会用到,到时就不用翻乱七八糟的文档了。
头文件关系
// graphics.h
#include
// easyx.h
#include
#include
函数整理
1.鼠标事件相关:
bool MouseHit(); // 检查是否存在鼠标消息
void FlushMouseMsgBuffer(); // 清空鼠标消息缓冲区
MOUSEMSG GetMouseMsg(); // 获取一个鼠标消息。如果没有,就等待
struct MOUSEMSG
{
UINT uMsg; // 当前鼠标消息
bool mkCtrl; // Ctrl 键是否按下
bool mkShift; // Shift 键是否按下
bool mkLButton; // 鼠标左键是否按下
bool mkMButton; // 鼠标中键是否按下
bool mkRButton; // 鼠标右键是否按下
short x; // 当前鼠标 x 坐标
short y; // 当前鼠标 y 坐标
short wheel; // 鼠标滚轮滚动值 (120 的倍数)
};
/*
鼠标消息:
WM_MOUSEMOVE //鼠标移动
WM_MOUSEWHEEL //鼠标滚轮拨动
WM_LBUTTONDOWN //左键按下
WM_LBUTTONUP //左键弹起
WM_LBUTTONDBLCLK //左键双击
WM_MBUTTONDOWN //中键按下
WM_MBUTTONUP //中键弹起
WM_MBUTTONDBLCLK //中键双击
WM_RBUTTONDOWN //右键按下
WM_RBUTTONUP //右键弹起
WM_RBUTTONDBLCLK //右键双击
*/
2.图像处理相关函数
IMAGE* GetWorkingImage(); // 获取当前绘图设备
DWORD* GetImageBuffer(IMAGE* pImg = NULL); // 获取绘图设备的显存指针
HDC GetImageHDC(IMAGE* pImg = NULL); // 获取绘图设备句柄(HDC)
void SetWorkingImage(IMAGE* pImg = NULL); // 设置当前绘图设备
void Resize( // 调整绘图设备的大小
IMAGE* pImg, // 要调整尺寸的绘图设备
int width, // 绘图设备的宽度
int height // 绘图设备的高度
);
void saveimage( // 保存图像
LPCTSTR pImgFile, // 图像文件名
IMAGE* pImg = NULL // 指向IMAGE对象的指针
);
void loadimage( // 从图片文件获取图像(bmp/jpg/gif/emf/wmf)
IMAGE* pDstImg, // 保存图像的 IMAGE 对象指针
LPCTSTR pImgFile, // 图片文件名
int nWidth = 0, // 图片的拉伸宽度
int nHeight = 0, // 图片的拉伸高度
bool bResize = false // 是否调整 IMAGE 的大小以适应图片
);
void loadimage( // 从资源文件获取图像(bmp/jpg/gif/emf/wmf)
IMAGE* pDstImg, // 保存图像的 IMAGE 对象指针
LPCTSTR pResType, // 资源类型
LPCTSTR pResName, // 资源名称
int nWidth = 0, // 图片的拉伸宽度
int nHeight = 0, // 图片的拉伸高度
bool bResize = false // 是否调整 IMAGE 的大小以适应图片
);
void getimage( // 从当前绘图设备获取图像
IMAGE* pDstImg, // 保存图像的 IMAGE 对象指针
int srcX, // 要获取图像区域左上角 x 坐标
int srcY, // 要获取图像区域的左上角 y 坐标
int srcWidth, // 要获取图像区域的宽度
int srcHeight // 要获取图像区域的高度
);
void putimage( // 绘制图像到屏幕
int dstX, // 绘制位置的 x 坐标
int dstY, // 绘制位置的 y 坐标
IMAGE *pSrcImg, // 要绘制的 IMAGE 对象指针
DWORD dwRop = SRCCOPY // 三元光栅操作码
);
void putimage( // 绘制图像到屏幕(指定宽高)
int dstX, // 绘制位置的 x 坐标
int dstY, // 绘制位置的 y 坐标
int dstWidth, // 绘制的宽度
int dstHeight, // 绘制的高度
IMAGE *pSrcImg, // 要绘制的 IMAGE 对象指针
int srcX, // 绘制内容在 IMAGE 对象中的左上角 x 坐标
int srcY, // 绘制内容在 IMAGE 对象中的左上角 y 坐标
DWORD dwRop = SRCCOPY // 三元光栅操作码
);
void rotateimage( // 旋转图像
IMAGE *dstimg, // 目标IMAGE对象指针
IMAGE *srcimg, // 源IMAGE对象指针
double radian, // 旋转的弧度
COLORREF bkcolor = BLACK, // 指定旋转后产生的空白区域的颜色
bool autosize = false, // 指定目标IMAGE对象是否自动调整尺寸以完全容纳旋转后的图像
bool highquality = true // 是否采用高质量旋转
);
/* 常用三元光栅操作码
setfillcolor当前填充的颜色用setfillcolor(COLORREF color)设置
DSTINVERT 绘制出的像素颜色 = NOT 屏幕颜色
MERGECOPY 绘制出的像素颜色 = 图像颜色 AND 当前填充颜色
MERGEPAINT 绘制出的像素颜色 = 屏幕颜色 OR (NOT 图像颜色)
NOTSRCCOPY 绘制出的像素颜色 = NOT 图像颜色
NOTSRCERASE 绘制出的像素颜色 = NOT (屏幕颜色 OR 图像颜色)
PATCOPY 绘制出的像素颜色 = 当前填充颜色
PATINVERT 绘制出的像素颜色 = 屏幕颜色 XOR 当前填充颜色
PATPAINT 绘制出的像素颜色 = 屏幕颜色 OR ((NOT 图像颜色) OR 当前填充颜色)
SRCAND 绘制出的像素颜色 = 屏幕颜色 AND 图像颜色
SRCCOPY 绘制出的像素颜色 = 图像颜色
SRCERASE 绘制出的像素颜色 = (NOT 屏幕颜色) AND 图像颜色
SRCINVERT 绘制出的像素颜色 = 屏幕颜色 XOR 图像颜色
SRCPAINT 绘制出的像素颜色 = 屏幕颜色 OR 图像颜色
*/
int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // 在指定区域内以指定格式输出字符串
int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // 在指定区域内以指定格式输出字符
int textwidth(LPCTSTR str); // 获取字符串占用的像素宽
int textwidth(TCHAR c); // 获取字符占用的像素宽
int textheight(LPCTSTR str); // 获取字符串占用的像素高
int textheight(TCHAR c); // 获取字符占用的像素高
void outtext(LPCTSTR str); // 在当前位置输出字符串
void outtext(TCHAR c); // 在当前位置输出字符
void outtextxy(int x, int y, LPCTSTR str); // 在指定位置输出字符串
void outtextxy(int x, int y, TCHAR c); // 在指定位置输出字符
void gettextstyle(LOGFONT *font); // 获取当前字体样式
// 设置当前字体样式函数组
void settextstyle(const LOGFONT *font);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace);
void settextstyle(
int nHeight, // 字符的平均高度
int nWidth, // 字符的平均宽度(0 表示自适应)
LPCTSTR lpszFace, // 字体名称
int nEscapement, // 字符串的书写角度(单位 0.1 度)
int nOrientation, // 每个字符的书写角度(单位 0.1 度)
int nWeight, // 字符的笔画粗细(0 表示默认粗细)
bool bItalic, // 设置斜体
bool bUnderline, // 设置下划线
bool bStrikeOut // 设置删除线
);
void settextstyle(
int nHeight, // 字符的平均高度
int nWidth, // 字符的平均宽度(0 表示自适应)
LPCTSTR lpszFace, // 字体名称
int nEscapement, // 字符串的书写角度(单位 0.1 度)
int nOrientation, // 每个字符的书写角度(单位 0.1 度)
int nWeight, // 字符的笔画粗细(0 表示默认粗细)
bool bItalic, // 设置斜体
bool bUnderline, // 设置下划线
bool bStrikeOut // 设置删除线
BYTE fbCharSet, // 设置字符集
BYTE fbOutPrecision, // 指定文字的输出精度
BYTE fbClipPrecision, // 指定文字的剪辑精度
BYTE fbQuality, // 指定文字的输出质量
BYTE fbPitchAndFamily // 指定以常规方式描述字体的字体系列
);
4.其他函数
TCHAR* GetEasyXVer(); // 获取 EasyX 当前版本
HWND GetHWnd(); // 获取绘图窗口句柄(HWND)
int getwidth(); // 获取绘图区宽度
int getheight(); // 获取绘图区高度
int getx(); // 获取当前 x 坐标
int gety(); // 获取当前 y 坐标
void BeginBatchDraw(); // 开始批量绘制
void FlushBatchDraw(); // 执行未完成的绘制任务
void EndBatchDraw(); // 结束批量绘制,并执行未完成的绘制任务
void FlushBatchDraw( // 执行指定区域内未完成的绘制任务
int left,
int top,
int right,
int bottom
);
void EndBatchDraw( // 结束批量绘制,并执行指定区域内未完成的绘制任务
int left,
int top,
int right,
int bottom
);
bool InputBox( // 获取用户输入
LPTSTR pString,
int nMaxCount,
LPCTSTR pPrompt = NULL,
LPCTSTR pTitle = NULL,
LPCTSTR pDefault = NULL,
int width = 0,
int height = 0,
bool bOnlyOK = true
);
5.绘图函数
HWND initgraph(int width, int height, int flag = NULL); // 初始化图形环境(常用)
HWND initgraph(int* gdriver, int* gmode, char* path); // BGI 格式的初始化图形设备,默认 640 x 480
void closegraph(); // 关闭图形环境
void cleardevice(); // 清屏
void setcliprgn(HRGN hrgn); // 设置当前绘图设备的裁剪区
void clearcliprgn(); // 清除裁剪区的屏幕内容
void getlinestyle(LINESTYLE* pstyle); // 获取当前画线样式
void getfillstyle(FILLSTYLE* pstyle); // 获取当前填充样式
void getaspectratio(float *pxasp, float *pyasp); // 获取当前缩放因子
COLORREF getcolor(); // 获取当前绘图前景色
void setcolor(COLORREF color); // 设置当前绘图前景色
void setwritemode(int mode); // 设置前景的二元光栅操作模式
int getmaxx(); // 获取最大的宽度值
int getmaxy(); // 获取最大的高度值
void setlinestyle(const LINESTYLE* pstyle); // 设置当前画线样式
void setlinestyle( // 设置当前画线样式
int style,
int thickness = 1,
const DWORD *puserstyle = NULL,
DWORD userstylecount = 0
);
void setfillstyle(const FILLSTYLE* pstyle); // 设置当前填充样式
void setfillstyle(BYTE* ppattern8x8); // 设置当前填充样式
void setfillstyle( // 设置当前填充样式
int style,
long hatch = NULL,
IMAGE* ppattern = NULL
);
void setorigin(int x, int y); // 设置坐标原点
void setaspectratio(float xasp, float yasp); // 设置当前缩放因子
int getrop2(); // 获取前景的二元光栅操作模式
void setrop2(int mode); // 设置前景的二元光栅操作模式
int getpolyfillmode(); // 获取多边形填充模式
void setpolyfillmode(int mode); // 设置多边形填充模式
void graphdefaults(); // 重置所有绘图设置为默认值
COLORREF getlinecolor(); // 获取当前线条颜色
void setlinecolor(COLORREF color); // 设置当前线条颜色
COLORREF gettextcolor(); // 获取当前文字颜色
void settextcolor(COLORREF color); // 设置当前文字颜色
COLORREF getfillcolor(); // 获取当前填充颜色
void setfillcolor(COLORREF color); // 设置当前填充颜色
COLORREF getbkcolor(); // 获取当前绘图背景色
void setbkcolor(COLORREF color); // 设置当前绘图背景色
int getbkmode(); // 获取背景混合模式
void setbkmode(int mode); // 设置背景混合模式
// 颜色模型转换函数
COLORREF RGBtoGRAY(COLORREF rgb);
void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L);
void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V);
COLORREF HSLtoRGB(float H, float S, float L);
COLORREF HSVtoRGB(float H, float S, float V);
// 绘图函数
COLORREF getpixel(int x, int y); // 获取点的颜色
void putpixel(int x, int y, COLORREF color); // 画点
// 颜色转换宏
#define BGR(color) ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) )
void moveto(int x, int y); // 移动当前点(绝对坐标)
void moverel(int dx, int dy); // 移动当前点(相对坐标)
void line(int x1, int y1, int x2, int y2); // 画线
void linerel(int dx, int dy); // 画线(至相对坐标)
void lineto(int x, int y); // 画线(至绝对坐标)
void rectangle (int left, int top, int right, int bottom); // 画矩形
void fillrectangle (int left, int top, int right, int bottom); // 画填充矩形(有边框)
void solidrectangle(int left, int top, int right, int bottom); // 画填充矩形(无边框)
void clearrectangle(int left, int top, int right, int bottom); // 清空矩形区域
void circle (int x, int y, int radius); // 画圆
void fillcircle (int x, int y, int radius); // 画填充圆(有边框)
void solidcircle(int x, int y, int radius); // 画填充圆(无边框)
void clearcircle(int x, int y, int radius); // 清空圆形区域
void ellipse (int left, int top, int right, int bottom); // 画椭圆
void fillellipse (int left, int top, int right, int bottom); // 画填充椭圆(有边框)
void solidellipse(int left, int top, int right, int bottom); // 画填充椭圆(无边框)
void clearellipse(int left, int top, int right, int bottom); // 清空椭圆形区域
void roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 画圆角矩形
void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 画填充圆角矩形(有边框)
void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 画填充圆角矩形(无边框)
void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 清空圆角矩形区域
void arc (int left, int top, int right, int bottom, double stangle, double endangle); // 画椭圆弧(起始角度和终止角度为弧度制)
void pie (int left, int top, int right, int bottom, double stangle, double endangle); // 画椭圆扇形(起始角度和终止角度为弧度制)
void fillpie (int left, int top, int right, int bottom, double stangle, double endangle); // 画填充椭圆扇形(有边框)
void solidpie(int left, int top, int right, int bottom, double stangle, double endangle); // 画填充椭圆扇形(无边框)
void clearpie(int left, int top, int right, int bottom, double stangle, double endangle); // 清空椭圆扇形区域
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 画有边框三维填充矩形
void bar(int left, int top, int right, int bottom); // 画无边框填充矩形
void drawpoly(int numpoints, const int *polypoints); // 画多边形
void fillpoly(int numpoints, const int *polypoints); // 画填充的多边形
void polyline (const POINT *points, int num); // 画多条连续的线
void polygon (const POINT *points, int num); // 画多边形
void fillpolygon (const POINT *points, int num); // 画填充的多边形(有边框)
void solidpolygon(const POINT *points, int num); // 画填充的多边形(无边框)
void clearpolygon(const POINT *points, int num); // 清空多边形区域
void floodfill(int x, int y, int border); // 填充区域
class LINESTYLE
{
public:
LINESTYLE();
LINESTYLE(const LINESTYLE &style);
LINESTYLE& operator = (const LINESTYLE &style); // 赋值运算符重载函数
virtual ~LINESTYLE();
DWORD style;
DWORD thickness;
DWORD *puserstyle;
DWORD userstylecount;
};
class FILLSTYLE
{
public:
FILLSTYLE();
FILLSTYLE(const FILLSTYLE &style);
FILLSTYLE& operator = (const FILLSTYLE &style); // 赋值运算符重载函数
virtual ~FILLSTYLE();
int style; // 填充形式
long hatch; // 填充图案样式
IMAGE* ppattern; // 填充图像
};
6.参数定义
// 绘图窗口初始化参数
#define SHOWCONSOLE 1 // 创建图形窗口时,保留控制台的显示
#define NOCLOSE 2 // 没有关闭功能
#define NOMINIMIZE 4 // 没有最小化功能
// 颜色
#define BLACK 0
#define BLUE 0xAA0000
#define GREEN 0x00AA00
#define CYAN 0xAAAA00
#define RED 0x0000AA
#define MAGENTA 0xAA00AA
#define BROWN 0x0055AA
#define LIGHTGRAY 0xAAAAAA
#define DARKGRAY 0x555555
#define LIGHTBLUE 0xFF5555
#define LIGHTGREEN 0x55FF55
#define LIGHTCYAN 0xFFFF55
#define LIGHTRED 0x5555FF
#define LIGHTMAGENTA 0xFF55FF
#define YELLOW 0x55FFFF
#define WHITE 0xFFFFFF