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

Function handleMouse

src/OpenLoco/src/Input/MouseInput.cpp:327–414  ·  view source on GitHub ↗

0x004C7174

Source from the content-addressed store, hash-verified

325
326 // 0x004C7174
327 void handleMouse(int32_t x, int32_t y, MouseButton button)
328 {
329 _lastKnownButtonState = button;
330
331 Ui::Window* window = WindowManager::findAt(x, y);
332
333 // TODO: I think window can never be null, there is always a main window,
334 // validate this and work with references from here on.
335
336 Ui::WidgetIndex_t widgetIndex = kWidgetIndexNull;
337 if (window != nullptr)
338 {
339 widgetIndex = window->findWidgetAt(x, y);
340 }
341
342 auto modalType = WindowManager::getCurrentModalType();
343 if (modalType != WindowType::undefined)
344 {
345 if (window != nullptr)
346 {
347 if (window->type != modalType)
348 {
349 if (button == MouseButton::leftPressed)
350 {
351 WindowManager::bringToFront(modalType);
352 Audio::playSound(Audio::SoundId::error, Audio::ChannelId::ui, x);
353 return;
354 }
355
356 if (button == MouseButton::rightPressed)
357 {
358 return;
359 }
360 }
361 }
362 }
363
364 Ui::Widget* widget = nullptr;
365 if (widgetIndex != kWidgetIndexNull)
366 {
367 widget = &window->widgets[widgetIndex];
368 }
369
370 switch (state())
371 {
372 case State::reset:
373 Ui::ToolTip::setTooltipMouseLocation({ x, y });
374 Ui::ToolTip::setTooltipTimeout(0);
375 Ui::ToolTip::setWindowType(Ui::WindowType::undefined);
376 state(State::normal);
377 resetFlag(Flags::leftMousePressed);
378 stateNormal(button, x, y, window, widget, widgetIndex);
379 break;
380
381 case State::normal:
382 stateNormal(button, x, y, window, widget, widgetIndex);
383 break;
384

Callers 2

handleInputFunction · 0.85
minimalHandleInputFunction · 0.85

Calls 15

findAtFunction · 0.85
getCurrentModalTypeFunction · 0.85
bringToFrontFunction · 0.85
playSoundFunction · 0.85
setTooltipMouseLocationFunction · 0.85
setTooltipTimeoutFunction · 0.85
setWindowTypeFunction · 0.85
stateNormalFunction · 0.85
stateWidgetPressedFunction · 0.85
statePositioningWindowFunction · 0.85
stateViewportRightFunction · 0.85
stateViewportLeftFunction · 0.85

Tested by

no test coverage detected