@@ -51,25 +51,32 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5151 // Save to settings that window is open
5252 SaveOpenStatus (true );
5353
54- // Restore minimized state
55- if (windowSettings_ && windowSettings_->isMinimized )
54+ if (windowSettings_)
5655 {
57- isMinimized_ = true ;
58- Extent minimizedSize (GetSize ().x , contentOffset.y + contentOffsetEnd.y );
59- Window::Resize (minimizedSize);
56+ // Restore minimized state
57+ if (windowSettings_ && windowSettings_->isMinimized )
58+ {
59+ isMinimized_ = true ;
60+ Extent minimizedSize (GetSize ().x , contentOffset.y + contentOffsetEnd.y );
61+ Window::Resize (minimizedSize);
62+ }
63+ // Load restorePos
64+ restorePos_ = windowSettings_->restorePos ;
6065 }
6166
6267 // Load last position or center the window
6368 if (pos == posLastOrCenter)
6469 {
6570 if (windowSettings_ && windowSettings_->lastPos .isValid ())
66- SetPos (windowSettings_->lastPos );
71+ SetPos (windowSettings_->lastPos , !restorePos_. isValid () );
6772 else
6873 MoveToCenter ();
6974 } else if (pos == posCenter)
7075 MoveToCenter ();
7176 else if (pos == posAtMouse)
7277 MoveNextToMouse ();
78+ else
79+ SetPos (pos); // always call SetPos() to update restorePos
7380}
7481
7582void IngameWindow::Resize (const Extent& newSize)
@@ -81,15 +88,23 @@ void IngameWindow::Resize(const Extent& newSize)
8188
8289void IngameWindow::SetIwSize (const Extent& newSize)
8390{
91+ // Is the window connecting with the bottom screen edge?
92+ const auto atBottom = (GetPos ().y + GetSize ().y ) >= VIDEODRIVER.GetRenderSize ().y ;
93+
8494 iwHeight = newSize.y ;
8595 Extent wndSize = newSize;
8696 if (isMinimized_)
8797 wndSize.y = 0 ;
8898 wndSize += contentOffset + contentOffsetEnd;
8999 Window::Resize (wndSize);
90100
91- // Reset the position to check if parts of the window are out of the visible area
92- SetPos (GetPos ());
101+ // Adjust restorePos if the window was connecting with the bottom screen edge before being minimized
102+ const auto pos = (atBottom && isMinimized_) ? DrawPoint (restorePos_.x , DrawPoint::MaxElementValue) : restorePos_;
103+
104+ // Reset the position
105+ // 1) to check if parts of the window are out of the visible area
106+ // 2) to re-connect the window with the bottom screen edge, if needed
107+ SetPos (pos, false );
93108}
94109
95110Extent IngameWindow::GetIwSize () const
@@ -102,24 +117,38 @@ DrawPoint IngameWindow::GetRightBottomBoundary()
102117 return DrawPoint (GetSize () - contentOffsetEnd);
103118}
104119
105- void IngameWindow::SetPos (DrawPoint newPos)
120+ void IngameWindow::SetPos (DrawPoint newPos, bool saveRestorePos )
106121{
107122 const Extent screenSize = VIDEODRIVER.GetRenderSize ();
123+ DrawPoint newRestorePos = newPos;
108124 // Too far left or right?
109125 if (newPos.x < 0 )
110- newPos.x = 0 ;
111- else if (newPos.x + GetSize ().x > screenSize.x )
126+ newRestorePos.x = newPos.x = 0 ;
127+ else if (newPos.x + GetSize ().x >= screenSize.x )
128+ {
112129 newPos.x = screenSize.x - GetSize ().x ;
130+ newRestorePos.x = DrawPoint::MaxElementValue; // make window stick to the right
131+ }
113132
114133 // Too high or low?
115134 if (newPos.y < 0 )
116- newPos.y = 0 ;
117- else if (newPos.y + GetSize ().y > screenSize.y )
135+ newRestorePos.y = newPos.y = 0 ;
136+ else if (newPos.y + GetSize ().y >= screenSize.y )
137+ {
118138 newPos.y = screenSize.y - GetSize ().y ;
139+ newRestorePos.y = DrawPoint::MaxElementValue; // make window stick to the bottom
140+ }
119141
120- // if possible save the position to settings
142+ if (saveRestorePos)
143+ restorePos_ = newRestorePos;
144+
145+ // if possible save the positions to settings
121146 if (windowSettings_)
147+ {
122148 windowSettings_->lastPos = newPos;
149+ if (saveRestorePos)
150+ windowSettings_->restorePos = newRestorePos;
151+ }
123152
124153 Window::SetPos (newPos);
125154}
0 commit comments