summaryrefslogtreecommitdiff
path: root/src/widget_type.h
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-01-09 20:39:06 +0000
committerfrosch <frosch@openttd.org>2011-01-09 20:39:06 +0000
commitda09ebc59a80bf3b21046df8b0e722e00e81d2e4 (patch)
treea4deb45f1f14fa9ad221e7b22673611b6e7d33c9 /src/widget_type.h
parentbeb7f63746e1ed04e370d0c06cf5614aaa24f12a (diff)
downloadopenttd-da09ebc59a80bf3b21046df8b0e722e00e81d2e4.tar.xz
(svn r21763) -Codechange: Pass the distance to Scrollbar::UpdatePosition() in units of small or big steps.
Diffstat (limited to 'src/widget_type.h')
-rw-r--r--src/widget_type.h28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/widget_type.h b/src/widget_type.h
index 5850443e1..5d135552a 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -556,9 +556,17 @@ private:
uint16 count; ///< Number of elements in the list.
uint16 cap; ///< Number of visible elements of the scroll bar.
uint16 pos; ///< Index of first visible item of the list.
+ uint16 stepsize; ///< Distance to scroll, when pressing the buttons or using the wheel.
public:
- Scrollbar(bool is_vertical) : is_vertical(is_vertical)
+ /** Stepping sizes when scrolling */
+ enum ScrollbarStepping {
+ SS_RAW, ///< Step in single units.
+ SS_SMALL, ///< Step in #stepsize units.
+ SS_BIG, ///< Step in #cap units.
+ };
+
+ Scrollbar(bool is_vertical) : is_vertical(is_vertical), stepsize(1)
{
}
@@ -609,6 +617,16 @@ public:
}
/**
+ * Set the distance to scroll when using the buttons or the wheel.
+ * @param stepsize Scrolling speed.
+ */
+ void SetStepSize(uint16 stepsize)
+ {
+ assert(stepsize > 0);
+ this->stepsize = stepsize;
+ }
+
+ /**
* Sets the number of elements in the list
* @param num the number of elements in the list
* @note updates the position if needed
@@ -655,10 +673,16 @@ public:
* Updates the position of the first visible element by the given amount.
* If the position would be too low or high it will be clamped appropriately
* @param difference the amount of change requested
+ * @param unit The stepping unit of \a difference
*/
- void UpdatePosition(int difference)
+ void UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
{
if (difference == 0) return;
+ switch (unit) {
+ case SS_SMALL: difference *= this->stepsize; break;
+ case SS_BIG: difference *= this->cap; break;
+ default: break;
+ }
this->SetPosition(Clamp(this->pos + difference, 0, max(this->count - this->cap, 0)));
}