(svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.

Note: All windows get individual members with the same names, which are initialised via Window::GetScrollbar(). This caching is not required at all, but simplifies conversion.
This commit is contained in:
frosch
2010-08-12 08:37:01 +00:00
parent 341f41e347
commit 4817d5dcd6
28 changed files with 466 additions and 340 deletions

View File

@@ -106,6 +106,8 @@ class ReplaceVehicleWindow : public Window {
GroupID sel_group; ///< Group selected to replace.
int details_height; ///< Minimal needed height of the details panels (found so far).
RailType sel_railtype; ///< Type of rail tracks selected.
Scrollbar *vscroll;
Scrollbar *vscroll2;
/**
* Figure out if an engine should be added to a list.
@@ -171,7 +173,7 @@ class ReplaceVehicleWindow : public Window {
if (this->engines[0].NeedRebuild()) {
/* We need to rebuild the left engines list */
this->GenerateReplaceVehList(true);
this->vscroll.SetCount(this->engines[0].Length());
this->vscroll->SetCount(this->engines[0].Length());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
this->sel_engine[0] = this->engines[0][0];
}
@@ -185,7 +187,7 @@ class ReplaceVehicleWindow : public Window {
this->sel_engine[1] = INVALID_ENGINE;
} else {
this->GenerateReplaceVehList(false);
this->vscroll2.SetCount(this->engines[1].Length());
this->vscroll2->SetCount(this->engines[1].Length());
if (this->reset_sel_engine && this->sel_engine[1] == INVALID_ENGINE && this->engines[1].Length() != 0) {
this->sel_engine[1] = this->engines[1][0];
}
@@ -226,7 +228,10 @@ public:
this->sel_engine[0] = INVALID_ENGINE;
this->sel_engine[1] = INVALID_ENGINE;
this->InitNested(desc, vehicletype);
this->CreateNestedTree(desc);
this->vscroll = this->GetScrollbar(RVW_WIDGET_LEFT_SCROLLBAR);
this->vscroll2 = this->GetScrollbar(RVW_WIDGET_RIGHT_SCROLLBAR);
this->FinishInitNested(desc, vehicletype);
this->owner = _local_company;
this->sel_group = id_g;
@@ -339,8 +344,8 @@ public:
case RVW_WIDGET_LEFT_MATRIX:
case RVW_WIDGET_RIGHT_MATRIX: {
int side = (widget == RVW_WIDGET_LEFT_MATRIX) ? 0 : 1;
EngineID start = side == 0 ? this->vscroll.GetPosition() : this->vscroll2.GetPosition(); // what is the offset for the start (scrolling)
EngineID end = min((side == 0 ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity()) + start, this->engines[side].Length());
EngineID start = side == 0 ? this->vscroll->GetPosition() : this->vscroll2->GetPosition(); // what is the offset for the start (scrolling)
EngineID end = min((side == 0 ? this->vscroll->GetCapacity() : this->vscroll2->GetCapacity()) + start, this->engines[side].Length());
/* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
@@ -453,10 +458,10 @@ public:
uint i;
byte click_side;
if (widget == RVW_WIDGET_LEFT_MATRIX) {
i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
click_side = 0;
} else {
i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
click_side = 1;
}
size_t engine_count = this->engines[click_side].Length();
@@ -480,8 +485,8 @@ public:
if (temp == sel_railtype) return; // we didn't select a new one. No need to change anything
sel_railtype = temp;
/* Reset scrollbar positions */
this->vscroll.SetPosition(0);
this->vscroll2.SetPosition(0);
this->vscroll->SetPosition(0);
this->vscroll2->SetPosition(0);
/* Rebuild the lists */
this->engines[0].ForceRebuild();
this->engines[1].ForceRebuild();
@@ -491,11 +496,11 @@ public:
virtual void OnResize()
{
this->vscroll.SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX);
this->vscroll2.SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX);
this->vscroll->SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX);
this->vscroll2->SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX);
this->GetWidget<NWidgetCore>(RVW_WIDGET_LEFT_MATRIX)->widget_data =
this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
this->GetWidget<NWidgetCore>(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
virtual void OnInvalidateData(int data)