* Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc. * @param icon New shape of the mouse cursor. * @param pal Palette to use. * @param mode Mode to perform. * @param window_class %Window class of the window requesting the mode change. * @param window_num Number of the window in its class requesting the
| 3523 | * @param window_num Number of the window in its class requesting the mode change. |
| 3524 | */ |
| 3525 | void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num) |
| 3526 | { |
| 3527 | if (_thd.window_class != WC_INVALID) { |
| 3528 | /* Undo clicking on button and drag & drop */ |
| 3529 | Window *w = _thd.GetCallbackWnd(); |
| 3530 | /* Call the abort function, but set the window class to something |
| 3531 | * that will never be used to avoid infinite loops. Setting it to |
| 3532 | * the 'next' window class must not be done because recursion into |
| 3533 | * this function might in some cases reset the newly set object to |
| 3534 | * place or not properly reset the original selection. */ |
| 3535 | _thd.window_class = WC_INVALID; |
| 3536 | if (w != nullptr) { |
| 3537 | w->OnPlaceObjectAbort(); |
| 3538 | HideMeasurementTooltips(); |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | /* Mark the old selection dirty, in case the selection shape or colour changes */ |
| 3543 | if ((_thd.drawstyle & HT_DRAG_MASK) != HT_NONE) SetSelectionTilesDirty(); |
| 3544 | |
| 3545 | SetTileSelectSize(1, 1); |
| 3546 | |
| 3547 | _thd.make_square_red = false; |
| 3548 | |
| 3549 | if (mode == HT_DRAG) { // HT_DRAG is for dragdropping trains in the depot window |
| 3550 | mode = HT_NONE; |
| 3551 | _special_mouse_mode = WSM_DRAGDROP; |
| 3552 | } else { |
| 3553 | _special_mouse_mode = WSM_NONE; |
| 3554 | } |
| 3555 | |
| 3556 | _thd.place_mode = mode; |
| 3557 | _thd.window_class = window_class; |
| 3558 | _thd.window_number = window_num; |
| 3559 | |
| 3560 | if ((mode & HT_DRAG_MASK) == HT_SPECIAL) { // special tools, like tunnels or docks start with presizing mode |
| 3561 | VpStartPreSizing(); |
| 3562 | } |
| 3563 | |
| 3564 | if ((icon & ANIMCURSOR_FLAG) != 0) { |
| 3565 | SetAnimatedMouseCursor(_animcursors[icon & ~ANIMCURSOR_FLAG]); |
| 3566 | } else { |
| 3567 | SetMouseCursor(icon, pal); |
| 3568 | } |
| 3569 | |
| 3570 | } |
| 3571 | |
| 3572 | /** Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows). */ |
| 3573 | void ResetObjectToPlace() |
no test coverage detected