MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / statePositioningWindow

Function statePositioningWindow

src/OpenLoco/src/Input/MouseInput.cpp:825–891  ·  view source on GitHub ↗

0x004C7903

Source from the content-addressed store, hash-verified

823
824 // 0x004C7903
825 static void statePositioningWindow(MouseButton button, int32_t x, int32_t y, [[maybe_unused]] Ui::Window* window, [[maybe_unused]] Ui::Widget* widget, [[maybe_unused]] Ui::WidgetIndex_t widgetIndex)
826 {
827 auto w = WindowManager::find(_dragWindowType, _dragWindowNumber);
828 if (w == nullptr)
829 {
830 state(State::reset);
831 return;
832 }
833
834 switch (button)
835 {
836 case MouseButton::released:
837 {
838 y = std::clamp(y, 29, Ui::height() - 29);
839
840 auto dx = x - _dragLast.x;
841 auto dy = y - _dragLast.y;
842
843 if (w->move(dx, dy))
844 {
845 _windowMoved = true;
846 }
847
848 _dragLast.x = x;
849 _dragLast.y = y;
850 break;
851 }
852
853 case MouseButton::leftReleased:
854 {
855 windowPositionEnd();
856
857 y = std::clamp(y, 29, Ui::height() - 29);
858
859 int dx = x - _dragLast.x;
860 int dy = y - _dragLast.y;
861 if (w->move(dx, dy))
862 {
863 _windowMoved = true;
864 }
865
866 _dragLast.x = x;
867 _dragLast.y = y;
868
869 if (_windowMoved == false)
870 {
871 auto dragWindow = WindowManager::find(_dragWindowType, _dragWindowNumber);
872 if (dragWindow != nullptr)
873 {
874 if (dragWindow->isEnabled(_pressedWidgetIndex))
875 {
876 auto pressedWidget = &dragWindow->widgets[_pressedWidgetIndex];
877
878 Audio::playSound(Audio::SoundId::clickPress, Audio::ChannelId::ui, dragWindow->x + pressedWidget->midX());
879 dragWindow->callOnMouseUp(_pressedWidgetIndex, pressedWidget->id);
880 }
881 }
882 }

Callers 1

handleMouseFunction · 0.85

Calls 10

findFunction · 0.85
heightFunction · 0.85
windowPositionEndFunction · 0.85
playSoundFunction · 0.85
moveMethod · 0.80
isEnabledMethod · 0.80
midXMethod · 0.80
callOnMouseUpMethod · 0.80
callOnMoveMethod · 0.80
stateFunction · 0.50

Tested by

no test coverage detected