* If needed and switched on, perform auto scrolling (automatically * moving window contents when mouse is near edge of the window). */
| 2748 | * moving window contents when mouse is near edge of the window). |
| 2749 | */ |
| 2750 | static void HandleAutoscroll() |
| 2751 | { |
| 2752 | if (_game_mode == GM_MENU || HasModalProgress()) return; |
| 2753 | if (_settings_client.gui.auto_scrolling == VA_DISABLED) return; |
| 2754 | if (_settings_client.gui.auto_scrolling == VA_MAIN_VIEWPORT_FULLSCREEN && !_fullscreen) return; |
| 2755 | |
| 2756 | int x = _cursor.pos.x; |
| 2757 | int y = _cursor.pos.y; |
| 2758 | Window *w = FindWindowFromPt(x, y); |
| 2759 | if (w == nullptr || w->flags.Test(WindowFlag::DisableVpScroll)) return; |
| 2760 | if (_settings_client.gui.auto_scrolling != VA_EVERY_VIEWPORT && w->window_class != WC_MAIN_WINDOW) return; |
| 2761 | |
| 2762 | Viewport *vp = IsPtInWindowViewport(w, x, y); |
| 2763 | if (vp == nullptr) return; |
| 2764 | |
| 2765 | x -= vp->left; |
| 2766 | y -= vp->top; |
| 2767 | |
| 2768 | /* here allows scrolling in both x and y axis */ |
| 2769 | /* If we succeed at scrolling in any direction, stop following a vehicle. */ |
| 2770 | static const int SCROLLSPEED = 3; |
| 2771 | if (x - 15 < 0) { |
| 2772 | w->viewport->CancelFollow(*w); |
| 2773 | w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom); |
| 2774 | } else if (15 - (vp->width - x) > 0) { |
| 2775 | w->viewport->CancelFollow(*w); |
| 2776 | w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom); |
| 2777 | } |
| 2778 | if (y - 15 < 0) { |
| 2779 | w->viewport->CancelFollow(*w); |
| 2780 | w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom); |
| 2781 | } else if (15 - (vp->height - y) > 0) { |
| 2782 | w->viewport->CancelFollow(*w); |
| 2783 | w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom); |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | enum MouseClick : uint8_t { |
| 2788 | MC_NONE = 0, |
no test coverage detected