@@ -24,12 +24,9 @@ namespace {
2424constexpr Extent ButtonSize (16 , 16 );
2525}
2626
27- const DrawPoint IngameWindow::posLastOrCenter (std::numeric_limits<DrawPoint::ElementType>::max(),
28- std::numeric_limits<DrawPoint::ElementType>::max());
29- const DrawPoint IngameWindow::posCenter (std::numeric_limits<DrawPoint::ElementType>::max() - 1,
30- std::numeric_limits<DrawPoint::ElementType>::max());
31- const DrawPoint IngameWindow::posAtMouse (std::numeric_limits<DrawPoint::ElementType>::max() - 1,
32- std::numeric_limits<DrawPoint::ElementType>::max() - 1);
27+ const DrawPoint IngameWindow::posLastOrCenter (DrawPoint::MaxElementValue, DrawPoint::MaxElementValue);
28+ const DrawPoint IngameWindow::posCenter (DrawPoint::MaxElementValue - 1 , DrawPoint::MaxElementValue);
29+ const DrawPoint IngameWindow::posAtMouse (DrawPoint::MaxElementValue - 1 , DrawPoint::MaxElementValue - 1 );
3330
3431const Extent IngameWindow::borderSize (1 , 1 );
3532IngameWindow::IngameWindow (unsigned id, const DrawPoint& pos, const Extent& size, std::string title,
@@ -54,25 +51,32 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5451 // Save to settings that window is open
5552 SaveOpenStatus (true );
5653
57- // Restore minimized state
58- if (windowSettings_ && windowSettings_->isMinimized )
54+ if (windowSettings_)
5955 {
60- isMinimized_ = true ;
61- Extent minimizedSize (GetSize ().x , contentOffset.y + contentOffsetEnd.y );
62- 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 ;
6365 }
6466
6567 // Load last position or center the window
6668 if (pos == posLastOrCenter)
6769 {
6870 if (windowSettings_ && windowSettings_->lastPos .isValid ())
69- SetPos (windowSettings_->lastPos );
71+ SetPos (windowSettings_->lastPos , !restorePos_. isValid () );
7072 else
7173 MoveToCenter ();
7274 } else if (pos == posCenter)
7375 MoveToCenter ();
7476 else if (pos == posAtMouse)
7577 MoveNextToMouse ();
78+ else
79+ SetPos (pos); // always call SetPos() to update restorePos
7680}
7781
7882void IngameWindow::Resize (const Extent& newSize)
@@ -84,15 +88,23 @@ void IngameWindow::Resize(const Extent& newSize)
8488
8589void IngameWindow::SetIwSize (const Extent& newSize)
8690{
91+ // Is the window connecting with the bottom screen edge?
92+ const auto atBottom = (GetPos ().y + GetSize ().y ) >= VIDEODRIVER.GetRenderSize ().y ;
93+
8794 iwHeight = newSize.y ;
8895 Extent wndSize = newSize;
8996 if (isMinimized_)
9097 wndSize.y = 0 ;
9198 wndSize += contentOffset + contentOffsetEnd;
9299 Window::Resize (wndSize);
93100
94- // Reset the position to check if parts of the window are out of the visible area
95- 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 );
96108}
97109
98110Extent IngameWindow::GetIwSize () const
@@ -105,24 +117,38 @@ DrawPoint IngameWindow::GetRightBottomBoundary()
105117 return DrawPoint (GetSize () - contentOffsetEnd);
106118}
107119
108- void IngameWindow::SetPos (DrawPoint newPos)
120+ void IngameWindow::SetPos (DrawPoint newPos, bool saveRestorePos )
109121{
110122 const Extent screenSize = VIDEODRIVER.GetRenderSize ();
123+ DrawPoint newRestorePos = newPos;
111124 // Too far left or right?
112125 if (newPos.x < 0 )
113- newPos.x = 0 ;
114- else if (newPos.x + GetSize ().x > screenSize.x )
126+ newRestorePos.x = newPos.x = 0 ;
127+ else if (newPos.x + GetSize ().x >= screenSize.x )
128+ {
115129 newPos.x = screenSize.x - GetSize ().x ;
130+ newRestorePos.x = DrawPoint::MaxElementValue; // make window stick to the right
131+ }
116132
117133 // Too high or low?
118134 if (newPos.y < 0 )
119- newPos.y = 0 ;
120- else if (newPos.y + GetSize ().y > screenSize.y )
135+ newRestorePos.y = newPos.y = 0 ;
136+ else if (newPos.y + GetSize ().y >= screenSize.y )
137+ {
121138 newPos.y = screenSize.y - GetSize ().y ;
139+ newRestorePos.y = DrawPoint::MaxElementValue; // make window stick to the bottom
140+ }
122141
123- // if possible save the position to settings
142+ if (saveRestorePos)
143+ restorePos_ = newRestorePos;
144+
145+ // if possible save the positions to settings
124146 if (windowSettings_)
147+ {
125148 windowSettings_->lastPos = newPos;
149+ if (saveRestorePos)
150+ windowSettings_->restorePos = newRestorePos;
151+ }
126152
127153 Window::SetPos (newPos);
128154}
0 commit comments