diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 7c1557a95e..6d0176b966 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -106,8 +106,7 @@ 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; + Scrollbar *vscroll[2]; /** * Figure out if an engine should be added to a list. @@ -173,7 +172,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[0]->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]; } @@ -187,7 +186,7 @@ class ReplaceVehicleWindow : public Window { this->sel_engine[1] = INVALID_ENGINE; } else { this->GenerateReplaceVehList(false); - this->vscroll2->SetCount(this->engines[1].Length()); + this->vscroll[1]->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]; } @@ -229,8 +228,8 @@ public: this->sel_engine[1] = INVALID_ENGINE; this->CreateNestedTree(desc); - this->vscroll = this->GetScrollbar(RVW_WIDGET_LEFT_SCROLLBAR); - this->vscroll2 = this->GetScrollbar(RVW_WIDGET_RIGHT_SCROLLBAR); + this->vscroll[0] = this->GetScrollbar(RVW_WIDGET_LEFT_SCROLLBAR); + this->vscroll[1] = this->GetScrollbar(RVW_WIDGET_RIGHT_SCROLLBAR); this->FinishInitNested(desc, vehicletype); this->owner = _local_company; @@ -344,8 +343,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 = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling) + EngineID end = min(this->vscroll[side]->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, @@ -455,15 +454,13 @@ public: case RVW_WIDGET_LEFT_MATRIX: case RVW_WIDGET_RIGHT_MATRIX: { - uint i; byte click_side; if (widget == 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); click_side = 1; } + uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget); size_t engine_count = this->engines[click_side].Length(); EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE; @@ -485,8 +482,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[0]->SetPosition(0); + this->vscroll[1]->SetPosition(0); /* Rebuild the lists */ this->engines[0].ForceRebuild(); this->engines[1].ForceRebuild(); @@ -496,11 +493,11 @@ public: virtual void OnResize() { - this->vscroll->SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX); - this->vscroll2->SetCapacityFromWidget(this, RVW_WIDGET_RIGHT_MATRIX); + this->vscroll[0]->SetCapacityFromWidget(this, RVW_WIDGET_LEFT_MATRIX); + this->vscroll[1]->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[0]->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } virtual void OnInvalidateData(int data) diff --git a/src/group_gui.cpp b/src/group_gui.cpp index d165e1e4be..35f935a7d4 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -119,7 +119,7 @@ private: GroupID group_rename; ///< Group being renamed, INVALID_GROUP if none GUIGroupList groups; ///< List of groups uint tiny_step_height; ///< Step height for the group list - Scrollbar *vscroll2; + Scrollbar *group_sb; /** * (Re)Build the group list. @@ -172,7 +172,7 @@ public: this->CreateNestedTree(desc); this->vscroll = this->GetScrollbar(GRP_WIDGET_LIST_VEHICLE_SCROLLBAR); - this->vscroll2 = this->GetScrollbar(GRP_WIDGET_LIST_GROUP_SCROLLBAR); + this->group_sb = this->GetScrollbar(GRP_WIDGET_LIST_GROUP_SCROLLBAR); this->vehicle_type = (VehicleType)GB(window_number, 11, 5); switch (this->vehicle_type) { @@ -309,7 +309,7 @@ public: this->BuildGroupList(owner); this->groups.Sort(&GroupNameSorter); - this->vscroll2->SetCount(this->groups.Length()); + this->group_sb->SetCount(this->groups.Length()); this->vscroll->SetCount(this->vehicles.Length()); /* The drop down menu is out, *but* it may not be used, retract it. */ @@ -369,8 +369,8 @@ public: case GRP_WIDGET_LIST_GROUP: { int y1 = r.top + WD_FRAMERECT_TOP + 1; - int max = min(this->vscroll2->GetPosition() + this->vscroll2->GetCapacity(), this->groups.Length()); - for (int i = this->vscroll2->GetPosition(); i < max; ++i) { + int max = min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.Length()); + for (int i = this->group_sb->GetPosition(); i < max; ++i) { const Group *g = this->groups[i]; assert(g->owner == this->owner); @@ -427,7 +427,7 @@ public: break; case GRP_WIDGET_LIST_GROUP: { // Matrix Group - uint id_g = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height); + uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height); if (id_g >= this->groups.Length()) return; this->group_sel = this->groups[id_g]->index; @@ -516,7 +516,7 @@ public: this->vehicle_sel = INVALID_VEHICLE; this->SetDirty(); - uint id_g = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height); + uint id_g = this->group_sb->GetScrolledRowFromWidget(pt.y, this, GRP_WIDGET_LIST_GROUP, 0, this->tiny_step_height); if (id_g >= this->groups.Length()) return; DoCommandP(0, this->groups[id_g]->index, vindex, CMD_ADD_VEHICLE_GROUP | CMD_MSG(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE)); @@ -550,8 +550,8 @@ public: virtual void OnResize() { NWidgetCore *nwi = this->GetWidget(GRP_WIDGET_LIST_GROUP); - this->vscroll2->SetCapacity(nwi->current_y / this->tiny_step_height); - nwi->widget_data = (this->vscroll2->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); + this->group_sb->SetCapacity(nwi->current_y / this->tiny_step_height); + nwi->widget_data = (this->group_sb->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); nwi = this->GetWidget(GRP_WIDGET_LIST_VEHICLE); this->vscroll->SetCapacityFromWidget(this, GRP_WIDGET_LIST_VEHICLE);