From c3c32a81fd797888fd1946e71472d31af4dd57aa Mon Sep 17 00:00:00 2001 From: yixy-only Date: Tue, 30 Apr 2024 22:21:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20flushwindow()=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0,=20=E7=94=A8=E4=BA=8E=E5=B0=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E5=B8=A7=E7=BC=93=E5=86=B2=E4=B8=AD=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=98=BE=E7=A4=BA=E5=88=B0=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/ege.h | 1 + src/ege_graph.h | 5 +++ src/egegapi.cpp | 6 +++- src/graphics.cpp | 88 ++++++++++++++++++++++++++++++------------------ src/window.cpp | 10 ++++++ 5 files changed, 76 insertions(+), 34 deletions(-) diff --git a/include/ege.h b/include/ege.h index e96d5144..6b834636 100644 --- a/include/ege.h +++ b/include/ege.h @@ -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); diff --git a/src/ege_graph.h b/src/ege_graph.h index c003378d..04fb30a4 100644 --- a/src/ege_graph.h +++ b/src/ege_graph.h @@ -33,4 +33,9 @@ void setmode(int gdriver, int gmode); // GDI+ 初始化 void gdipluinit(); + +int swapbuffers(); + +bool isinitialized(); + } diff --git a/src/egegapi.cpp b/src/egegapi.cpp index b7be42f1..8ea3df2b 100644 --- a/src/egegapi.cpp +++ b/src/egegapi.cpp @@ -26,7 +26,6 @@ #include "ege_extension.h" - #include namespace ege @@ -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; diff --git a/src/graphics.cpp b/src/graphics.cpp index 77f876df..32b81c5c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -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; @@ -151,6 +152,27 @@ 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) @@ -158,41 +180,41 @@ 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) diff --git a/src/window.cpp b/src/window.cpp index 0d3a0350..8e35ca27 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -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;