(svn r17375) -Codechange: remove last direct usage of scrollbar variables

This commit is contained in:
rubidium 2009-09-02 08:58:20 +00:00
parent 900aedf270
commit 5cb22df0f5
5 changed files with 20 additions and 30 deletions

View File

@ -1167,7 +1167,7 @@ public:
virtual void OnResize(Point delta) virtual void OnResize(Point delta)
{ {
/* Update the scroll + matrix */ /* 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. */ /* Update the button bars. */
if (this->vehicle->owner == _local_company) { if (this->vehicle->owner == _local_company) {

View File

@ -42,9 +42,9 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
height = (bottom - top); height = (bottom - top);
pos = sb->pos; pos = sb->GetPosition();
count = sb->count; count = sb->GetCount();
cap = sb->cap; cap = sb->GetCapacity();
if (count != 0) top += height * pos / count; 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; w->flags4 |= WF_SCROLL_UP;
if (_scroller_click_timeout == 0) { if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6; _scroller_click_timeout = 6;
if (sb->pos != 0) sb->pos--; sb->UpdatePosition(-1);
} }
_left_button_clicked = false; _left_button_clicked = false;
} else if (pos >= ma - 10) { } 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) { if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6; _scroller_click_timeout = 6;
if (sb->pos + sb->cap < sb->count) sb->pos++; sb->UpdatePosition(1);
} }
_left_button_clicked = false; _left_button_clicked = false;
} else { } else {
Point pt = HandleScrollbarHittest(sb, mi, ma); Point pt = HandleScrollbarHittest(sb, mi, ma);
if (pos < pt.x) { if (pos < pt.x) {
sb->pos = max(sb->pos - sb->cap, 0); sb->UpdatePosition(-sb->GetCapacity());
} else if (pos > pt.y) { } else if (pos > pt.y) {
sb->pos = min(sb->pos + sb->cap, max(sb->count - sb->cap, 0)); sb->UpdatePosition(sb->GetCapacity());
} 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;

View File

@ -116,7 +116,7 @@ struct DropdownWindow : Window {
int y = _cursor.pos.y - this->top - 2; int y = _cursor.pos.y - this->top - 2;
int width = this->widget[0].right - 3; int width = this->widget[0].right - 3;
int pos = this->vscroll.pos; int pos = this->vscroll.GetPosition();
const DropDownList *list = this->list; const DropDownList *list = this->list;
@ -150,7 +150,7 @@ struct DropdownWindow : Window {
int width = this->widget[0].right - 2; int width = this->widget[0].right - 2;
int right = this->widget[0].right; int right = this->widget[0].right;
int bottom = this->widget[0].bottom; int bottom = this->widget[0].bottom;
int pos = this->vscroll.pos; int pos = this->vscroll.GetPosition();
DropDownList *list = this->list; DropDownList *list = this->list;
@ -189,14 +189,7 @@ struct DropdownWindow : Window {
virtual void OnTick() virtual void OnTick()
{ {
if (this->scrolling == -1) { this->vscroll.UpdatePosition(this->scrolling);
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;
} }
virtual void OnMouseLoop() virtual void OnMouseLoop()
@ -354,8 +347,8 @@ void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, u
dw->widget[0].right -= 12; dw->widget[0].right -= 12;
/* Capacity is the average number of items visible */ /* Capacity is the average number of items visible */
dw->vscroll.cap = height * (uint16)list->size() / list_height; dw->vscroll.SetCapacity(height * (uint16)list->size() / list_height);
dw->vscroll.count = (uint16)list->size(); dw->vscroll.SetCount((uint16)list->size());
} }
dw->desc_flags = WDF_DEF_WIDGET; dw->desc_flags = WDF_DEF_WIDGET;

View File

@ -452,13 +452,10 @@ 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 (w->nested_array != NULL && (uint)widget < w->nested_array_size) sb = w->nested_array[widget]->FindScrollbar(w);
if (sb != NULL && sb->count > sb->cap) { if (sb != NULL && sb->GetCount() > sb->GetCapacity()) {
int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap); sb->UpdatePosition(wheel);
if (pos != sb->pos) {
sb->pos = pos;
w->SetDirty(); w->SetDirty();
} }
}
} }
/** /**
@ -1886,9 +1883,9 @@ static bool HandleScrollbarScrolling()
} }
/* Find the item we want to move to and make sure it's inside bounds. */ /* 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)); int pos = min(max(0, i + _scrollbar_start_pos) * sb->GetCount() / _scrollbar_size, max(0, sb->GetCount() - sb->GetCapacity()));
if (pos != sb->pos) { if (pos != sb->GetPosition()) {
sb->pos = pos; sb->SetPosition(pos);
w->SetDirty(); w->SetDirty();
} }
return false; return false;

View File

@ -185,7 +185,7 @@ enum WindowDefaultPosition {
* Scrollbar data structure * Scrollbar data structure
*/ */
class Scrollbar { class Scrollbar {
public: // To become private 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