Skip to content

Commit

Permalink
feat: 增加 flushwindow() 函数, 用于将后台帧缓冲中的内容显示到窗口 (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only authored Apr 30, 2024
1 parent d0d2eb9 commit 557fa96
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 34 deletions.
1 change: 1 addition & 0 deletions include/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ int EGEAPI attachHWND(HWND hWnd);

void EGEAPI movewindow(int x, int y, bool redraw = true);
void EGEAPI resizewindow(int width, int height);
void EGEAPI flushwindow();

void EGEAPI setrendermode(rendermode_e mode);

Expand Down
5 changes: 5 additions & 0 deletions src/ege_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ void setmode(int gdriver, int gmode);

// GDI+ 初始化
void gdipluinit();

int swapbuffers();

bool isinitialized();

}
6 changes: 5 additions & 1 deletion src/egegapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "ege_extension.h"



#include <stdio.h>

namespace ege
Expand All @@ -41,6 +40,11 @@ bool is_run()
return true;
}

bool isinitialized()
{
return graph_setting.has_init;
}

int showmouse(int bShow)
{
struct _graph_setting* pg = &graph_setting;
Expand Down
88 changes: 55 additions & 33 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static void ui_msg_process(EGEMSG& qmsg)
}

/*private function*/
/*
static int redraw_window(_graph_setting* pg, HDC dc)
{
int page = pg->visual_page;
Expand All @@ -151,48 +152,69 @@ static int redraw_window(_graph_setting* pg, HDC dc)
pg->update_mark_count = UPDATE_MAX_CALL;
return 0;
}
*/

int swapbuffers()
{
if (!isinitialized())
return grNoInitGraph;

struct _graph_setting* pg = &graph_setting;

PIMAGE backFrameBuffer = pg->img_page[pg->visual_page];
HDC backFrameBufferDC = backFrameBuffer->getdc();

int left = backFrameBuffer->m_vpt.left;
int top = backFrameBuffer->m_vpt.top;

HDC frontFrameBufferDC = GetDC(getHWnd());
BitBlt(frontFrameBufferDC, 0, 0, pg->base_w, pg->base_h, backFrameBufferDC, pg->base_x - left, pg->base_y - top, SRCCOPY);
ReleaseDC(getHWnd(), frontFrameBufferDC);

return grOk;
}

/*private function*/
static int graphupdate(_graph_setting* pg)
{
if (pg->exit_window) {
return grNoInitGraph;
}
{
if (IsWindowVisible(pg->hwnd)) {
HDC hdc = ::GetDC(pg->hwnd);
redraw_window(pg, hdc);
::ReleaseDC(pg->hwnd, hdc);
} else {
pg->update_mark_count = UPDATE_MAX_CALL;
}
EGE_PRIVATE_GetFPS(0x100);
{
RECT rect, crect;
HWND hwnd;
int _dw, _dh;
GetClientRect(pg->hwnd, &crect);
GetWindowRect(pg->hwnd, &rect);
int w = pg->dc_w, h = pg->dc_h;
_dw = w - (crect.right - crect.left);
_dh = h - (crect.bottom - crect.top);
if (_dw != 0 || _dh != 0) {
hwnd = ::GetParent(pg->hwnd);
if (hwnd) {
POINT pt = {0, 0};
ClientToScreen(hwnd, &pt);
rect.left -= pt.x;
rect.top -= pt.y;
rect.right -= pt.x;
rect.bottom -= pt.y;
}
SetWindowPos(pg->hwnd, NULL, 0, 0, rect.right + _dw - rect.left, rect.bottom + _dh - rect.top,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}
}

return grOk;
if (IsWindowVisible(pg->hwnd)) {
swapbuffers();
}

pg->update_mark_count = UPDATE_MAX_CALL;

EGE_PRIVATE_GetFPS(0x100);

RECT rect, crect;
HWND hwnd;
int _dw, _dh;

GetClientRect(pg->hwnd, &crect);
GetWindowRect(pg->hwnd, &rect);
int w = pg->dc_w, h = pg->dc_h;
_dw = w - (crect.right - crect.left);
_dh = h - (crect.bottom - crect.top);

if (_dw != 0 || _dh != 0) {
hwnd = ::GetParent(pg->hwnd);
if (hwnd) {
POINT pt = {0, 0};
ClientToScreen(hwnd, &pt);
rect.left -= pt.x;
rect.top -= pt.y;
rect.right -= pt.x;
rect.bottom -= pt.y;
}
SetWindowPos(pg->hwnd, NULL, 0, 0, rect.right + _dw - rect.left, rect.bottom + _dh - rect.top,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER);
}

return grOk;

}

int dealmessage(_graph_setting* pg, bool force_update)
Expand Down
10 changes: 10 additions & 0 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ void movewindow(int x, int y, bool redraw)
::MoveWindow(getHWnd(), x, y, getwidth(), getheight(), redraw);
}

void flushwindow()
{
if (!isinitialized())
return;
struct _graph_setting* pg = &graph_setting;
pg->skip_timer_mark = true;
swapbuffers();
pg->skip_timer_mark = false;
}

HWND getParentWindow()
{
return g_attach_hwnd;
Expand Down

0 comments on commit 557fa96

Please sign in to comment.