mirror of https://github.com/OpenTTD/OpenTTD
Fix: Zoom-scroll extra viewports only if the mouse cursor is over the viewport. (#14209)
parent
afc1e76575
commit
3e608b5fe4
|
@ -361,8 +361,9 @@ struct IConsoleWindow : Window
|
||||||
return GetCharAtPosition(_iconsole_cmdline.GetText(), pt.x - delta);
|
return GetCharAtPosition(_iconsole_cmdline.GetText(), pt.x - delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_C_BACKGROUND) return;
|
||||||
this->Scroll(-wheel);
|
this->Scroll(-wheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1131,8 +1131,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_IV_VIEWPORT) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,8 +433,9 @@ struct MainWindow : Window
|
||||||
this->refresh_timeout.Reset();
|
this->refresh_timeout.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_M_VIEWPORT) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
bool in = wheel < 0;
|
bool in = wheel < 0;
|
||||||
|
|
||||||
|
|
|
@ -1857,16 +1857,15 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_SM_MAP) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
|
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_SM_MAP);
|
||||||
int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
|
int cursor_x = _cursor.pos.x - this->left - wid->pos_x;
|
||||||
int cursor_y = _cursor.pos.y - this->top - wid->pos_y;
|
int cursor_y = _cursor.pos.y - this->top - wid->pos_y;
|
||||||
if (IsInsideMM(cursor_x, 0, wid->current_x) && IsInsideMM(cursor_y, 0, wid->current_y)) {
|
Point pt = {cursor_x, cursor_y};
|
||||||
Point pt = {cursor_x, cursor_y};
|
this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
|
||||||
this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -577,8 +577,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_TV_VIEWPORT) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3332,8 +3332,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_VV_VIEWPORT) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,8 +124,9 @@ public:
|
||||||
return widget == WID_EV_VIEWPORT;
|
return widget == WID_EV_VIEWPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseWheel(int wheel) override
|
void OnMouseWheel(int wheel, WidgetID widget) override
|
||||||
{
|
{
|
||||||
|
if (widget != WID_EV_VIEWPORT) return;
|
||||||
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
|
||||||
ZoomInOrOutToCursorWindow(wheel < 0, this);
|
ZoomInOrOutToCursorWindow(wheel < 0, this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2823,7 +2823,11 @@ static void MouseLoop(MouseClick click, int mousewheel)
|
||||||
|
|
||||||
if (mousewheel != 0) {
|
if (mousewheel != 0) {
|
||||||
/* Send mousewheel event to window, unless we're scrolling a viewport or the map */
|
/* Send mousewheel event to window, unless we're scrolling a viewport or the map */
|
||||||
if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) w->OnMouseWheel(mousewheel);
|
if (!scrollwheel_scrolling || (vp == nullptr && w->window_class != WC_SMALLMAP)) {
|
||||||
|
if (NWidgetCore *nwid = w->nested_root->GetWidgetFromPos(x - w->left, y - w->top); nwid != nullptr) {
|
||||||
|
w->OnMouseWheel(mousewheel, nwid->GetIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
|
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
|
||||||
if (vp == nullptr) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
|
if (vp == nullptr) DispatchMouseWheelEvent(w, w->nested_root->GetWidgetFromPos(x - w->left, y - w->top), mousewheel);
|
||||||
|
|
|
@ -720,8 +720,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* The mouse wheel has been turned.
|
* The mouse wheel has been turned.
|
||||||
* @param wheel the amount of movement of the mouse wheel.
|
* @param wheel the amount of movement of the mouse wheel.
|
||||||
|
* @param widget the widget the mouse hovers over.
|
||||||
*/
|
*/
|
||||||
virtual void OnMouseWheel([[maybe_unused]] int wheel) {}
|
virtual void OnMouseWheel([[maybe_unused]] int wheel, [[maybe_unused]] WidgetID widget) {}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue