summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-02 08:58:20 +0000
committerrubidium <rubidium@openttd.org>2009-09-02 08:58:20 +0000
commit5cb22df0f56420759e727b9e9fd16e379a358fb2 (patch)
tree23e18970c93398f1879757bed924b5be3a861ac7 /src
parent900aedf270319b5fbcd3373dfa268a5a5c1cfc78 (diff)
downloadopenttd-5cb22df0f56420759e727b9e9fd16e379a358fb2.tar.xz
(svn r17375) -Codechange: remove last direct usage of scrollbar variables
Diffstat (limited to 'src')
-rw-r--r--src/order_gui.cpp2
-rw-r--r--src/widget.cpp14
-rw-r--r--src/widgets/dropdown.cpp17
-rw-r--r--src/window.cpp15
-rw-r--r--src/window_gui.h2
5 files changed, 20 insertions, 30 deletions
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index fb7498f2f..ebd40f050 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -1167,7 +1167,7 @@ public:
virtual void OnResize(Point delta)
{
/* Update the scroll + matrix */
- this->vscroll.UpdateCapacity((this->widget[ORDER_WIDGET_ORDER_LIST].bottom - this->widget[ORDER_WIDGET_ORDER_LIST].top - 1) / ORDER_LIST_LINE_HEIGHT);
+ this->vscroll.UpdateCapacity(delta.y / ORDER_LIST_LINE_HEIGHT);
/* Update the button bars. */
if (this->vehicle->owner == _local_company) {
diff --git a/src/widget.cpp b/src/widget.cpp
index ab0582698..e3307bd69 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -42,9 +42,9 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
height = (bottom - top);
- pos = sb->pos;
- count = sb->count;
- cap = sb->cap;
+ pos = sb->GetPosition();
+ count = sb->GetCount();
+ cap = sb->GetCapacity();
if (count != 0) top += height * pos / count;
@@ -102,7 +102,7 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
w->flags4 |= WF_SCROLL_UP;
if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6;
- if (sb->pos != 0) sb->pos--;
+ sb->UpdatePosition(-1);
}
_left_button_clicked = false;
} else if (pos >= ma - 10) {
@@ -111,16 +111,16 @@ static void ScrollbarClickPositioning(Window *w, WidgetType wtp, int x, int y, i
if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6;
- if (sb->pos + sb->cap < sb->count) sb->pos++;
+ sb->UpdatePosition(1);
}
_left_button_clicked = false;
} else {
Point pt = HandleScrollbarHittest(sb, mi, ma);
if (pos < pt.x) {
- sb->pos = max(sb->pos - sb->cap, 0);
+ sb->UpdatePosition(-sb->GetCapacity());
} else if (pos > pt.y) {
- sb->pos = min(sb->pos + sb->cap, max(sb->count - sb->cap, 0));
+ sb->UpdatePosition(sb->GetCapacity());
} else {
_scrollbar_start_pos = pt.x - mi - 9;
_scrollbar_size = ma - mi - 23;
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp
index 6da4989e3..04c27de88 100644
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -116,7 +116,7 @@ struct DropdownWindow : Window {
int y = _cursor.pos.y - this->top - 2;
int width = this->widget[0].right - 3;
- int pos = this->vscroll.pos;
+ int pos = this->vscroll.GetPosition();
const DropDownList *list = this->list;
@@ -150,7 +150,7 @@ struct DropdownWindow : Window {
int width = this->widget[0].right - 2;
int right = this->widget[0].right;
int bottom = this->widget[0].bottom;
- int pos = this->vscroll.pos;
+ int pos = this->vscroll.GetPosition();
DropDownList *list = this->list;
@@ -189,14 +189,7 @@ struct DropdownWindow : Window {
virtual void OnTick()
{
- if (this->scrolling == -1) {
- this->vscroll.pos = max(0, this->vscroll.pos - 1);
- this->SetDirty();
- } else if (this->scrolling == 1) {
- this->vscroll.pos = min(this->vscroll.count - this->vscroll.cap, this->vscroll.pos + 1);
- this->SetDirty();
- }
- this->scrolling = 0;
+ this->vscroll.UpdatePosition(this->scrolling);
}
virtual void OnMouseLoop()
@@ -354,8 +347,8 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
dw->widget[0].right -= 12;
/* Capacity is the average number of items visible */
- dw->vscroll.cap = height * (uint16)list->size() / list_height;
- dw->vscroll.count = (uint16)list->size();
+ dw->vscroll.SetCapacity(height * (uint16)list->size() / list_height);
+ dw->vscroll.SetCount((uint16)list->size());
}
dw->desc_flags = WDF_DEF_WIDGET;
diff --git a/src/window.cpp b/src/window.cpp
index af0c4e024..9ce9f105d 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -452,12 +452,9 @@ static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
if (w->nested_array != NULL && (uint)widget < w->nested_array_size) sb = w->nested_array[widget]->FindScrollbar(w);
- if (sb != NULL && sb->count > sb->cap) {
- int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
- if (pos != sb->pos) {
- sb->pos = pos;
- w->SetDirty();
- }
+ if (sb != NULL && sb->GetCount() > sb->GetCapacity()) {
+ sb->UpdatePosition(wheel);
+ w->SetDirty();
}
}
@@ -1886,9 +1883,9 @@ static bool HandleScrollbarScrolling()
}
/* Find the item we want to move to and make sure it's inside bounds. */
- int pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
- if (pos != sb->pos) {
- sb->pos = pos;
+ int pos = min(max(0, i + _scrollbar_start_pos) * sb->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
+ if (pos != sb->GetPosition()) {
+ sb->SetPosition(pos);
w->SetDirty();
}
return false;
diff --git a/src/window_gui.h b/src/window_gui.h
index d8f01f929..4a4750b43 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -185,7 +185,7 @@ enum WindowDefaultPosition {
* Scrollbar data structure
*/
class Scrollbar {
-public: // To become private
+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