From 623f0137ab1e1f812331c7baea34e4d2e754519d Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 6 Aug 2023 00:33:45 -0500 Subject: [PATCH] Use correct layer ordering when refocusing windows. Focused window gets an internal refresh event. --- FiestaOnlineEditor/FiestaOnlineEditor.cpp | 10 ++++++++-- FiestaOnlineEditor/Window.cpp | 5 +++-- FiestaOnlineEditor/Window.h | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/FiestaOnlineEditor/FiestaOnlineEditor.cpp b/FiestaOnlineEditor/FiestaOnlineEditor.cpp index e645d31..a98f3f9 100644 --- a/FiestaOnlineEditor/FiestaOnlineEditor.cpp +++ b/FiestaOnlineEditor/FiestaOnlineEditor.cpp @@ -168,10 +168,15 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){ if(!menuOpened){ if(!internalMouseFocus){ - for(Window*w:windows){ //A second iteration through the windows because windows without focus should only have priority after a window with focus. + for(auto it=windows.begin();it!=windows.end();++it){ //A second iteration through the windows because windows without focus should only have priority after a window with focus. + Window*w=*it; if(!w->IsFocusedWindow()){ if(w->IsInBounds(GetMousePos())){ w->InternalMouseFocus(this); + if(w->IsFocusedWindow()){//The focused window has changed! + windows.push_back(w);//HACK ALERT! Whenever we are iterating through the windows list we could potentially add an item to the end of it whenever it becomes focused to keep layering. Because of this we don't want to reallocate during another push_back. This ensures that will never occur. + it=windows.erase(it); + } w->MouseFocus(this); } } @@ -194,7 +199,7 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){ }); if(focusErased&&windows.size()>0){ - Window::SetFocusedWindow(windows[0]); + Window::SetFocusedWindow(this,windows.back()); } SetDrawTarget(nullptr); @@ -210,6 +215,7 @@ void FiestaOnlineEditor::CreateWindow(Window*window){ } window->InternalRefresh(this); windows.push_back(window); + windows.reserve(windows.size()+1);//HACK ALERT! Whenever we are iterating through the windows list we could potentially add an item to the end of it whenever it becomes focused to keep layering. Because of this we don't want to reallocate during another push_back. This ensures that will never occur. } int main() diff --git a/FiestaOnlineEditor/Window.cpp b/FiestaOnlineEditor/Window.cpp index 566274a..a430f05 100644 --- a/FiestaOnlineEditor/Window.cpp +++ b/FiestaOnlineEditor/Window.cpp @@ -118,6 +118,7 @@ bool Window::IsClosed(){ return closed; } -void Window::SetFocusedWindow(Window*w){ - focusedWindow=w; +void Window::SetFocusedWindow(FiestaOnlineEditor*pge,Window*w){ + focusedWindow=w; + w->InternalRefresh(pge); } \ No newline at end of file diff --git a/FiestaOnlineEditor/Window.h b/FiestaOnlineEditor/Window.h index c2b736c..2493ec9 100644 --- a/FiestaOnlineEditor/Window.h +++ b/FiestaOnlineEditor/Window.h @@ -26,7 +26,7 @@ public: void InternalRefresh(FiestaOnlineEditor*pge); void Draw(FiestaOnlineEditor*pge); bool IsFocusedWindow(); - static void SetFocusedWindow(Window*w); + static void SetFocusedWindow(FiestaOnlineEditor*pge,Window*w); void Cleanup(); bool IsInBounds(vf2d point); void InternalMouseFocus(FiestaOnlineEditor*pge);