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

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
rubidium 15 years ago
parent 900aedf270
commit 5cb22df0f5

@ -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) {

@ -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;

@ -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;

@ -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;

@ -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

Loading…
Cancel
Save