Skip to content

Commit c1faa91

Browse files
Persist window pinned state
1 parent 4866603 commit c1faa91

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

libs/s25main/Settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ void Settings::LoadIngame()
355355
settings.restorePos = DrawPoint(iniWindow->getValue("restore_pos_x", lastPos.x),
356356
iniWindow->getValue("restore_pos_y", lastPos.y));
357357
settings.isOpen = iniWindow->getIntValue("is_open");
358+
settings.isPinned = iniWindow->getValue("is_pinned", false);
358359
settings.isMinimized = iniWindow->getValue("is_minimized", false);
359360
}
360361
} catch(std::runtime_error& e)
@@ -516,6 +517,7 @@ void Settings::SaveIngame()
516517
iniWindow->setValue("restore_pos_y", settings.restorePos.y);
517518
}
518519
iniWindow->setValue("is_open", settings.isOpen);
520+
iniWindow->setValue("is_pinned", settings.isPinned);
519521
iniWindow->setValue("is_minimized", settings.isMinimized);
520522
}
521523

libs/s25main/Settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct PersistentWindowSettings
2727
DrawPoint lastPos = DrawPoint::Invalid();
2828
DrawPoint restorePos = DrawPoint::Invalid();
2929
bool isOpen = false;
30+
bool isPinned = false;
3031
bool isMinimized = false;
3132
};
3233

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5656
if(windowSettings_)
5757
{
5858
// Restore minimized state
59-
if(windowSettings_ && windowSettings_->isMinimized)
59+
if(windowSettings_->isMinimized)
6060
{
6161
isMinimized_ = true;
6262
Extent minimizedSize(GetSize().x, contentOffset.y + contentOffsetEnd.y);
6363
Window::Resize(minimizedSize);
6464
}
65-
// Load restorePos
66-
restorePos_ = windowSettings_->restorePos;
65+
isPinned_ = windowSettings_->isPinned; // Restore pinned state
66+
restorePos_ = windowSettings_->restorePos; // Load restorePos
6767
}
6868

6969
// Load last position or center the window
@@ -179,6 +179,15 @@ void IngameWindow::SetMinimized(bool minimized)
179179
windowSettings_->isMinimized = isMinimized_;
180180
}
181181

182+
void IngameWindow::SetPinned(bool pinned)
183+
{
184+
isPinned_ = pinned;
185+
186+
// if possible save the pinned state to settings
187+
if(windowSettings_)
188+
windowSettings_->isPinned = isPinned_;
189+
}
190+
182191
void IngameWindow::MouseLeftDown(const MouseCoords& mc)
183192
{
184193
// Maus muss sich auf der Titelleiste befinden

libs/s25main/ingameWindows/IngameWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class IngameWindow : public Window
8787
/// ist das Fenster minimiert?
8888
bool IsMinimized() const { return isMinimized_; }
8989

90-
void SetPinned(bool pinned = true) { isPinned_ = pinned; }
90+
void SetPinned(bool pinned = true);
9191
bool IsPinned() const { return isPinned_; }
9292

9393
CloseBehavior getCloseBehavior() const { return closeBehavior_; }

0 commit comments

Comments
 (0)