changeset 12883:3cef4e937afd draft

(svn r17375) -Codechange: remove last direct usage of scrollbar variables
author rubidium <rubidium@openttd.org>
date Wed, 02 Sep 2009 08:58:20 +0000
parents 0d902cefe84b
children 3c68578a8f63
files src/order_gui.cpp src/widget.cpp src/widgets/dropdown.cpp src/window.cpp src/window_gui.h
diffstat 5 files changed, 20 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -1167,7 +1167,7 @@
 	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) {
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -42,9 +42,9 @@
 
 	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 @@
 		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 @@
 
 		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;
--- a/src/widgets/dropdown.cpp
+++ b/src/widgets/dropdown.cpp
@@ -116,7 +116,7 @@
 
 		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 @@
 		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 @@
 
 	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 @@
 		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;
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -452,12 +452,9 @@
 
 	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 @@
 			}
 
 			/* 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;
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -185,7 +185,7 @@
  * 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