From 71ca58c2bb1b72a088acec5b70423a43512ec195 Mon Sep 17 00:00:00 2001 From: frosch Date: Thu, 12 Aug 2010 08:37:01 +0000 Subject: (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. --- src/autoreplace_gui.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/autoreplace_gui.cpp') diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 6a628e75f..7c1557a95 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -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(RVW_WIDGET_LEFT_MATRIX)->widget_data = - this->GetWidget(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); + this->GetWidget(RVW_WIDGET_RIGHT_MATRIX)->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } virtual void OnInvalidateData(int data) -- cgit v1.2.3-54-g00ecf