summaryrefslogtreecommitdiff
path: root/src/fios_gui.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-04 23:06:49 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2020-01-05 23:50:00 +0100
commitac3bc30a30d3daeb912c989accbb0fb08ea6e582 (patch)
tree63a2ad4a5522066da923a46c75730e6149ec9e55 /src/fios_gui.cpp
parent838117b05ec5ca6e111b86fb9c1210c755e42201 (diff)
downloadopenttd-ac3bc30a30d3daeb912c989accbb0fb08ea6e582.tar.xz
Add: Highlight item under mouse in file browser
Diffstat (limited to 'src/fios_gui.cpp')
-rw-r--r--src/fios_gui.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index de66d6b89..9f8b45413 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -271,6 +271,7 @@ private:
FileList fios_items; ///< Save game list.
FiosItem o_dir; ///< Original dir (home dir for this browser)
const FiosItem *selected; ///< Selected game in #fios_items, or \c nullptr.
+ const FiosItem *highlighted; ///< Item in fios_items highlighted by mouse pointer, or \c nullptr.
Scrollbar *vscroll;
StringFilter string_filter; ///< Filter for available games.
@@ -445,6 +446,8 @@ public:
if (item == this->selected) {
GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE);
+ } else if (item == this->highlighted) {
+ GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_VERY_DARK_BLUE);
}
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[GetDetailedFileType(item->type)]);
y += this->resize.step_height;
@@ -714,6 +717,33 @@ public:
}
}
+ void OnMouseLoop() override
+ {
+ const Point pt{ _cursor.pos.x - this->left, _cursor.pos.y - this->top };
+ const int widget = GetWidgetFromPos(this, pt.x, pt.y);
+
+ if (widget == WID_SL_DRIVES_DIRECTORIES_LIST) {
+ int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
+ if (y == INT_MAX) return;
+
+ /* Get the corresponding non-filtered out item from the list */
+ int i = 0;
+ while (i <= y) {
+ if (!this->fios_items_shown[i]) y++;
+ i++;
+ }
+ const FiosItem *file = this->fios_items.Get(y);
+
+ if (file != this->highlighted) {
+ this->highlighted = file;
+ this->SetWidgetDirty(WID_SL_DRIVES_DIRECTORIES_LIST);
+ }
+ } else if (this->highlighted != nullptr) {
+ this->highlighted = nullptr;
+ this->SetWidgetDirty(WID_SL_DRIVES_DIRECTORIES_LIST);
+ }
+ }
+
EventState OnKeyPress(WChar key, uint16 keycode) override
{
if (keycode == WKC_ESC) {