Skip to content

Commit 5ed5468

Browse files
Look up PersistentWindowSettings only once
1 parent c0d0f8a commit 5ed5468

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
3939
contentOffsetEnd.x = LOADER.GetImageN("resource", 39)->getWidth(); // right border
4040
contentOffsetEnd.y = LOADER.GetImageN("resource", 40)->getHeight(); // bottom bar
4141

42+
const auto it = SETTINGS.windows.persistentSettings.find(GetGUIID());
43+
windowSettings_ = (it == SETTINGS.windows.persistentSettings.cend() ? nullptr : &it->second);
44+
4245
// For compatibility we treat the given height as the window height, not the content height
4346
// First we have to make sure the size is not to small
4447
Window::Resize(elMax(contentOffset + contentOffsetEnd, GetSize()));
@@ -50,9 +53,8 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5053
// Load last position or center the window
5154
if(pos == posLastOrCenter)
5255
{
53-
const auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
54-
if(windowSettings != SETTINGS.windows.persistentSettings.cend() && windowSettings->second.lastPos.isValid())
55-
SetPos(windowSettings->second.lastPos);
56+
if(windowSettings_ && windowSettings_->lastPos.isValid())
57+
SetPos(windowSettings_->lastPos);
5658
else
5759
MoveToCenter();
5860
} else if(pos == posCenter)
@@ -107,11 +109,8 @@ void IngameWindow::SetPos(DrawPoint newPos)
107109
newPos.y = screenSize.y - GetSize().y;
108110

109111
// if possible save the position to settings
110-
const auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
111-
if(windowSettings != SETTINGS.windows.persistentSettings.cend())
112-
{
113-
windowSettings->second.lastPos = newPos;
114-
}
112+
if(windowSettings_)
113+
windowSettings_->lastPos = newPos;
115114

116115
Window::SetPos(newPos);
117116
}
@@ -371,9 +370,6 @@ Rect IngameWindow::GetMinimizeButtonBounds() const
371370

372371
void IngameWindow::SaveOpenStatus(bool isOpen) const
373372
{
374-
auto windowSettings = SETTINGS.windows.persistentSettings.find(GetGUIID());
375-
if(windowSettings != SETTINGS.windows.persistentSettings.cend())
376-
{
377-
windowSettings->second.isOpen = isOpen;
378-
}
373+
if(windowSettings_)
374+
windowSettings_->isOpen = isOpen;
379375
}

libs/s25main/ingameWindows/IngameWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class glArchivItem_Bitmap;
1313
class MouseCoords;
14+
struct PersistentWindowSettings;
1415
template<typename T>
1516
struct Point;
1617

@@ -119,4 +120,5 @@ class IngameWindow : public Window
119120
bool isMinimized_;
120121
bool isMoving;
121122
CloseBehavior closeBehavior_;
123+
PersistentWindowSettings* windowSettings_;
122124
};

0 commit comments

Comments
 (0)