ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

EasyX 简易绘图工具接口整理

2020-06-26 20:55:34  阅读:268  来源: 互联网

标签:COLORREF const int void EasyX 接口 绘图 IMAGE define


 

 

 EasyX Library for C++ (Ver:20190415(beta))
 http://www.easyx.cn
 EasyX.h

  1 #pragma once
  2 
  3 #ifndef WINVER
  4 #define WINVER 0x0400            // Specifies that the minimum required platform is Windows 95 and Windows NT 4.0.
  5 #endif
  6 
  7 #ifndef _WIN32_WINNT
  8 #define _WIN32_WINNT 0x0500        // Specifies that the minimum required platform is Windows 2000.
  9 #endif
 10 
 11 #ifndef _WIN32_WINDOWS
 12 #define _WIN32_WINDOWS 0x0410    // Specifies that the minimum required platform is Windows 98.
 13 #endif
 14 
 15 #if defined(UNICODE)
 16     #pragma comment(lib,"EasyXw.lib")
 17 #else
 18     #pragma comment(lib,"EasyXa.lib")
 19 #endif
 20 
 21 
 22 #ifndef __cplusplus
 23 #error EasyX is only for C++
 24 #endif
 25 
 26 #include <windows.h>
 27 #include <tchar.h>
 28 
 29 // 绘图窗口初始化参数
 30 #define SHOWCONSOLE        1        // 创建图形窗口时,保留控制台的显示
 31 #define NOCLOSE            2        // 没有关闭功能
 32 #define NOMINIMIZE        4        // 没有最小化功能
 33 
 34 // 颜色
 35 #define    BLACK            0
 36 #define    BLUE            0xAA0000
 37 #define    GREEN            0x00AA00
 38 #define    CYAN            0xAAAA00
 39 #define    RED                0x0000AA
 40 #define    MAGENTA            0xAA00AA
 41 #define    BROWN            0x0055AA
 42 #define    LIGHTGRAY        0xAAAAAA
 43 #define    DARKGRAY        0x555555
 44 #define    LIGHTBLUE        0xFF5555
 45 #define    LIGHTGREEN        0x55FF55
 46 #define    LIGHTCYAN        0xFFFF55
 47 #define    LIGHTRED        0x5555FF
 48 #define    LIGHTMAGENTA    0xFF55FF
 49 #define    YELLOW            0x55FFFF
 50 #define    WHITE            0xFFFFFF
 51 
 52 // 定义颜色转换宏
 53 #define BGR(color)    ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) )
 54 
 55 
 56 class IMAGE;
 57 
 58 // 定义线的样式
 59 class LINESTYLE
 60 {
 61 public:
 62     LINESTYLE();
 63     LINESTYLE(const LINESTYLE &style);
 64     LINESTYLE& operator = (const LINESTYLE &style);            // 赋值运算符重载函数
 65     virtual ~LINESTYLE();
 66 
 67     DWORD    style;
 68     DWORD    thickness;
 69     DWORD    *puserstyle;
 70     DWORD    userstylecount;
 71 };
 72 
 73 class FILLSTYLE
 74 {
 75 public:
 76     FILLSTYLE();
 77     FILLSTYLE(const FILLSTYLE &style);
 78     FILLSTYLE& operator = (const FILLSTYLE &style);            // 赋值运算符重载函数
 79     virtual ~FILLSTYLE();
 80 
 81     int            style;            // 填充形式
 82     long        hatch;            // 填充图案样式
 83     IMAGE*        ppattern;        // 填充图像
 84 };
 85 
 86 // 定义图像对象
 87 class IMAGE
 88 {
 89 public:
 90     int getwidth() const;    // 获取对象的宽度
 91     int getheight() const;    // 获取对象的高度
 92 
 93 private:
 94     int width, height;        // 对象的宽高
 95     HBITMAP m_hBmp;
 96     HDC m_hMemDC;
 97     int m_MemCurX;            // 当前点X坐标
 98     int m_MemCurY;            // 当前点Y坐标
 99     float m_data[6];
100     COLORREF    m_LineColor;        // 当前线条颜色
101     COLORREF    m_FillColor;        // 当前填充颜色
102     COLORREF    m_TextColor;        // 当前文字颜色
103     COLORREF    m_BkColor;            // 当前背景颜色
104     DWORD*        m_pBuffer;            // 绘图区的内存
105 
106     LINESTYLE    m_LineStyle;        // 画线样式
107     FILLSTYLE    m_FillStyle;        // 填充样式
108 
109     virtual void SetDefault();                        // 设置为默认状态
110 
111 public:
112     IMAGE(int _width = 0, int _height = 0);            // 创建图像
113     IMAGE(const IMAGE &img);                        // 拷贝构造函数
114     IMAGE& operator = (const IMAGE &img);            // 赋值运算符重载函数
115     virtual ~IMAGE();
116     virtual void Resize(int _width, int _height);    // 调整尺寸
117 };
118 
119 
120 
121 // 绘图模式相关函数
122 
123 HWND initgraph(int width, int height, int flag = NULL);    // 初始化图形环境
124 void closegraph();                                        // 关闭图形环境
125 
126 // 绘图环境设置
127 
128 void cleardevice();                    // 清屏
129 void setcliprgn(HRGN hrgn);            // 设置当前绘图设备的裁剪区
130 void clearcliprgn();                // 清除裁剪区的屏幕内容
131 
132 void getlinestyle(LINESTYLE* pstyle);                        // 获取当前画线样式
133 void setlinestyle(const LINESTYLE* pstyle);                    // 设置当前画线样式
134 void setlinestyle(int style, int thickness = 1, const DWORD *puserstyle = NULL, DWORD userstylecount = 0);    // 设置当前画线样式
135 void getfillstyle(FILLSTYLE* pstyle);                        // 获取当前填充样式
136 void setfillstyle(const FILLSTYLE* pstyle);                    // 设置当前填充样式
137 void setfillstyle(int style, long hatch = NULL, IMAGE* ppattern = NULL);        // 设置当前填充样式
138 void setfillstyle(BYTE* ppattern8x8);                        // 设置当前填充样式
139 
140 void setorigin(int x, int y);                            // 设置坐标原点
141 void getaspectratio(float *pxasp, float *pyasp);        // 获取当前缩放因子
142 void setaspectratio(float xasp, float yasp);            // 设置当前缩放因子
143 
144 int  getrop2();                        // 获取前景的二元光栅操作模式
145 void setrop2(int mode);                // 设置前景的二元光栅操作模式
146 int  getpolyfillmode();                // 获取多边形填充模式
147 void setpolyfillmode(int mode);        // 设置多边形填充模式
148 
149 void graphdefaults();                // 重置所有绘图设置为默认值
150 
151 COLORREF getlinecolor();            // 获取当前线条颜色
152 void setlinecolor(COLORREF color);    // 设置当前线条颜色
153 COLORREF gettextcolor();            // 获取当前文字颜色
154 void settextcolor(COLORREF color);    // 设置当前文字颜色
155 COLORREF getfillcolor();            // 获取当前填充颜色
156 void setfillcolor(COLORREF color);    // 设置当前填充颜色
157 COLORREF getbkcolor();                // 获取当前绘图背景色
158 void setbkcolor(COLORREF color);    // 设置当前绘图背景色
159 int  getbkmode();                    // 获取背景混合模式
160 void setbkmode(int mode);            // 设置背景混合模式
161 
162 // 颜色模型转换函数
163 COLORREF RGBtoGRAY(COLORREF rgb);
164 void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L);
165 void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V);
166 COLORREF HSLtoRGB(float H, float S, float L);
167 COLORREF HSVtoRGB(float H, float S, float V);
168 
169 
170 // 绘图函数
171 
172 COLORREF getpixel(int x, int y);                // 获取点的颜色
173 void putpixel(int x, int y, COLORREF color);    // 画点
174 
175 void moveto(int x, int y);                        // 移动当前点(绝对坐标)
176 void moverel(int dx, int dy);                    // 移动当前点(相对坐标)
177 
178 void line(int x1, int y1, int x2, int y2);        // 画线
179 void linerel(int dx, int dy);                    // 画线(至相对坐标)
180 void lineto(int x, int y);                        // 画线(至绝对坐标)
181 
182 void rectangle       (int left, int top, int right, int bottom);    // 画矩形
183 void fillrectangle (int left, int top, int right, int bottom);    // 画填充矩形(有边框)
184 void solidrectangle(int left, int top, int right, int bottom);    // 画填充矩形(无边框)
185 void clearrectangle(int left, int top, int right, int bottom);    // 清空矩形区域
186 
187 void circle        (int x, int y, int radius);        // 画圆
188 void fillcircle (int x, int y, int radius);        // 画填充圆(有边框)
189 void solidcircle(int x, int y, int radius);        // 画填充圆(无边框)
190 void clearcircle(int x, int y, int radius);        // 清空圆形区域
191 
192 void ellipse     (int left, int top, int right, int bottom);    // 画椭圆
193 void fillellipse (int left, int top, int right, int bottom);    // 画填充椭圆(有边框)
194 void solidellipse(int left, int top, int right, int bottom);    // 画填充椭圆(无边框)
195 void clearellipse(int left, int top, int right, int bottom);    // 清空椭圆形区域
196 
197 void roundrect       (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);        // 画圆角矩形
198 void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);        // 画填充圆角矩形(有边框)
199 void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);        // 画填充圆角矩形(无边框)
200 void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight);        // 清空圆角矩形区域
201 
202 void arc     (int left, int top, int right, int bottom, double stangle, double endangle);    // 画椭圆弧(起始角度和终止角度为弧度制)
203 void pie     (int left, int top, int right, int bottom, double stangle, double endangle);    // 画椭圆扇形(起始角度和终止角度为弧度制)
204 void fillpie (int left, int top, int right, int bottom, double stangle, double endangle);    // 画填充椭圆扇形(有边框)
205 void solidpie(int left, int top, int right, int bottom, double stangle, double endangle);    // 画填充椭圆扇形(无边框)
206 void clearpie(int left, int top, int right, int bottom, double stangle, double endangle);    // 清空椭圆扇形区域
207 
208 void polyline     (const POINT *points, int num);                                // 画多条连续的线
209 void polygon     (const POINT *points, int num);                                // 画多边形
210 void fillpolygon (const POINT *points, int num);                                // 画填充的多边形(有边框)
211 void solidpolygon(const POINT *points, int num);                                // 画填充的多边形(无边框)
212 void clearpolygon(const POINT *points, int num);                                // 清空多边形区域
213 
214 void polybezier(const POINT *points, int num);                                    // 画贝塞尔曲线
215 void floodfill(int x, int y, COLORREF color, int filltype = FLOODFILLBORDER);    // 填充区域
216 
217 
218 
219 // 文字相关函数
220 
221 void outtext(LPCTSTR str);                    // 在当前位置输出字符串
222 void outtext(TCHAR c);                        // 在当前位置输出字符
223 void outtextxy(int x, int y, LPCTSTR str);    // 在指定位置输出字符串
224 void outtextxy(int x, int y, TCHAR c);        // 在指定位置输出字符
225 int textwidth(LPCTSTR str);                    // 获取字符串占用的像素宽
226 int textwidth(TCHAR c);                        // 获取字符占用的像素宽
227 int textheight(LPCTSTR str);                // 获取字符串占用的像素高
228 int textheight(TCHAR c);                    // 获取字符占用的像素高
229 int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat);    // 在指定区域内以指定格式输出字符串
230 int drawtext(TCHAR c, RECT* pRect, UINT uFormat);        // 在指定区域内以指定格式输出字符
231 
232 // 设置当前字体样式(详见帮助)
233 //        nHeight: 字符的平均高度;
234 //        nWidth: 字符的平均宽度(0 表示自适应);
235 //        lpszFace: 字体名称;
236 //        nEscapement: 字符串的书写角度(单位 0.1 度);
237 //        nOrientation: 每个字符的书写角度(单位 0.1 度);
238 //        nWeight: 字符的笔画粗细(0 表示默认粗细);
239 //        bItalic: 是否斜体;
240 //        bUnderline: 是否下划线;
241 //        bStrikeOut: 是否删除线;
242 //        fbCharSet: 指定字符集;
243 //        fbOutPrecision: 指定文字的输出精度;
244 //        fbClipPrecision: 指定文字的剪辑精度;
245 //        fbQuality: 指定文字的输出质量;
246 //        fbPitchAndFamily: 指定以常规方式描述字体的字体系列。
247 void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace);
248 void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
249 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);
250 void settextstyle(const LOGFONT *font);    // 设置当前字体样式
251 void gettextstyle(LOGFONT *font);        // 获取当前字体样式
252 
253 
254 
255 // 图像处理函数
256 void loadimage(IMAGE *pDstImg, LPCTSTR pImgFile, int nWidth = 0, int nHeight = 0, bool bResize = false);                        // 从图片文件获取图像(bmp/gif/jpg/png/tif/emf/wmf/ico)
257 void loadimage(IMAGE *pDstImg, LPCTSTR pResType, LPCTSTR pResName, int nWidth = 0, int nHeight = 0, bool bResize = false);        // 从资源文件获取图像(bmp/gif/jpg/png/tif/emf/wmf/ico)
258 void saveimage(LPCTSTR pImgFile, IMAGE* pImg = NULL);                                                                            // 保存图像(bmp/gif/jpg/png/tif)
259 void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth, int srcHeight);                                                    // 从当前绘图设备获取图像
260 void putimage(int dstX, int dstY, const IMAGE *pSrcImg, DWORD dwRop = SRCCOPY);                                                    // 绘制图像到屏幕
261 void putimage(int dstX, int dstY, int dstWidth, int dstHeight, const IMAGE *pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY);        // 绘制图像到屏幕(指定宽高)
262 void rotateimage(IMAGE *dstimg, IMAGE *srcimg, double radian, COLORREF bkcolor = BLACK, bool autosize = false, bool highquality = true);// 旋转图像
263 void Resize(IMAGE* pImg, int width, int height);    // 调整绘图设备的大小
264 DWORD* GetImageBuffer(IMAGE* pImg = NULL);            // 获取绘图设备的显存指针
265 IMAGE* GetWorkingImage();                            // 获取当前绘图设备
266 void SetWorkingImage(IMAGE* pImg = NULL);            // 设置当前绘图设备
267 HDC GetImageHDC(IMAGE* pImg = NULL);                // 获取绘图设备句柄(HDC)
268 
269 
270 // 其它函数
271 
272 int    getwidth();            // 获取绘图区宽度
273 int    getheight();        // 获取绘图区高度
274 int    getx();                // 获取当前 x 坐标
275 int    gety();                // 获取当前 y 坐标
276 
277 void BeginBatchDraw();    // 开始批量绘制
278 void FlushBatchDraw();    // 执行未完成的绘制任务
279 void FlushBatchDraw(int left, int top, int right, int bottom);    // 执行指定区域内未完成的绘制任务
280 void EndBatchDraw();    // 结束批量绘制,并执行未完成的绘制任务
281 void EndBatchDraw(int left, int top, int right, int bottom);    // 结束批量绘制,并执行指定区域内未完成的绘制任务
282 
283 HWND GetHWnd();                                // 获取绘图窗口句柄(HWND)
284 TCHAR* GetEasyXVer();                        // 获取 EasyX 当前版本
285 
286 // 获取用户输入
287 bool InputBox(LPTSTR pString, int nMaxCount, LPCTSTR pPrompt = NULL, LPCTSTR pTitle = NULL, LPCTSTR pDefault = NULL, int width = 0, int height = 0, bool bOnlyOK = true);
288 
289 // 鼠标消息
290 // 支持如下消息:
291 //        WM_MOUSEMOVE        鼠标移动
292 //        WM_MOUSEWHEEL        鼠标滚轮拨动
293 //        WM_LBUTTONDOWN        左键按下
294 //        WM_LBUTTONUP        左键弹起
295 //        WM_LBUTTONDBLCLK    左键双击
296 //        WM_MBUTTONDOWN        中键按下
297 //        WM_MBUTTONUP        中键弹起
298 //        WM_MBUTTONDBLCLK    中键双击
299 //        WM_RBUTTONDOWN        右键按下
300 //        WM_RBUTTONUP        右键弹起
301 //        WM_RBUTTONDBLCLK    右键双击
302 
303 struct MOUSEMSG
304 {
305     UINT uMsg;                // 当前鼠标消息
306     bool mkCtrl;            // Ctrl 键是否按下
307     bool mkShift;            // Shift 键是否按下
308     bool mkLButton;            // 鼠标左键是否按下
309     bool mkMButton;            // 鼠标中键是否按下
310     bool mkRButton;            // 鼠标右键是否按下
311     short x;                // 当前鼠标 x 坐标
312     short y;                // 当前鼠标 y 坐标
313     short wheel;            // 鼠标滚轮滚动值 (120 的倍数)
314 };
315 
316 bool MouseHit();            // 检查是否存在鼠标消息
317 MOUSEMSG GetMouseMsg();        // 获取一个鼠标消息。如果没有,就等待
318 void FlushMouseMsgBuffer();    // 清空鼠标消息缓冲区

 

 

 

 

 

========================================================================================================================

标签:COLORREF,const,int,void,EasyX,接口,绘图,IMAGE,define
来源: https://www.cnblogs.com/CooCoChoco/p/13196305.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有