From fea9cfb0c847acce80a204f70ecca6ee4c0a8159 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 4 Jan 2023 15:27:33 -0700 Subject: [PATCH] call redraw_everything() when cDialogs move --- src/dialogxml/dialogs/dialog.cpp | 14 +++++++++++++- src/dialogxml/dialogs/dialog.hpp | 3 +++ src/game/boe.main.cpp | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/dialogxml/dialogs/dialog.cpp b/src/dialogxml/dialogs/dialog.cpp index dc324518..544a2649 100644 --- a/src/dialogxml/dialogs/dialog.cpp +++ b/src/dialogxml/dialogs/dialog.cpp @@ -35,6 +35,7 @@ extern sf::Texture bg_gworld; const short cDialog::BG_DARK = 5, cDialog::BG_LIGHT = 16; short cDialog::defaultBackground = cDialog::BG_DARK; cDialog* cDialog::topWindow = nullptr; +void (*cDialog::redraw_everything)() = nullptr; std::string cDialog::generateRandomString(){ // Not bothering to seed, because it doesn't actually matter if it's truly random. @@ -517,7 +518,9 @@ void cDialog::run(std::function onopen){ win.create(sf::VideoMode(1,1),""); win.close(); win.create(sf::VideoMode(winRect.width(), winRect.height()), "Dialog", sf::Style::Titlebar); - win.setPosition({parentPos.x + int(parentSz.x - winRect.width()) / 2, parentPos.y + int(parentSz.y - winRect.height()) / 2}); + winLastX = parentPos.x + int(parentSz.x - winRect.width()) / 2; + winLastY = parentPos.y + int(parentSz.y - winRect.height()) / 2; + win.setPosition({winLastX, winLastY}); draw(); makeFrontWindow(parent ? parent-> win : mainPtr); makeFrontWindow(win); @@ -690,6 +693,15 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) { break; case sf::Event::GainedFocus: case sf::Event::MouseMoved: + // Did the window move, potentially dirtying the canvas below it? + auto winPosition = win.getPosition(); + if (winLastX != winPosition.x || winLastY != winPosition.y) { + if (redraw_everything != NULL) + redraw_everything(); + } + winLastX = winPosition.x; + winLastY = winPosition.y; + bool inField = false; for(auto& ctrl : controls) { if(ctrl.second->getType() == CTRL_FIELD && ctrl.second->getBounds().contains(currentEvent.mouseMove.x, currentEvent.mouseMove.y)) { diff --git a/src/dialogxml/dialogs/dialog.hpp b/src/dialogxml/dialogs/dialog.hpp index 8badb6a6..758df396 100644 --- a/src/dialogxml/dialogs/dialog.hpp +++ b/src/dialogxml/dialogs/dialog.hpp @@ -41,6 +41,8 @@ class cDialog { short bg; sf::Color defTextClr; sf::RenderWindow win; + int winLastX=-1; + int winLastY=-1; std::string currentFocus; cDialog* parent; std::string generateRandomString(); @@ -49,6 +51,7 @@ class cDialog { std::vector> tabOrder; static cDialog* topWindow; // Tracks the frontmost dialog. public: + static void (*redraw_everything)(); /// Performs essential startup initialization. Generally should not be called directly. static void init(); /// The light background pattern used by the scenario editor dialogs. diff --git a/src/game/boe.main.cpp b/src/game/boe.main.cpp index eb25b2ec..27970b2f 100644 --- a/src/game/boe.main.cpp +++ b/src/game/boe.main.cpp @@ -115,6 +115,8 @@ int main(int argc, char* argv[]) { debug_oldstructs(); #endif try{ + cDialog::redraw_everything = &redraw_everything; + init_boe(argc, argv); if(!get_bool_pref("GameRunBefore"))