mirror of https://github.com/OpenTTD/OpenTTD
(svn r21763) -Codechange: Pass the distance to Scrollbar::UpdatePosition() in units of small or big steps.
parent
beb7f63746
commit
da09ebc59a
|
@ -103,9 +103,9 @@ static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, in
|
||||||
Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
|
Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
|
||||||
|
|
||||||
if (pos < pt.x) {
|
if (pos < pt.x) {
|
||||||
sb->UpdatePosition(rtl ? sb->GetCapacity() : -sb->GetCapacity());
|
sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
|
||||||
} else if (pos > pt.y) {
|
} else if (pos > pt.y) {
|
||||||
sb->UpdatePosition(rtl ? -sb->GetCapacity() : sb->GetCapacity());
|
sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
|
||||||
} else {
|
} else {
|
||||||
_scrollbar_start_pos = pt.x - mi - 9;
|
_scrollbar_start_pos = pt.x - mi - 9;
|
||||||
_scrollbar_size = ma - mi - 23;
|
_scrollbar_size = ma - mi - 23;
|
||||||
|
|
|
@ -556,9 +556,17 @@ private:
|
||||||
uint16 count; ///< Number of elements in the list.
|
uint16 count; ///< Number of elements in the list.
|
||||||
uint16 cap; ///< Number of visible elements of the scroll bar.
|
uint16 cap; ///< Number of visible elements of the scroll bar.
|
||||||
uint16 pos; ///< Index of first visible item of the list.
|
uint16 pos; ///< Index of first visible item of the list.
|
||||||
|
uint16 stepsize; ///< Distance to scroll, when pressing the buttons or using the wheel.
|
||||||
|
|
||||||
public:
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,6 +616,16 @@ public:
|
||||||
return this->is_vertical;
|
return this->is_vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Sets the number of elements in the list
|
||||||
* @param num the number of elements in the list
|
* @param num the number of elements in the list
|
||||||
|
@ -655,10 +673,16 @@ public:
|
||||||
* Updates the position of the first visible element by the given amount.
|
* 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
|
* If the position would be too low or high it will be clamped appropriately
|
||||||
* @param difference the amount of change requested
|
* @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;
|
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)));
|
this->SetPosition(Clamp(this->pos + difference, 0, max(this->count - this->cap, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue