Skip to content

Commit

Permalink
Persist window pinned state
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Jul 27, 2023
1 parent 4866603 commit c1faa91
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions libs/s25main/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ void Settings::LoadIngame()
settings.restorePos = DrawPoint(iniWindow->getValue("restore_pos_x", lastPos.x),
iniWindow->getValue("restore_pos_y", lastPos.y));
settings.isOpen = iniWindow->getIntValue("is_open");
settings.isPinned = iniWindow->getValue("is_pinned", false);
settings.isMinimized = iniWindow->getValue("is_minimized", false);
}
} catch(std::runtime_error& e)
Expand Down Expand Up @@ -516,6 +517,7 @@ void Settings::SaveIngame()
iniWindow->setValue("restore_pos_y", settings.restorePos.y);
}
iniWindow->setValue("is_open", settings.isOpen);
iniWindow->setValue("is_pinned", settings.isPinned);
iniWindow->setValue("is_minimized", settings.isMinimized);
}

Expand Down
1 change: 1 addition & 0 deletions libs/s25main/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct PersistentWindowSettings
DrawPoint lastPos = DrawPoint::Invalid();
DrawPoint restorePos = DrawPoint::Invalid();
bool isOpen = false;
bool isPinned = false;
bool isMinimized = false;
};

Expand Down
15 changes: 12 additions & 3 deletions libs/s25main/ingameWindows/IngameWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
if(windowSettings_)
{
// Restore minimized state
if(windowSettings_ && windowSettings_->isMinimized)
if(windowSettings_->isMinimized)
{
isMinimized_ = true;
Extent minimizedSize(GetSize().x, contentOffset.y + contentOffsetEnd.y);
Window::Resize(minimizedSize);
}
// Load restorePos
restorePos_ = windowSettings_->restorePos;
isPinned_ = windowSettings_->isPinned; // Restore pinned state
restorePos_ = windowSettings_->restorePos; // Load restorePos
}

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

void IngameWindow::SetPinned(bool pinned)
{
isPinned_ = pinned;

// if possible save the pinned state to settings
if(windowSettings_)
windowSettings_->isPinned = isPinned_;
}

void IngameWindow::MouseLeftDown(const MouseCoords& mc)
{
// Maus muss sich auf der Titelleiste befinden
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/ingameWindows/IngameWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class IngameWindow : public Window
/// ist das Fenster minimiert?
bool IsMinimized() const { return isMinimized_; }

void SetPinned(bool pinned = true) { isPinned_ = pinned; }
void SetPinned(bool pinned = true);
bool IsPinned() const { return isPinned_; }

CloseBehavior getCloseBehavior() const { return closeBehavior_; }
Expand Down

0 comments on commit c1faa91

Please sign in to comment.