2222
2323namespace {
2424constexpr Extent ButtonSize (16 , 16 );
25- }
25+ constexpr unsigned TitleMargin = 32 ;
26+ } // namespace
2627
2728const DrawPoint IngameWindow::posLastOrCenter (std::numeric_limits<DrawPoint::ElementType>::max(),
2829 std::numeric_limits<DrawPoint::ElementType>::max());
@@ -35,7 +36,8 @@ const Extent IngameWindow::borderSize(1, 1);
3536IngameWindow::IngameWindow (unsigned id, const DrawPoint& pos, const Extent& size, std::string title,
3637 glArchivItem_Bitmap* background, bool modal, CloseBehavior closeBehavior, Window* parent)
3738 : Window(parent, id, pos, size), title_(std::move(title)), background(background), lastMousePos(0 , 0 ),
38- isModal_(modal), closeme(false ), isMinimized_(false ), isMoving(false ), closeBehavior_(closeBehavior)
39+ isModal_(modal), closeme(false ), isPinned_(false ), isMinimized_(false ), isMoving(false ),
40+ closeBehavior_(closeBehavior)
3941{
4042 std::fill (buttonStates_.begin (), buttonStates_.end (), ButtonState::Up);
4143 contentOffset.x = LOADER .GetImageN (" resource" , 38 )->getWidth (); // left border
@@ -180,17 +182,32 @@ void IngameWindow::MouseLeftUp(const MouseCoords& mc)
180182 buttonStates_[btn] = ButtonState::Up;
181183
182184 if ((btn == IwButton::Close && closeBehavior_ == CloseBehavior::Custom) // no close button
183- || (btn == IwButton::Minimize && isModal_)) // modal windows cannot be minimized
185+ || (isModal_ // modal windows cannot be pinned or minimized
186+ && (btn == IwButton::Title || btn == IwButton::PinOrMinimize)))
184187 continue ;
185188
186189 if (IsPointInRect (mc.GetPos (), GetButtonBounds (btn)))
187190 {
188191 switch (btn)
189192 {
190193 case IwButton::Close: Close (); break ;
191- case IwButton::Minimize:
192- SetMinimized (!IsMinimized ());
193- LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
194+ case IwButton::Title:
195+ if (SETTINGS .interface .enableWindowPinning && mc.dbl_click )
196+ {
197+ SetMinimized (!IsMinimized ());
198+ LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
199+ }
200+ break ;
201+ case IwButton::PinOrMinimize:
202+ if (SETTINGS .interface .enableWindowPinning )
203+ {
204+ SetPinned (!IsPinned ());
205+ LOADER .GetSoundN (" sound" , 111 )->Play (255 , false );
206+ } else
207+ {
208+ SetMinimized (!IsMinimized ());
209+ LOADER .GetSoundN (" sound" , 113 )->Play (255 , false );
210+ }
194211 break ;
195212 }
196213 }
@@ -263,11 +280,27 @@ void IngameWindow::Draw_()
263280 using ButtonStateResIds = helpers::EnumArray<unsigned , ButtonState>;
264281 constexpr ButtonStateResIds closeResIds = {47 , 55 , 51 };
265282 constexpr ButtonStateResIds minimizeResIds = {48 , 56 , 52 };
283+ constexpr ButtonStateResIds pinBaseResIds = {47 , 47 , 51 };
284+ constexpr auto overlayIdsStart = 15u ;
285+ constexpr ButtonStateResIds pinOverlayResIdsRel = {0 , 1 , 2 };
286+ constexpr ButtonStateResIds unpinOverlayResIdsRel = {3 , 4 , 5 };
266287 if (closeBehavior_ != CloseBehavior::Custom)
267- LOADER .GetImageN (" resource" , closeResIds[buttonStates_[IwButton::Close]])->DrawFull (GetPos ());
288+ LOADER .GetImageN (" resource" , closeResIds[buttonStates_[IwButton::Close]])
289+ ->DrawFull (GetButtonBounds (IwButton::Close));
268290 if (!IsModal ())
269- LOADER .GetImageN (" resource" , minimizeResIds[buttonStates_[IwButton::Minimize]])
270- ->DrawFull (GetButtonBounds (IwButton::Minimize));
291+ {
292+ const auto buttonState = buttonStates_[IwButton::PinOrMinimize];
293+ const auto bounds = GetButtonBounds (IwButton::PinOrMinimize);
294+ if (SETTINGS .interface .enableWindowPinning )
295+ {
296+ LOADER .GetImageN (" resource" , pinBaseResIds[buttonState])->DrawFull (bounds);
297+ if (isPinned_)
298+ LOADER .GetImageN (" io_new" , unpinOverlayResIdsRel[buttonState] + overlayIdsStart)->DrawFull (bounds);
299+ else
300+ LOADER .GetImageN (" io_new" , pinOverlayResIdsRel[buttonState] + overlayIdsStart)->DrawFull (bounds);
301+ } else
302+ LOADER .GetImageN (" resource" , minimizeResIds[buttonState])->DrawFull (bounds);
303+ }
271304
272305 // The title bar
273306 unsigned titleIndex;
@@ -379,10 +412,15 @@ void IngameWindow::SaveOpenStatus(bool isOpen) const
379412Rect IngameWindow::GetButtonBounds (IwButton btn) const
380413{
381414 auto pos = GetPos ();
415+ auto size = ButtonSize;
382416 switch (btn)
383417 {
384418 case IwButton::Close: break ;
385- case IwButton::Minimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
419+ case IwButton::Title:
420+ pos.x += TitleMargin;
421+ size.x = GetSize ().x - TitleMargin * 2 ;
422+ break ;
423+ case IwButton::PinOrMinimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
386424 }
387- return Rect (pos, ButtonSize );
425+ return Rect (pos, size );
388426}
0 commit comments