@@ -34,8 +34,8 @@ constexpr Extent IngameWindow::ButtonSize;
3434IngameWindow::IngameWindow (unsigned id, const DrawPoint& pos, const Extent& size, std::string title,
3535 glArchivItem_Bitmap* background, bool modal, CloseBehavior closeBehavior, Window* parent)
3636 : Window(parent, id, pos, size), title_(std::move(title)), background(background), lastMousePos(0 , 0 ),
37- isModal_(modal), closeme(false ), isMinimized_ (false ), isMoving (false ), closeBehavior_(closeBehavior ),
38- buttonStates_({ButtonState::Up, ButtonState::Up})
37+ isModal_(modal), closeme(false ), isPinned_ (false ), isMinimized_ (false ), isMoving( false ),
38+ closeBehavior_(closeBehavior), buttonStates_({ButtonState::Up, ButtonState::Up, ButtonState::Up})
3939{
4040 contentOffset.x = LOADER.GetImageN (" resource" , 38 )->getWidth (); // left border
4141 contentOffset.y = LOADER.GetImageN (" resource" , 42 )->getHeight (); // title bar
@@ -168,14 +168,31 @@ void IngameWindow::MouseLeftUp(const MouseCoords& mc)
168168 buttonStates_[id] = ButtonState::Up;
169169
170170 if ((id == IwButtonId::Close && closeBehavior_ == CloseBehavior::Custom) // no close button
171- || (id != IwButtonId::Close && isModal_)) // modal windows cannot be minimized
171+ || (id != IwButtonId::Close && isModal_)) // modal windows cannot be pinned or minimized
172+ continue ;
173+
174+ if (IsPointInRect (mc.GetPos (), GetButtonBounds (id)))
172175 {
173176 switch (id)
174177 {
175178 case IwButtonId::Close: Close (); break ;
176- case IwButtonId::Minimize:
177- SetMinimized (!IsMinimized ());
178- LOADER.GetSoundN (" sound" , 113 )->Play (255 , false );
179+ case IwButtonId::Title:
180+ if (SETTINGS.interface .enableWindowPinning && mc.dbl_click )
181+ {
182+ SetMinimized (!IsMinimized ());
183+ LOADER.GetSoundN (" sound" , 113 )->Play (255 , false );
184+ }
185+ break ;
186+ case IwButtonId::PinOrMinimize:
187+ if (SETTINGS.interface .enableWindowPinning )
188+ {
189+ SetPinned (!IsPinned ());
190+ LOADER.GetSoundN (" sound" , 111 )->Play (255 , false );
191+ } else
192+ {
193+ SetMinimized (!IsMinimized ());
194+ LOADER.GetSoundN (" sound" , 113 )->Play (255 , false );
195+ }
179196 break ;
180197 }
181198 }
@@ -248,11 +265,25 @@ void IngameWindow::Draw_()
248265 using ButtonStateResIds = helpers::EnumArray<uint16_t , ButtonState>;
249266 constexpr ButtonStateResIds closeButtonResIds = {47 , 55 , 51 };
250267 constexpr ButtonStateResIds minimizeButtonResIds = {48 , 56 , 52 };
268+ constexpr ButtonStateResIds pinButtonBaseResIds = {47 , 47 , 51 };
269+ constexpr ButtonStateResIds pinButtonOverlayResIds = {0 , 1 , 2 };
270+ constexpr ButtonStateResIds unpinButtonOverlayResIds = {3 , 4 , 5 };
251271 if (closeBehavior_ != CloseBehavior::Custom)
252272 LOADER.GetImageN (" resource" , closeButtonResIds[buttonStates_[IwButtonId::Close]])->DrawFull (GetPos ());
253273 if (!IsModal ())
254- LOADER.GetImageN (" resource" , minimizeButtonResIds[buttonStates_[IwButtonId::Minimize]])
255- ->DrawFull (GetButtonBounds (IwButtonId::Minimize));
274+ {
275+ const auto buttonState = buttonStates_[IwButtonId::PinOrMinimize];
276+ const auto bounds = GetButtonBounds (IwButtonId::PinOrMinimize);
277+ if (SETTINGS.interface .enableWindowPinning )
278+ {
279+ LOADER.GetImageN (" resource" , pinButtonBaseResIds[buttonState])->DrawFull (bounds);
280+ if (isPinned_)
281+ LOADER.GetImageN (" resource_new" , unpinButtonOverlayResIds[buttonState])->DrawFull (bounds);
282+ else
283+ LOADER.GetImageN (" resource_new" , pinButtonOverlayResIds[buttonState])->DrawFull (bounds);
284+ } else
285+ LOADER.GetImageN (" resource" , minimizeButtonResIds[buttonState])->DrawFull (bounds);
286+ }
256287
257288 // The title bar
258289 unsigned titleIndex;
@@ -367,10 +398,15 @@ void IngameWindow::SaveOpenStatus(bool isOpen) const
367398Rect IngameWindow::GetButtonBounds (IwButtonId id) const
368399{
369400 auto pos = GetPos ();
401+ auto size = ButtonSize;
370402 switch (id)
371403 {
372404 case IwButtonId::Close: break ;
373- case IwButtonId::Minimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
405+ case IwButtonId::Title:
406+ pos.x += TitleMargin;
407+ size.x = GetSize ().x - TitleMargin * 2 ;
408+ break ;
409+ case IwButtonId::PinOrMinimize: pos.x += GetSize ().x - ButtonSize.x ; break ;
374410 }
375- return Rect (pos, ButtonSize );
411+ return Rect (pos, size );
376412}
0 commit comments