From 70a0f4a71894c3c2bb2a0588e4d546767ade1c03 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 30 Dec 2022 16:58:40 -0800 Subject: [PATCH 1/5] only do a full refresh when needed this significantly reduces CPU utilization when DFHack-owned screens are visible. --- docs/dev/Lua API.rst | 9 ++++++++- library/lua/gui.lua | 6 +++++- library/lua/gui/widgets.lua | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 7c6e72f19..683bb9d29 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2363,7 +2363,14 @@ Supported callbacks and fields are: where the above painting functions work correctly. If omitted, the screen is cleared; otherwise it should do that itself. - In order to make a see-through dialog, call ``self._native.parent:render()``. + In order to make a dialog where portions of the parent viewscreen are still + visible in the background, call ``screen:renderParent()``. + + If artifacts are left on the parent even after this function is called, such + as when the window is dragged or is resized, any code can set + ``gui.Screen.request_full_screen_refresh`` to ``true``. Then when + ``screen.renderParent()`` is next called, it will do a full flush of the + graphics and clear the screen of artifacts. * ``function screen:onIdle()`` diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 1eaa9861a..ba15e32aa 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -597,6 +597,7 @@ end Screen = defclass(Screen, View) Screen.text_input_mode = false +Screen.request_full_screen_refresh = false function Screen:postinit() self:onResize(dscreen.getWindowSize()) @@ -622,7 +623,10 @@ function Screen:renderParent() else dscreen.clear() end - df.global.gps.force_full_display_count = 1 + if Screen.request_full_screen_refresh then + df.global.gps.force_full_display_count = 1 + Screen.request_full_screen_refresh = false + end end function Screen:sendInputToParent(...) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 55d8facf9..18d61c6b3 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -487,6 +487,10 @@ Window.ATTRS { draggable = true, } +function Window:postUpdateLayout() + gui.Screen.request_full_screen_refresh = true +end + ------------------- -- ResizingPanel -- ------------------- From 88dcdfd158a44e0ca4c061d1e549d8fe028915c7 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 30 Dec 2022 20:01:09 -0800 Subject: [PATCH 2/5] move trigger code from Window to Panel where the drag/resize code actually is. Panels can be dragged around the parent screen without them being a Window --- library/lua/gui/widgets.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 18d61c6b3..19b898446 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -441,6 +441,9 @@ end -- if self.autoarrange_subviews is true, lay out visible subviews vertically, -- adding gaps between widgets according to self.autoarrange_gap. function Panel:postUpdateLayout() + -- don't leave artifacts behind on the parent screen when we move + gui.Screen.request_full_screen_refresh = true + if not self.autoarrange_subviews then return end local gap = self.autoarrange_gap @@ -487,10 +490,6 @@ Window.ATTRS { draggable = true, } -function Window:postUpdateLayout() - gui.Screen.request_full_screen_refresh = true -end - ------------------- -- ResizingPanel -- ------------------- From 33787473f0b058df5032b4cee82d0b4acd802f12 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 30 Dec 2022 20:44:15 -0800 Subject: [PATCH 3/5] consolidate full refresh logic in widgets.Panel --- docs/dev/Lua API.rst | 6 ------ library/lua/gui.lua | 5 ----- library/lua/gui/widgets.lua | 6 +++++- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 683bb9d29..93a3ea160 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2366,12 +2366,6 @@ Supported callbacks and fields are: In order to make a dialog where portions of the parent viewscreen are still visible in the background, call ``screen:renderParent()``. - If artifacts are left on the parent even after this function is called, such - as when the window is dragged or is resized, any code can set - ``gui.Screen.request_full_screen_refresh`` to ``true``. Then when - ``screen.renderParent()`` is next called, it will do a full flush of the - graphics and clear the screen of artifacts. - * ``function screen:onIdle()`` Called every frame when the screen is on top of the stack. diff --git a/library/lua/gui.lua b/library/lua/gui.lua index ba15e32aa..1bb9bae6b 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -597,7 +597,6 @@ end Screen = defclass(Screen, View) Screen.text_input_mode = false -Screen.request_full_screen_refresh = false function Screen:postinit() self:onResize(dscreen.getWindowSize()) @@ -623,10 +622,6 @@ function Screen:renderParent() else dscreen.clear() end - if Screen.request_full_screen_refresh then - df.global.gps.force_full_display_count = 1 - Screen.request_full_screen_refresh = false - end end function Screen:sendInputToParent(...) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 19b898446..01e1de89d 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -442,7 +442,7 @@ end -- adding gaps between widgets according to self.autoarrange_gap. function Panel:postUpdateLayout() -- don't leave artifacts behind on the parent screen when we move - gui.Screen.request_full_screen_refresh = true + self.request_full_screen_refresh = true if not self.autoarrange_subviews then return end @@ -464,6 +464,10 @@ end function Panel:onRenderFrame(dc, rect) Panel.super.onRenderFrame(self, dc, rect) + if self.request_full_screen_refresh then + df.global.gps.force_full_display_count = 1 + self.request_full_screen_refresh = false + end if not self.frame_style then return end gui.paint_frame(dc, rect, self.frame_style, self.frame_title) if self.kbd_get_pos then From dd0cc087d5d32f96dcee428b37f5003e68327e03 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 30 Dec 2022 22:13:53 -0800 Subject: [PATCH 4/5] Revert "consolidate full refresh logic in widgets.Panel" This reverts commit 33787473f0b058df5032b4cee82d0b4acd802f12. I've already found another use case where we need a more general implementation -- modal dialogs that inherit from FramedScreen that appear and disappear --- docs/dev/Lua API.rst | 6 ++++++ library/lua/gui.lua | 5 +++++ library/lua/gui/widgets.lua | 6 +----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 93a3ea160..683bb9d29 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2366,6 +2366,12 @@ Supported callbacks and fields are: In order to make a dialog where portions of the parent viewscreen are still visible in the background, call ``screen:renderParent()``. + If artifacts are left on the parent even after this function is called, such + as when the window is dragged or is resized, any code can set + ``gui.Screen.request_full_screen_refresh`` to ``true``. Then when + ``screen.renderParent()`` is next called, it will do a full flush of the + graphics and clear the screen of artifacts. + * ``function screen:onIdle()`` Called every frame when the screen is on top of the stack. diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 1bb9bae6b..ba15e32aa 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -597,6 +597,7 @@ end Screen = defclass(Screen, View) Screen.text_input_mode = false +Screen.request_full_screen_refresh = false function Screen:postinit() self:onResize(dscreen.getWindowSize()) @@ -622,6 +623,10 @@ function Screen:renderParent() else dscreen.clear() end + if Screen.request_full_screen_refresh then + df.global.gps.force_full_display_count = 1 + Screen.request_full_screen_refresh = false + end end function Screen:sendInputToParent(...) diff --git a/library/lua/gui/widgets.lua b/library/lua/gui/widgets.lua index 01e1de89d..19b898446 100644 --- a/library/lua/gui/widgets.lua +++ b/library/lua/gui/widgets.lua @@ -442,7 +442,7 @@ end -- adding gaps between widgets according to self.autoarrange_gap. function Panel:postUpdateLayout() -- don't leave artifacts behind on the parent screen when we move - self.request_full_screen_refresh = true + gui.Screen.request_full_screen_refresh = true if not self.autoarrange_subviews then return end @@ -464,10 +464,6 @@ end function Panel:onRenderFrame(dc, rect) Panel.super.onRenderFrame(self, dc, rect) - if self.request_full_screen_refresh then - df.global.gps.force_full_display_count = 1 - self.request_full_screen_refresh = false - end if not self.frame_style then return end gui.paint_frame(dc, rect, self.frame_style, self.frame_title) if self.kbd_get_pos then From 1d7a7c8a49f2fc3bcc4030eacfe1735808e1d972 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 30 Dec 2022 22:20:50 -0800 Subject: [PATCH 5/5] Don't leave artifats behind when dimissing mboxes --- library/lua/gui.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/lua/gui.lua b/library/lua/gui.lua index ba15e32aa..31631b469 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -661,6 +661,8 @@ function Screen:dismiss() if self._native then dscreen.dismiss(self) end + -- don't leave artifacts behind on the parent screen when we disappear + Screen.request_full_screen_refresh = true end function Screen:onDismiss()