From 8e9ca5ebcb016aa0e15c52f08a8a6f5e1c8439e7 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 13 Sep 2022 23:14:14 +0100 Subject: [PATCH] Fix: Online Players list mouse hover behaviour. Hover highlight was visible even if the mouse pointer was in a different window, and the window refreshed itself every frame if the mouse pointer was not over its matrix widget. Resolved by using OnMouseOver() instead of OnMouseLoop(), and only redrawing if the hover position has changed. --- src/network/network_gui.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 4017c0e71c..ae3f8c8f9b 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2115,21 +2115,19 @@ public: } } - virtual void OnMouseLoop() override + void OnMouseOver(Point pt, int widget) override { - if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) != WID_CL_MATRIX) { - this->hover_index = -1; - this->SetDirty(); - return; - } - - NWidgetBase *nwi = this->GetWidget(WID_CL_MATRIX); - int y = _cursor.pos.y - this->top - nwi->pos_y - 2; - int index = y / this->line_height; - - if (index != this->hover_index) { - this->hover_index = index; - this->SetDirty(); + if (widget != WID_CL_MATRIX) { + if (this->hover_index != -1) { + this->hover_index = -1; + this->SetWidgetDirty(WID_CL_MATRIX); + } + } else { + int index = this->GetRowFromWidget(pt.y, widget, 0, -1); + if (index != this->hover_index) { + this->hover_index = index; + this->SetWidgetDirty(WID_CL_MATRIX); + } } } };