/****************************************************** * EasyX Library for C++ (Ver:20220901) * https://easyx.cn * * EasyX.h * Provides the latest API. ******************************************************/
以下截取自easyx.h第37行到第366行
// EasyX Window PropertiesEasyX 窗口属性
#define EX_SHOWCONSOLE 1 // Maintain the console window when creating a graphics window创建图形窗口时维护控制台窗口
#define EX_NOCLOSE 2 // Disable the close button禁用关闭按钮
#define EX_NOMINIMIZE 4 // Disable the minimize button禁用最小化按钮
#define EX_DBLCLKS 8 // Support double-click events支持双击事件
// Color constant颜色常数
#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
// Color conversion macro颜色转换宏
#define BGR(color) ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) )
class IMAGE;
// Line style class线条类
class LINESTYLE
{
public:
LINESTYLE();
LINESTYLE(const LINESTYLE &style);
LINESTYLE& operator = (const LINESTYLE &style);
virtual ~LINESTYLE();
DWORD style;
DWORD thickness;
DWORD *puserstyle;
DWORD userstylecount;
};
// Fill style class填充样式类
class FILLSTYLE
{
public:
FILLSTYLE();
FILLSTYLE(const FILLSTYLE &style);
FILLSTYLE& operator = (const FILLSTYLE &style);
virtual ~FILLSTYLE();
int style; // Fill style填充样式
long hatch; // Hatch pattern填充图案
IMAGE* ppattern; // Fill image填充图像
};
// Image class图像类
class IMAGE
{
public:
int getwidth() const; // Get the width of the image
int getheight() const; // Get the height of the image
private:
int width, height; // Width and height of the image
HBITMAP m_hBmp;
HDC m_hMemDC;
float m_data[6];
COLORREF m_LineColor; // Current line color
COLORREF m_FillColor; // Current fill color
COLORREF m_TextColor; // Current text color
COLORREF m_BkColor; // Current background color
DWORD* m_pBuffer; // Memory buffer of the image图像的内存缓冲区
LINESTYLE m_LineStyle; // Current line style
FILLSTYLE m_FillStyle; // Current fill style
virtual void SetDefault(); // Set the graphics environment as default将图形环境设置为默认
public:
IMAGE(int _width = 0, int _height = 0);
IMAGE(const IMAGE &img);
IMAGE& operator = (const IMAGE &img);
virtual ~IMAGE();
virtual void Resize(int _width, int _height); // Resize image调整图像大小
};
// Graphics window related functions图形窗口相关函数
HWND initgraph(int width, int height, int flag = 0); // Create graphics window
void closegraph(); // Close graphics window
// Graphics environment related functions图形环境相关函数
void cleardevice(); // Clear device清除设备
void setcliprgn(HRGN hrgn); // Set clip region设置剪辑区域
void clearcliprgn(); // Clear clip region
void getlinestyle(LINESTYLE* pstyle); // Get line style
void setlinestyle(const LINESTYLE* pstyle); // Set line style
void setlinestyle(int style, int thickness = 1, const DWORD *puserstyle = NULL, DWORD userstylecount = 0); // Set line style
void getfillstyle(FILLSTYLE* pstyle); // Get fill style获取填充样式
void setfillstyle(const FILLSTYLE* pstyle); // Set fill style
void setfillstyle(int style, long hatch = NULL, IMAGE* ppattern = NULL); // Set fill style
void setfillstyle(BYTE* ppattern8x8); // Set fill style
void setorigin(int x, int y); // Set coordinate origin设置坐标原点
void getaspectratio(float *pxasp, float *pyasp); // Get aspect ratio获取纵横比
void setaspectratio(float xasp, float yasp); // Set aspect ratio设置纵横比
int getrop2(); // Get binary raster operation mode获取二进制光栅操作模式
void setrop2(int mode); // Set binary raster operation mode
int getpolyfillmode(); // Get polygon fill mode获取多边形填充模式
void setpolyfillmode(int mode); // Set polygon fill mode
void graphdefaults(); // Reset the graphics environment as default将图形环境重置为默认值
COLORREF getlinecolor(); // Get line color
void setlinecolor(COLORREF color); // Set line color
COLORREF gettextcolor(); // Get text color
void settextcolor(COLORREF color); // Set text color
COLORREF getfillcolor(); // Get fill color
void setfillcolor(COLORREF color); // Set fill color
COLORREF getbkcolor(); // Get background color
void setbkcolor(COLORREF color); // Set background color
int getbkmode(); // Get background mode
void setbkmode(int mode); // Set background mode
// Color model transformation related functions颜色模型转换相关函数
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);
// Drawing related functions绘图相关函数
COLORREF getpixel(int x, int y); // Get pixel color获取像素颜色
void putpixel(int x, int y, COLORREF color); // Set pixel color
void line(int x1, int y1, int x2, int y2); // Draw a line画一条线
void rectangle (int left, int top, int right, int bottom); // Draw a rectangle without filling画一个没有填充的矩形
void fillrectangle (int left, int top, int right, int bottom); // Draw a filled rectangle with a border绘制一个带边框的填充矩形
void solidrectangle(int left, int top, int right, int bottom); // Draw a filled rectangle without a border
void clearrectangle(int left, int top, int right, int bottom); // Clear a rectangular region清除一个矩形区域
void circle (int x, int y, int radius); // Draw a circle without filling画一个没有填充的圆
void fillcircle (int x, int y, int radius); // Draw a filled circle with a border
void solidcircle(int x, int y, int radius); // Draw a filled circle without a border
void clearcircle(int x, int y, int radius); // Clear a circular region
void ellipse (int left, int top, int right, int bottom); // Draw an ellipse without filling
void fillellipse (int left, int top, int right, int bottom); // Draw a filled ellipse with a border绘制带边框的实心椭圆
void solidellipse(int left, int top, int right, int bottom); // Draw a filled ellipse without a border
void clearellipse(int left, int top, int right, int bottom); // Clear an elliptical region
void roundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a rounded rectangle without filling画一个没有填充的圆角矩形
void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a filled rounded rectangle with a border
void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Draw a filled rounded rectangle without a border绘制一个没有边框的填充圆角矩形
void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // Clear a rounded rectangular region
void arc (int left, int top, int right, int bottom, double stangle, double endangle); // Draw an arc画弧线
void pie (int left, int top, int right, int bottom, double stangle, double endangle); // Draw a sector without filling画一个没有填充的扇区
void fillpie (int left, int top, int right, int bottom, double stangle, double endangle); // Draw a filled sector with a border绘制一个带边框的填充扇区
void solidpie(int left, int top, int right, int bottom, double stangle, double endangle); // Draw a filled sector without a border
void clearpie(int left, int top, int right, int bottom, double stangle, double endangle); // Clear a rounded rectangular region
void polyline (const POINT *points, int num); // Draw multiple consecutive lines绘制多条连续的线
void polygon (const POINT *points, int num); // Draw a polygon without filling绘制一个没有填充的多边形
void fillpolygon (const POINT *points, int num); // Draw a filled polygon with a border
void solidpolygon(const POINT *points, int num); // Draw a filled polygon without a border
void clearpolygon(const POINT *points, int num); // Clear a polygon region清除多边形区域
void polybezier(const POINT *points, int num); // Draw three square Bezier curves
void floodfill(int x, int y, COLORREF color, int filltype = FLOODFILLBORDER); // Fill the area填充区域
// Text related functions文字相关函数
void outtextxy(int x, int y, LPCTSTR str); // Output a string at the specified location在指定位置输出字符串
void outtextxy(int x, int y, TCHAR c); // Output a char at the specified location在指定位置输出一个字符
int textwidth(LPCTSTR str); // Get the width of a string获取字符串的宽度
int textwidth(TCHAR c); // Get the width of a char
int textheight(LPCTSTR str); // Get the height of a string
int textheight(TCHAR c); // Get the height of a char
int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // Output a string in the specified format within the specified area.在指定区域内输出指定格式的字符串。
int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // Output a char in the specified format within the specified area.
// Set current text style.设置当前文本样式。
// nHeight: The height of the text
// nWidth: The average width of the character. If 0, the scale is adaptive.字符的平均宽度。 如果为 0,则比例是自适应的。
// lpszFace: The font name字体名称
// nEscapement: The writing angle of the string, 0.1 degrees, defaults to 0.字符串的书写角度,0.1度,默认为0。
// nOrientation: The writing angle of each character, 0.1 degrees, defaults to 0.每个字符的书写角度,0.1度,默认为0。
// nWeight: The stroke weight of the character字符的笔划粗细
// bItalic: Specify whether the font is italic指定字体是否为斜体
// bUnderline: Specify whether the font is underlined指定字体是否带下划线
// bStrikeOut: Specify whether the font has a strikeout指定字体是否有删除线
// fbCharSet: Specifies the character set指定字符集
// fbOutPrecision: Specifies the output accuracy of the text指定文本的输出精度
// fbClipPrecision: Specifies the clip accuracy of the text指定文本的剪辑精度
// fbQuality: Specifies the output quality of the text指定文本的输出质量
// fbPitchAndFamily: Specifies a font family that describes a font in a general way指定以一般方式描述字体的字体系列
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily);
void settextstyle(const LOGFONT *font); // Set current text style
void gettextstyle(LOGFONT *font); // Get current text style
// Image related functions图片相关函数
void loadimage(IMAGE *pDstImg, LPCTSTR pImgFile, int nWidth = 0, int nHeight = 0, bool bResize = false); // Load image from a file (bmp/gif/jpg/png/tif/emf/wmf/ico)从文件加载图像
void loadimage(IMAGE *pDstImg, LPCTSTR pResType, LPCTSTR pResName, int nWidth = 0, int nHeight = 0, bool bResize = false); // Load image from resources (bmp/gif/jpg/png/tif/emf/wmf/ico)从资源加载图像
void saveimage(LPCTSTR pImgFile, IMAGE* pImg = NULL); // Save image to a file (bmp/gif/jpg/png/tif)
void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth, int srcHeight); // Get image from device从设备获取图像
void putimage(int dstX, int dstY, const IMAGE *pSrcImg, DWORD dwRop = SRCCOPY); // Put image to device将图像放入设备
void putimage(int dstX, int dstY, int dstWidth, int dstHeight, const IMAGE *pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY); // Put image to device
void rotateimage(IMAGE *dstimg, IMAGE *srcimg, double radian, COLORREF bkcolor = BLACK, bool autosize = false, bool highquality = true);// Rotate image旋转图像
void Resize(IMAGE* pImg, int width, int height); // Resize the device调整设备大小
DWORD* GetImageBuffer(IMAGE* pImg = NULL); // Get the display buffer of the graphics device获取图形设备的显示缓冲区
IMAGE* GetWorkingImage(); // Get current graphics device
void SetWorkingImage(IMAGE* pImg = NULL); // Set current graphics device
HDC GetImageHDC(IMAGE* pImg = NULL); // Get the graphics device handle获取图形设备句柄
// Other functions其他函数
int getwidth(); // Get the width of current graphics device获取当前图形设备的宽度
int getheight(); // Get the height of current graphics device
void BeginBatchDraw(); // Begin batch drawing mode开始批量绘制模式
void FlushBatchDraw(); // Refreshes the undisplayed drawing刷新未显示的绘图
void FlushBatchDraw(int left, int top, int right, int bottom); // Refreshes the undisplayed drawing
void EndBatchDraw(); // End batch drawing mode and refreshes the undisplayed drawing结束批量绘图模式并刷新未显示的绘图
void EndBatchDraw(int left, int top, int right, int bottom); // End batch drawing mode and refreshes the undisplayed drawing
HWND GetHWnd(); // Get the handle of the graphics window获取图形窗口的句柄
const TCHAR* GetEasyXVer(); // Get version of EasyX library获取 EasyX 库的版本
// Get user input as a dialog box将用户输入作为对话框获取
bool InputBox(LPTSTR pString, int nMaxCount, LPCTSTR pPrompt = NULL, LPCTSTR pTitle = NULL, LPCTSTR pDefault = NULL, int width = 0, int height = 0, bool bOnlyOK = true);
// Message
//
// Category Type Description类别类型说明
//
// EX_MOUSE WM_MOUSEMOVE Mouse moves鼠标移动
// WM_MOUSEWHEEL Mouse wheel is rotated鼠标滚轮旋转
// WM_LBUTTONDOWN Left mouse button is pressed
// WM_LBUTTONUP Left mouse button is released鼠标左键被释放
// WM_LBUTTONDBLCLK Left mouse button is double-clicked双击鼠标左键
// WM_MBUTTONDOWN Middle mouse button is pressed
// WM_MBUTTONUP Middle mouse button is released
// WM_MBUTTONDBLCLK Middle mouse button is double-clicked
// WM_RBUTTONDOWN Right mouse button is pressed
// WM_RBUTTONUP Right mouse button is released
// WM_RBUTTONDBLCLK Right mouse button is double-clicked
//
// EX_KEY WM_KEYDOWN A key is pressed按下一个键
// WM_KEYUP A key is released
//
// EX_CHAR WM_CHAR
//
// EX_WINDOW WM_ACTIVATE The window is activated or deactivated窗口被激活或停用
// WM_MOVE The window has been moved窗口已移动
// WM_SIZE The size of window has changed窗口的大小发生了变化
// Message Category
#define EX_MOUSE 1
#define EX_KEY 2
#define EX_CHAR 4
#define EX_WINDOW 8
// Message Structure消息结构
struct ExMessage
{
USHORT message; // The message identifier消息标识符
union
{
// Data of the mouse message鼠标消息的数据
struct
{
bool ctrl :1; // Indicates whether the CTRL key is pressed指示是否按下了 CTRL 键
bool shift :1; // Indicates whether the SHIFT key is pressed
bool lbutton :1; // Indicates whether the left mouse button is pressed
bool mbutton :1; // Indicates whether the middle mouse button is pressed
bool rbutton :1; // Indicates whether the right mouse button is pressed指示是否按下鼠标右键
short x; // The x-coordinate of the cursor
short y; // The y-coordinate of the cursor光标的y坐标
short wheel; // The distance the wheel is rotated, expressed in multiples or divisions of 120车轮转动的距离,以120的倍数或除数表示
};
// Data of the key message
struct
{
BYTE vkcode; // The virtual-key code of the key按键的虚拟键码
BYTE scancode; // The scan code of the key. The value depends on the OEM按键的扫描码。 该值取决于 OEM
bool extended :1; // Indicates whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is true if the key is an extended key; otherwise, it is false.表示该键是否为扩展键,如功能键或数字键盘上的键。 如果密钥是扩展密钥,则值为真; 否则,它是错误的。
bool prevdown :1; // Indicates whether the key is previously up or down指示键之前是向上还是向下
};
// Data of the char message字符消息的数据
TCHAR ch;
// Data of the window message窗口消息的数据
struct
{
WPARAM wParam;
LPARAM lParam;
};
};
};
// Message Function
ExMessage getmessage(BYTE filter = -1); // Get a message until a message is available for retrieval获取消息,直到消息可用于检索
void getmessage(ExMessage *msg, BYTE filter = -1); // Get a message until a message is available for retrieval
bool peekmessage(ExMessage *msg, BYTE filter = -1, bool removemsg = true); // Get a message if any exist, otherwise return false如果存在则获取消息,否则返回false
void flushmessage(BYTE filter = -1); // Flush the message buffer刷新消息缓冲区