Skip to content

Commit

Permalink
Merge pull request #36 from chirsz-ever/initgraph-2007
Browse files Browse the repository at this point in the history
修改 `initgraph` 的定义,使代码更清晰
  • Loading branch information
wysaid authored Aug 11, 2020
2 parents 7a74063 + f059d41 commit f7ec076
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
38 changes: 19 additions & 19 deletions src/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,15 @@ enum music_state_flag {
};

enum initmode_flag {
INIT_DEFAULT = 0x0,
INIT_NOBORDER = 0x1,
INIT_CHILD = 0x2,
INIT_TOPMOST = 0x4,
INIT_RENDERMANUAL = 0x8,
INIT_NOFORCEEXIT = 0x10,
INIT_UNICODE = 0x20,
INIT_WITHLOGO = 0x100,
#if defined(_DEBUG) || defined(DEBUG)
INIT_DEFAULT = 0x0,
#else
INIT_DEFAULT = INIT_WITHLOGO,
#endif
INIT_ANIMATION = INIT_DEFAULT | INIT_RENDERMANUAL | INIT_NOFORCEEXIT,
INIT_ANIMATION = INIT_DEFAULT | INIT_RENDERMANUAL | INIT_NOFORCEEXIT,
};

enum rendermode_e {
Expand Down Expand Up @@ -554,12 +550,6 @@ struct msg_createwindow {
};


// 绘图环境初始化参数
#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_

//音乐类宏
#define MUSIC_ERROR 0xFFFFFFFF

Expand Down Expand Up @@ -630,14 +620,26 @@ typedef IMAGE *PIMAGE;
typedef const IMAGE *PCIMAGE;

// 绘图环境相关函数

void EGEAPI initgraph(int Width, int Height, int Flag = INIT_DEFAULT); // 初始化图形环境
void EGEAPI initgraph(int* gdriver, int* gmode, char* path); // 兼容 Borland C++ 3.1 的重载,只使用 640x480x24bit
void EGEAPI closegraph(); // 关闭图形环境
bool EGEAPI is_run(); // 判断UI是否退出
void EGEAPI setinitmode(int mode, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT); //设置初始化模式,mode=0为普通,1为无边框窗口,xy是初始窗口坐标
int EGEAPI getinitmode();
void EGEAPI initgraph(int Width, int Height, int Flag); // 初始化图形环境
// Debug 配置下默认不显示 LOGO,Release 模式下默认显示。
#if !defined(NDEBUG) || defined(DEBUG) || defined(_DEBUG)
inline void EGEAPI initgraph(int Width, int Height) {
initgraph(Width, Height, getinitmode());
}
#else
inline void EGEAPI initgraph(int Width, int Height) {
initgraph(Width, Height, getinitmode()|INIT_WITHLOGO);
}
#endif
void EGEAPI initgraph(int* gdriver, int* gmode, const char* path); // 兼容 Borland C++ 3.1 的重载,只使用 640x480x24bit
void EGEAPI closegraph(); // 关闭图形环境
bool EGEAPI is_run(); // 判断UI是否退出
void EGEAPI setcaption(LPCSTR caption);
void EGEAPI setcaption(LPCWSTR caption);
void EGEAPI seticon(int icon_id);
int EGEAPI attachHWND(HWND hWnd);

void EGEAPI movewindow(int x, int y, bool redraw = true); //移动窗口
void EGEAPI resizewindow(int width, int height); //重设窗口尺寸
Expand Down Expand Up @@ -688,8 +690,6 @@ EGE_DEPRECATE(setfillstyle)
void EGEAPI setbkcolor_f(color_t color, PIMAGE pimg = NULL); // 快速设置当前绘图背景色(只设置不绘画)
void EGEAPI setfontbkcolor(color_t color, PIMAGE pimg = NULL); // 设置当前文字背景色
void EGEAPI setbkmode(int iBkMode, PIMAGE pimg = NULL); // 设置背景混合模式(0=OPAQUE, 1=TRANSPARENT)
void EGEAPI setinitmode(int mode = INIT_DEFAULT, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT); //设置初始化模式,mode=0为普通,1为无边框窗口,xy是初始窗口坐标
int EGEAPI attachHWND(HWND hWnd);

// 兼容宏
#define RGBtoGRAY rgb2gray
Expand Down
18 changes: 8 additions & 10 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static DWORD g_windowstyle = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEB
static DWORD g_windowexstyle = WS_EX_LEFT|WS_EX_LTRREADING;
static int g_windowpos_x = CW_USEDEFAULT;
static int g_windowpos_y = CW_USEDEFAULT;
static int g_initoption = -1;
static int g_initoption = INIT_DEFAULT;
static HWND g_attach_hwnd = 0;
static WNDPROC DefWindowProcFunc = NULL;

Expand Down Expand Up @@ -1239,7 +1239,7 @@ void initicon(void) {
}

void
initgraph(int *gdriver, int *gmode, char *path) {
initgraph(int *gdriver, int *gmode, const char *path) {
struct _graph_setting * pg = &graph_setting;

pg->exit_flag = 0;
Expand All @@ -1257,8 +1257,6 @@ initgraph(int *gdriver, int *gmode, char *path) {
}

//初始化环境
if (g_initoption == -1)
setinitmode();
setmode(*gdriver, *gmode);
init_img_page(pg);

Expand Down Expand Up @@ -1304,12 +1302,8 @@ initgraph(int *gdriver, int *gmode, char *path) {
void
initgraph(int Width, int Height, int Flag) {
int g = TRUECOLORSIZE, m = (Width) | (Height<<16);

if (g_initoption == -1)
setinitmode(Flag);

initgraph(&g, &m, (char*)"");
//using flag;
setinitmode(Flag);
initgraph(&g, &m, "");
}

void
Expand Down Expand Up @@ -1412,6 +1406,10 @@ setinitmode(int mode, int x, int y) {
g_windowpos_y = y;
}

int getinitmode() {
return g_initoption;
}

// 获取当前版本 ####
int getGraphicsVer() {
return EGE_VERSION_INT;
Expand Down

0 comments on commit f7ec076

Please sign in to comment.