summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-04-23 15:01:02 +0200
committerPatric Stout <github@truebrain.nl>2021-04-24 21:43:58 +0200
commitc2e116a3d3240daf6f1f27a0847efe10a0489adc (patch)
tree6e0433c57c8714a7dac3f957465bbca2533b3c33 /src
parent54f69deb0c627b602da949e8c3fb5ed40daaeaa0 (diff)
downloadopenttd-c2e116a3d3240daf6f1f27a0847efe10a0489adc.tar.xz
Change: track hover position on Online Players GUI
Especially if there are many players online, trying to chat with the right one can be a visual challenge. This can be solved by highlighting the row you are on. This visual cue is often enough for humans to find the right row.
Diffstat (limited to 'src')
-rw-r--r--src/network/network_gui.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 7aaabb3c0..6eac3e8d7 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1755,6 +1755,7 @@ private:
Scrollbar *vscroll; ///< Vertical scrollbar of this window.
uint line_height; ///< Current lineheight of each entry in the matrix.
uint line_count; ///< Amount of lines in the matrix.
+ int hover_index; ///< Index of the current line we are hovering over, or -1 if none.
std::map<uint, std::vector<std::unique_ptr<ButtonCommon>>> buttons; ///< Per line which buttons are available.
@@ -2261,6 +2262,11 @@ public:
case WID_CL_MATRIX: {
uint line = 0;
+ if (this->hover_index >= 0) {
+ uint offset = this->hover_index * this->line_height;
+ GfxFillRect(r.left + 2, r.top + offset, r.right - 1, r.top + offset + this->line_height - 1, GREY_SCALE(9));
+ }
+
for (const Company *c : Company::Iterate()) {
this->DrawCompany(c, r.left, r.right, r.top, line);
}
@@ -2271,6 +2277,24 @@ public:
}
}
}
+
+ virtual void OnMouseLoop() 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<NWidgetBase>(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();
+ }
+ }
};
void ShowClientList()