2222
2323namespace {
2424constexpr Extent ButtonSize (16 , 16 );
25- }
25+ constexpr unsigned TitleMargin = 32 ;
26+ } // namespace
2627
2728const DrawPoint IngameWindow::posLastOrCenter (DrawPoint::MaxElementValue, DrawPoint::MaxElementValue);
2829const DrawPoint IngameWindow::posCenter (DrawPoint::MaxElementValue - 1 , DrawPoint::MaxElementValue);
@@ -32,7 +33,8 @@ const Extent IngameWindow::borderSize(1, 1);
3233IngameWindow::IngameWindow (unsigned id, const DrawPoint& pos, const Extent& size, std::string title,
3334 glArchivItem_Bitmap* background, bool modal, CloseBehavior closeBehavior, Window* parent)
3435 : Window(parent, id, pos, size), title_(std::move(title)), background(background), lastMousePos(0 , 0 ),
35- isModal_(modal), closeme(false ), isMinimized_(false ), isMoving(false ), closeBehavior_(closeBehavior)
36+ isModal_(modal), closeme(false ), isPinned_(false ), isMinimized_(false ), isMoving(false ),
37+ closeBehavior_(closeBehavior)
3638{
3739 std::fill (buttonStates_.begin (), buttonStates_.end (), ButtonState::Up);
3840 contentOffset.x = LOADER .GetImageN (" resource" , 38 )->getWidth (); // left border
@@ -211,17 +213,32 @@ void IngameWindow::MouseLeftUp(const MouseCoords& mc)
211213 buttonStates_[btn] = ButtonState::Up;
212214
213215 if ((btn == IwButton::Close && closeBehavior_ == CloseBehavior::Custom) // no close button
214- || (btn == IwButton::Minimize && isModal_)) // modal windows cannot be minimized
216+ || (isModal_ // modal windows cannot be pinned or minimized
217+ && (btn == IwButton::Title || btn == IwButton::PinOrMinimize)))
215218 continue ;
216219
217220 if (IsPointInRect (mc.GetPos (), GetButtonBounds (btn)))
218221 {
219222 switch (btn)
220223 {
221224 case IwButton::Close: Close (); break ;
222- case IwButton::Minimize:
223- SetMinimized (!IsMinimized ());
224- LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
225+ case IwButton::Title:
226+ if (SETTINGS .interface .enableWindowPinning && mc.dbl_click )
227+ {
228+ SetMinimized (!IsMinimized ());
229+ LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
230+ }
231+ break ;
232+ case IwButton::PinOrMinimize:
233+ if (SETTINGS .interface .enableWindowPinning )
234+ {
235+ SetPinned (!IsPinned ());
236+ LOADER .GetSoundN (" sound" , 111 )->Play (255 , false );
237+ } else
238+ {
239+ SetMinimized (!IsMinimized ());
240+ LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
241+ }
225242 break ;
226243 }
227244 }
@@ -294,11 +311,27 @@ void IngameWindow::Draw_()
294311 using ButtonStateResIds = helpers::EnumArray<unsigned , ButtonState>;
295312 constexpr ButtonStateResIds closeResIds = {47 , 55 , 51 };
296313 constexpr ButtonStateResIds minimizeResIds = {48 , 56 , 52 };
314+ constexpr ButtonStateResIds pinBaseResIds = {47 , 47 , 51 };
315+ constexpr auto overlayIdsStart = 15u ;
316+ constexpr ButtonStateResIds pinOverlayResIdsRel = {0 , 1 , 2 };
317+ constexpr ButtonStateResIds unpinOverlayResIdsRel = {3 , 4 , 5 };
297318 if (closeBehavior_ != CloseBehavior::Custom)
298- LOADER .GetImageN (" resource" , closeResIds[buttonStates_[IwButton::Close]])->DrawFull (GetPos ());
319+ LOADER .GetImageN (" resource" , closeResIds[buttonStates_[IwButton::Close]])
320+ ->DrawFull (GetButtonBounds (IwButton::Close));
299321 if (!IsModal ())
300- LOADER .GetImageN (" resource" , minimizeResIds[buttonStates_[IwButton::Minimize]])
301- ->DrawFull (GetButtonBounds (IwButton::Minimize));
322+ {
323+ const auto buttonState = buttonStates_[IwButton::PinOrMinimize];
324+ const auto bounds = GetButtonBounds (IwButton::PinOrMinimize);
325+ if (SETTINGS .interface .enableWindowPinning )
326+ {
327+ LOADER .GetImageN (" resource" , pinBaseResIds[buttonState])->DrawFull (bounds);
328+ if (isPinned_)
329+ LOADER .GetImageN (" io_new" , unpinOverlayResIdsRel[buttonState] + overlayIdsStart)->DrawFull (bounds);
330+ else
331+ LOADER .GetImageN (" io_new" , pinOverlayResIdsRel[buttonState] + overlayIdsStart)->DrawFull (bounds);
332+ } else
333+ LOADER .GetImageN (" resource" , minimizeResIds[buttonState])->DrawFull (bounds);
334+ }
302335
303336 // The title bar
304337 unsigned titleIndex;
@@ -410,10 +443,15 @@ void IngameWindow::SaveOpenStatus(bool isOpen) const
410443Rect IngameWindow::GetButtonBounds (IwButton btn) const
411444{
412445 auto pos = GetPos ();
446+ auto size = ButtonSize;
413447 switch (btn)
414448 {
415449 case IwButton::Close: break ;
416- case IwButton::Minimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
450+ case IwButton::Title:
451+ pos.x += TitleMargin;
452+ size.x = GetSize ().x - TitleMargin * 2 ;
453+ break ;
454+ case IwButton::PinOrMinimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
417455 }
418- return Rect (pos, ButtonSize );
456+ return Rect (pos, size );
419457}
0 commit comments