summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-07-26 13:02:28 +0000
committeralberth <alberth@openttd.org>2010-07-26 13:02:28 +0000
commit3a1451644a0eae226545818adbde8a8a8c45eab7 (patch)
tree130026ba4b8d6f2d094d756f434671a4cbc52569 /src/window.cpp
parent80cc566553ca1eb33566e0b05a49b7112d98718d (diff)
downloadopenttd-3a1451644a0eae226545818adbde8a8a8c45eab7.tar.xz
(svn r20221) -Codechange: Move unscrolled row calculation into a function.
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp
index da6a1cc18..c3cde4d5a 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -82,6 +82,22 @@ WindowDesc::~WindowDesc()
}
/**
+ * Compute the row of a widget that a user clicked in.
+ * @param clickpos Vertical position of the mouse click.
+ * @param widget Widget number of the widget clicked in.
+ * @param padding Amount of empty space between the widget edge and the top of the first row.
+ * @param line_height Height of a single row.
+ * @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
+ * @note The widget does not know where a list printed at the widget ends, so below a list is not a wrong position.
+ */
+int Window::GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const
+{
+ const NWidgetBase *wid = this->GetWidget<NWidgetBase>(widget);
+ if (clickpos < (int)wid->pos_y + padding) return INT_MAX;
+ return (clickpos - (int)wid->pos_y - padding) / line_height;
+}
+
+/**
* Set capacity of visible elements from the size and resize properties of a widget.
* @param w Window.
* @param widget Widget with size and resize properties.