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

📄 pex.h

📁 MP4源代码
💻 H
📖 第 1 页 / 共 3 页
字号:
struct linestyletype {
    int linestyle;
    unsigned short upattern;
    int thickness;
};


// 绘图环境初始化参数
#define SHOWCONSOLE     1       // 进入图形模式时,保留控制台的显示
#define RGBTOBGR(color) ((((color) & 0xFF) << 16) | (((color) & 0xFF0000) >> 16) | ((color) & 0xFF00FF00))
#define INITGRAPH(x, y) struct _initgraph_{_initgraph_(){initgraph(x, y);}\
    ~_initgraph_(){closegraph();}}_g_initgraph_
#define INITGRAPH3(x, y, f) struct _initgraph_{_initgraph_(){initgraph(x, y, f);}\
    ~_initgraph_(){closegraph();}}_g_initgraph_


typedef void (CALLBACK_PROC)();
typedef int (__stdcall MSG_KEY_PROC  )(void*, unsigned, int);
typedef int (__stdcall MSG_MOUSE_PROC)(void*, unsigned, int, int, int);
typedef CALLBACK_PROC       * LPCALLBACK_PROC;
typedef MSG_KEY_PROC        * LPMSG_KEY_PROC;
typedef MSG_MOUSE_PROC      * LPMSG_MOUSE_PROC;

/*
注意:以下函数的注释后带'###'的函数表示未实现
*/

struct VECTOR3D;

// 3d 计算辅助函数
void rotate_point3d_x(VECTOR3D  * pt, float r); //弧度,右手定则
void rotate_point3d_y(VECTOR3D  * pt, float r);
void rotate_point3d_z(VECTOR3D  * pt, float r);

struct VECTOR3D {
    float x, y, z;
    VECTOR3D() {
        x = 0; y = 0; z = 0;
    }
    VECTOR3D(float _x, float _y) {
        x = _x; y = _y; z = 0;
    }
    VECTOR3D(float _x, float _y, float _z) {
        x = _x; y = _y; z = _z;
    }
    VECTOR3D& operator = (const VECTOR3D& _fp)  {
        x = _fp.x; y = _fp.y; z = _fp.z;
        return *this;
    }
    VECTOR3D& operator += (const VECTOR3D& _fp);
    VECTOR3D& operator -= (const VECTOR3D& _fp);
    VECTOR3D operator + (const VECTOR3D& _fp) const;
    VECTOR3D operator - (const VECTOR3D& _fp) const;
    VECTOR3D& operator *= (float f); //缩放
    VECTOR3D operator * (float f) const; //缩放
    float operator * (const VECTOR3D& _fp) const; //点乘
    VECTOR3D operator & (const VECTOR3D& _fp) const; //叉乘
    VECTOR3D& operator &= (const VECTOR3D& _fp); //叉乘
    float GetModule() const {
        return (float)sqrt(x*x + y*y + z*z);
    }
    float GetSqrModule() const {
        return float(x*x + y*y + z*z);
    }
    VECTOR3D& SetModule(float m) {
        float t = m / GetModule();
        *this *= t;
        return *this;
    }
    VECTOR3D& Rotate(float rad, const VECTOR3D& v); //绕任意轴旋转,右手定则,rad为弧度
    VECTOR3D& Rotate(float rad, float x, float y, float z) {
        VECTOR3D v(x, y, z);
        return Rotate(rad, v);
    }
    VECTOR3D& Rotate(const VECTOR3D& e, const VECTOR3D& s = VECTOR3D(0.0f, 0.0f, 1.0f)); //从s到e之间的夹角确定旋转
    static float GetAngel(const VECTOR3D& e, const VECTOR3D& s = VECTOR3D(0.0f, 0.0f, 1.0f));
};

// 绘图模式相关函数

void initgraph(int Width, int Height, int Flag = 0); // 初始化图形环境
void initgraph(int* gdriver, int* gmode, char* path);   // 兼容 Borland C++ 3.1 的重载,只使用 640x480x24bit
void closegraph();                                      // 关闭图形环境


class IMAGE;
typedef IMAGE *PIMAGE;

// 绘图环境设置

void cleardevice(IMAGE* pimg = NULL);                   // 清屏

void getviewport(int *pleft, int *ptop, int *pright, int *pbottom, int *pclip = 0, IMAGE* pimg = NULL); // 获取视图信息
void setviewport(int left, int top, int right, int bottom, int clip = 1, IMAGE* pimg = NULL);           // 设置视图
void clearviewport(IMAGE* pimg = NULL);                                                                     // 清空视图

void getlinestyle(int *plinestyle, WORD *pupattern = NULL, int *pthickness = NULL, IMAGE* pimg = NULL); // 获取当前线形
void setlinestyle(int linestyle, WORD upattern = NULL, int thickness = 1, IMAGE* pimg = NULL);          // 设置当前线形
//void getfillstyle(COLORREF *pcolor, int *ppattern = NULL, char *pupattern = NULL, IMAGE* pimg = NULL);          // 获取填充类型 ###
void setfillstyle(COLORREF color, int pattern = SOLID_FILL, const char *pupattern = NULL, IMAGE* pimg = NULL);  // 设置填充类型

//void getaspectratio(float *pxasp, float *pyasp);        // 获取当前缩放因子 ###
//void setaspectratio(float xasp = 1, float yasp = 1);    // 设置当前缩放因子 ###

void setwritemode(int mode, IMAGE* pimg = NULL);        // 设置绘图位操作模式

//void graphdefaults(IMAGE* pimg = NULL);                 // 重置所有绘图设置为默认值 ###

COLORREF getcolor(IMAGE* pimg = NULL);                  // 获取当前绘图前景色
void setcolor(COLORREF color, IMAGE* pimg = NULL);      // 设置当前绘图前景色
COLORREF getbkcolor(IMAGE* pimg = NULL);                // 获取当前绘图背景色
void setbkcolor(COLORREF color, IMAGE* pimg = NULL);    // 设置当前绘图背景色
void setbkcolor_f(COLORREF color, IMAGE* pimg = NULL);  // 快速设置当前绘图背景色(只设置不绘画)
void setfontbkcolor(COLORREF color, IMAGE* pimg = NULL);// 设置当前文字背景色
void setbkmode(int iBkMode, IMAGE* pimg = NULL);        // 设置背景混合模式(0=OPAQUE, 1=TRANSPARENT)
void setinitmode(int mode, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT); //设置初始化模式,mode=0为普通,1为无边框窗口,xy是初始窗口坐标

// 颜色模型转换函数
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, IMAGE* pimg = NULL);                   // 获取点的颜色
void        putpixel  (int x, int y, COLORREF color, IMAGE* pimg = NULL);   // 画点
COLORREF    getpixel_f(int x, int y, IMAGE* pimg = NULL);                   // 获取点的颜色
void        putpixel_f(int x, int y, COLORREF color, IMAGE* pimg = NULL);   // 画点
void        putpixels  (int nPoint, int* pPoints, IMAGE* pimg = NULL);      // 批量画点
void        putpixels_f(int nPoint, int* pPoints, IMAGE* pimg = NULL);      // 批量画点

void moveto(int x, int y, IMAGE* pimg = NULL);                      // 移动当前点(绝对坐标)
void moverel(int dx, int dy, IMAGE* pimg = NULL);                   // 移动当前点(相对坐标)

void line(int x1, int y1, int x2, int y2, IMAGE* pimg = NULL);      // 画线
void linerel(int dx, int dy, IMAGE* pimg = NULL);                   // 画线(至相对坐标)
void lineto(int x, int y, IMAGE* pimg = NULL);                      // 画线(至绝对坐标)

void rectangle(int left, int top, int right, int bottom, IMAGE* pimg = NULL);   // 画矩形

//void getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend, IMAGE* pimg = NULL);    // 获取圆弧坐标信息 ###
void arc(int x, int y, int stangle, int endangle, int radius, IMAGE* pimg = NULL);                  // 画圆弧
void circle(int x, int y, int radius, IMAGE* pimg = NULL);                                          // 画圆
void pieslice(int x, int y, int stangle, int endangle, int radius, IMAGE* pimg = NULL);             // 画填充圆扇形
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius, IMAGE* pimg = NULL);// 画椭圆弧线
void fillellipse(int x, int y, int xradius, int yradius, IMAGE* pimg = NULL);                       // 画填充椭圆
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius, IMAGE* pimg = NULL); // 画填充椭圆扇形

void bar(int left, int top, int right, int bottom, IMAGE* pimg = NULL);                             // 画无边框填充矩形
void bar3d(int left, int top, int right, int bottom, int depth, int topflag, IMAGE* pimg = NULL);   // 画有边框三维填充矩形

void drawpoly(int numpoints, const int *polypoints, IMAGE* pimg = NULL);    // 画多边形
void fillpoly(int numpoints, const int *polypoints, IMAGE* pimg = NULL);    // 画填充的多边形
void floodfill(int x, int y, int border, IMAGE* pimg = NULL);               // 填充区域

void setactivepage(int page); // 设置当前绘图页,即绘图函数默认的输出缓冲,范围0-1,默认为0
void setvisualpage(int page); // 设置当前显示页,用于设置显示到窗口上的页,范围0-1,默认为0
void swappage();
void window_getviewport(struct viewporttype * viewport);
void window_getviewport(int* left, int* top, int* right, int* bottom);
void window_setviewport(int  left, int  top, int  right, int  bottom);

//int  Begin2d();
//void EndRender();

//键盘处理函数
int getkey();
int getchEx(int flag = 0);  //flag参数如果为1(不能是其它值),表示把KEY_DOWN和KEY_UP事件取得,返回值会包含KEYMSG_DOWN或者KEYMSG_UP位
int kbhitEx(int flag = 0);  //(接上)而低四位是虚拟键码,与flag=0时特殊按键的键码会不相同
int keystate(int key);      //获得键码为key的键是否按下,如果key使用鼠标按键的键码,则获得的是鼠标键状态

//#ifndef _GRAPH_LIB_BUILD_
#if !defined(_INC_CONIO) && !defined(_CONIO_H_)
#define _INC_CONIO
#define _CONIO_H_
#define getch getchEx
#define kbhit kbhitEx
#endif
//#endif

//时间函数
void delay(int ms);         // 同delay_ms
void delay_ms(int ms);      // 延迟ms毫秒
void delay_fps(int fps);    // 延迟1000/fps毫秒,用于稳定帧率控制
void delay_jfps(int fps);   // 延迟1000/fps毫秒,用于稳定逻辑帧率控制,绘图带跳帧
void API_Sleep(DWORD dwMilliseconds);
double fclock();

// 文字相关函数
void outtext(LPCSTR  textstring, IMAGE* pimg = NULL);                   // 在当前位置输出文字
void outtext(LPCWSTR textstring, IMAGE* pimg = NULL);                   // 在当前位置输出文字
void outtext(CHAR  c, IMAGE* pimg = NULL);                              // 在当前位置输出字符
void outtext(WCHAR c, IMAGE* pimg = NULL);                              // 在当前位置输出字符
void outtextxy(int x, int y, LPCSTR  textstring, IMAGE* pimg = NULL);   // 在指定位置输出文字
void outtextxy(int x, int y, LPCWSTR textstring, IMAGE* pimg = NULL);   // 在指定位置输出文字
void outtextxy(int x, int y, CHAR c, IMAGE* pimg = NULL);               // 在指定位置输出字符
void outtextxy(int x, int y, WCHAR c, IMAGE* pimg = NULL);              // 在指定位置输出字符
void outtextrect(int x, int y, int w, int h, LPCSTR  textstring, IMAGE* pimg = NULL); // 在指定矩形范围输出文字
void outtextrect(int x, int y, int w, int h, LPCWSTR textstring, IMAGE* pimg = NULL); // 在指定矩形范围输出文字

int  textwidth(LPCSTR  textstring, IMAGE* pimg = NULL);                 // 获取字符串占用的像素宽
int  textwidth(LPCWSTR textstring, IMAGE* pimg = NULL);                 // 获取字符串占用的像素宽
int  textwidth(CHAR  c, IMAGE* pimg = NULL);
int  textwidth(WCHAR c, IMAGE* pimg = NULL);
int  textheight(LPCSTR  textstring, IMAGE* pimg = NULL);                // 获取字符串占用的像素高
int  textheight(LPCWSTR textstring, IMAGE* pimg = NULL);                // 获取字符串占用的像素高
int  textheight(CHAR  c, IMAGE* pimg = NULL);
int  textheight(WCHAR c, IMAGE* pimg = NULL);
void settextjustify(int horiz, int vert, IMAGE* pimg = NULL);

// 设置当前字体样式(详见帮助)
//      nHeight: 字符的平均高度;
//      nWidth: 字符的平均宽度(0 表示自适应);
//      lpszFace: 字体名称;
//      nEscapement: 字符串的书写角度(单位 0.1 度);
//      nOrientation: 每个字符的书写角度(单位 0.1 度);
//      nWeight: 字符的笔画粗细(0 表示默认粗细);
//      bItalic: 是否斜体;
//      bUnderline: 是否下划线;
//      bStrikeOut: 是否删除线;
//      fbCharSet: 指定字符集;
//      fbOutPrecision: 指定文字的输出精度;
//      fbClipPrecision: 指定文字的剪辑精度;
//      fbQuality: 指定文字的输出质量;
//      fbPitchAndFamily: 指定以常规方式描述字体的字体系列。
void setfont(int nHeight, int nWidth, LPCSTR lpszFace,  IMAGE* pimg = NULL);
void setfont(int nHeight, int nWidth, LPCWSTR lpszFace, IMAGE* pimg = NULL);
void setfont(int nHeight, int nWidth, LPCSTR lpszFace,  int nEscapement, int nOrientation, int nWeight, int bItalic, int bUnderline, int bStrikeOut, IMAGE* pimg = NULL);
void setfont(int nHeight, int nWidth, LPCWSTR lpszFace, int nEscapement, int nOrientation, int nWeight, int bItalic, int bUnderline, int bStrikeOut, IMAGE* pimg = NULL);
void setfont(int nHeight, int nWidth, LPCSTR lpszFace,  int nEscapement, int nOrientation, int nWeight, int bItalic, int bUnderline, int bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily, IMAGE* pimg = NULL);
void setfont(int nHeight, int nWidth, LPCWSTR lpszFace, int nEscapement, int nOrientation, int nWeight, int bItalic, int bUnderline, int bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily, IMAGE* pimg = NULL);
void setfont(const LOGFONTA *font, IMAGE* pimg = NULL); // 设置当前字体样式
void setfont(const LOGFONTW *font, IMAGE* pimg = NULL); // 设置当前字体样式
void getfont(LOGFONTA *font, IMAGE* pimg = NULL);       // 获取当前字体样式
void getfont(LOGFONTW *font, IMAGE* pimg = NULL);       // 获取当前字体样式



// 图像处理函数

// 定义图像对象
class IMAGE
{
    int     m_initflag;
#ifdef _GRAPH_LIB_BUILD_
public:
#else
private:
#endif
    HDC     m_hDC;
    HBITMAP m_hBmp;
    //HRGN    m_rgn;
    int     m_width;
    int     m_height;
    PDWORD  m_pBuffer;
private:
    int newimage(HDC hdc, int width, int height);

⌨️ 快捷键说明

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