diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index d2cf21c9bc..ef2e9e0a8b 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -278,7 +278,7 @@ struct DepotWindow : Window { free_wagon = u->IsFreeWagon(); uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0; - DrawTrainImage(u, x + 24 + x_space, sprite_y - 1, this->sel, this->hscroll.cap - x_space, this->hscroll.pos); + DrawTrainImage(u, x + 24 + x_space, sprite_y - 1, this->sel, this->hscroll.GetCapacity() - x_space, this->hscroll.GetPosition()); /* Number of wagons relative to a standard length wagon (rounded up) */ SetDParam(0, (u->tcache.cached_total_length + 7) / 8); @@ -349,10 +349,10 @@ struct DepotWindow : Window { max_width = max(max_width, width); } /* Always have 1 empty row, so people can change the setting of the train */ - SetVScrollCount(this, this->vehicle_list.Length() + this->wagon_list.Length() + 1); - SetHScrollCount(this, max_width); + this->vscroll.SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1); + this->hscroll.SetCount(max_width); } else { - SetVScrollCount(this, (this->vehicle_list.Length() + this->hscroll.cap - 1) / this->hscroll.cap); + this->vscroll.SetCount((this->vehicle_list.Length() + this->hscroll.GetCapacity() - 1) / this->hscroll.GetCapacity()); } /* locate the depot struct */ @@ -367,7 +367,7 @@ struct DepotWindow : Window { this->DrawWidgets(); - uint16 num = this->vscroll.pos * boxes_in_each_row; + uint16 num = this->vscroll.GetPosition() * boxes_in_each_row; maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row)); for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows @@ -380,7 +380,7 @@ struct DepotWindow : Window { } } - maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); + maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); /* draw the train wagons, that do not have an engine in front */ for (; num < maxval; num++, y += 14) { @@ -413,15 +413,15 @@ struct DepotWindow : Window { } else { xt = x / this->resize.step_width; xm = x % this->resize.step_width; - if (xt >= this->hscroll.cap) return MODE_ERROR; + if (xt >= this->hscroll.GetCapacity()) return MODE_ERROR; ym = (y - 14) % this->resize.step_height; } row = (y - 14) / this->resize.step_height; - if (row >= this->vscroll.cap) return MODE_ERROR; + if (row >= this->vscroll.GetCapacity()) return MODE_ERROR; - pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt; + pos = ((row + this->vscroll.GetPosition()) * boxes_in_each_row) + xt; if ((int)(this->vehicle_list.Length() + this->wagon_list.Length()) <= pos) { if (this->type == VEH_TRAIN) { @@ -435,7 +435,7 @@ struct DepotWindow : Window { if ((int)this->vehicle_list.Length() > pos) { *veh = this->vehicle_list[pos]; - skip = this->hscroll.pos; + skip = this->hscroll.GetPosition(); } else { pos -= this->vehicle_list.Length(); *veh = this->wagon_list[pos]; @@ -657,8 +657,8 @@ struct DepotWindow : Window { /* Resize the window according to the vehicle type */ /* Set the number of blocks in each direction */ - this->vscroll.cap = _resize_cap[type][0]; - this->hscroll.cap = _resize_cap[type][1]; + this->vscroll.SetCapacity(_resize_cap[type][0]); + this->hscroll.SetCapacity(_resize_cap[type][1]); /* Set the block size */ this->resize.step_width = _block_sizes[type][0]; @@ -666,8 +666,8 @@ struct DepotWindow : Window { /* Enlarge the window to fit with the selected number of blocks of the selected size */ ResizeWindow(this, - _block_sizes[type][0] * this->hscroll.cap, - _block_sizes[type][1] * this->vscroll.cap); + _block_sizes[type][0] * this->hscroll.GetCapacity(), + _block_sizes[type][1] * this->vscroll.GetCapacity()); if (type == VEH_TRAIN) { /* Make space for the horizontal scrollbar vertically, and the unit @@ -684,8 +684,8 @@ struct DepotWindow : Window { this->SetupStringsForDepotWindow(type); this->widget[DEPOT_WIDGET_MATRIX].data = - (this->vscroll.cap << MAT_ROW_START) // number of rows to draw on the background - + ((type == VEH_TRAIN ? 1 : this->hscroll.cap) << MAT_COL_START); // number of boxes in each row. Trains always have just one + (this->vscroll.GetCapacity() << MAT_ROW_START) // number of rows to draw on the background + + ((type == VEH_TRAIN ? 1 : this->hscroll.GetCapacity()) << MAT_COL_START); // number of boxes in each row. Trains always have just one this->SetWidgetsHiddenState(type != VEH_TRAIN, @@ -945,9 +945,9 @@ struct DepotWindow : Window { virtual void OnResize(Point delta) { - this->vscroll.cap += delta.y / (int)this->resize.step_height; - this->hscroll.cap += delta.x / (int)this->resize.step_width; - this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + ((this->type == VEH_TRAIN ? 1 : this->hscroll.cap) << MAT_COL_START); + this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->hscroll.UpdateCapacity(delta.x / (int)this->resize.step_width); + this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + ((this->type == VEH_TRAIN ? 1 : this->hscroll.GetCapacity()) << MAT_COL_START); this->ResizeDepotButtons(); } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 1c220a0839..6287377d0e 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -237,20 +237,20 @@ public: default: NOT_REACHED(); case VEH_TRAIN: case VEH_ROAD: - this->vscroll2.cap = 9; - this->vscroll.cap = 6; + this->vscroll2.SetCapacity(9); + this->vscroll.SetCapacity(6); this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL; break; case VEH_SHIP: case VEH_AIRCRAFT: - this->vscroll2.cap = 9; - this->vscroll.cap = 4; + this->vscroll2.SetCapacity(9); + this->vscroll.SetCapacity(4); this->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG; break; } - this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << MAT_ROW_START) + (1 << MAT_COL_START); - this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START); + this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); + this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); switch (this->vehicle_type) { default: NOT_REACHED(); @@ -348,8 +348,8 @@ public: this->BuildGroupList(owner); this->groups.Sort(&GroupNameSorter); - SetVScroll2Count(this, this->groups.Length()); - SetVScrollCount(this, this->vehicles.Length()); + this->vscroll2.SetCount(this->groups.Length()); + this->vscroll.SetCount(this->vehicles.Length()); /* The drop down menu is out, *but* it may not be used, retract it. */ if (this->vehicles.Length() == 0 && this->IsWidgetLowered(GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN)) { @@ -416,8 +416,8 @@ public: DrawString(this->widget[GRP_WIDGET_LIST_GROUP].left + 10, this->widget[GRP_WIDGET_LIST_GROUP].right, y1, STR_GROUP_DEFAULT_TRAINS + this->vehicle_type, IsDefaultGroupID(this->group_sel) ? TC_WHITE : TC_BLACK); - max = min(this->vscroll2.pos + this->vscroll2.cap, this->groups.Length()); - for (i = this->vscroll2.pos ; i < max ; ++i) { + max = min(this->vscroll2.GetPosition() + this->vscroll2.GetCapacity(), this->groups.Length()); + for (i = this->vscroll2.GetPosition() ; i < max ; ++i) { const Group *g = this->groups[i]; assert(g->owner == owner); @@ -469,9 +469,9 @@ public: case GRP_WIDGET_LIST_GROUP: { // Matrix Group uint16 id_g = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET - 26) / PLY_WND_PRC__SIZE_OF_ROW_TINY; - if (id_g >= this->vscroll2.cap) return; + if (id_g >= this->vscroll2.GetCapacity()) return; - id_g += this->vscroll2.pos; + id_g += this->vscroll2.GetPosition(); if (id_g >= this->groups.Length()) return; @@ -484,9 +484,9 @@ public: case GRP_WIDGET_LIST_VEHICLE: { // Matrix Vehicle uint32 id_v = (pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / (int)this->resize.step_height; - if (id_v >= this->vscroll.cap) return; // click out of bounds + if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds - id_v += this->vscroll.pos; + id_v += this->vscroll.GetPosition(); if (id_v >= this->vehicles.Length()) return; // click out of list bound @@ -568,9 +568,9 @@ public: this->SetDirty(); - if (id_g >= this->vscroll2.cap) return; + if (id_g >= this->vscroll2.GetCapacity()) return; - id_g += this->vscroll2.pos; + id_g += this->vscroll2.GetPosition(); if (id_g >= this->groups.Length()) return; @@ -588,9 +588,9 @@ public: this->SetDirty(); - if (id_v >= this->vscroll.cap) return; // click out of bounds + if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds - id_v += this->vscroll.pos; + id_v += this->vscroll.GetPosition(); if (id_v >= this->vehicles.Length()) return; // click out of list bound @@ -614,11 +614,11 @@ public: virtual void OnResize(Point delta) { - this->vscroll2.cap += delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY; - this->vscroll.cap += delta.y / (int)this->resize.step_height; + this->vscroll2.UpdateCapacity(delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY); + this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); - this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << MAT_ROW_START) + (1 << MAT_COL_START); - this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START); + this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); + this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } virtual void OnDropdownSelect(int widget, int index) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6fbad77ba6..8c33d92823 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -193,7 +193,7 @@ public: this->timer_enabled = _loaded_newgrf_features.has_newindustries; - this->vscroll.cap = 8; // rows in grid, same in scroller + this->vscroll.SetCapacity(8); // rows in grid, same in scroller this->resize.step_height = 13; this->selected_index = -1; @@ -227,22 +227,22 @@ public: } this->SetWidgetDisabledState(DPIW_FUND_WIDGET, !this->enabled[this->selected_index]); - SetVScrollCount(this, this->count); + this->vscroll.SetCount(this->count); this->DrawWidgets(); /* and now with the matrix painting */ - for (byte i = 0; i < this->vscroll.cap && ((i + this->vscroll.pos) < this->count); i++) { + for (byte i = 0; i < this->vscroll.GetCapacity() && ((i + this->vscroll.GetPosition()) < this->count); i++) { int offset = i * 13; int x = 3; int y = 16; - bool selected = this->selected_index == i + this->vscroll.pos; + bool selected = this->selected_index == i + this->vscroll.GetPosition(); - if (this->index[i + this->vscroll.pos] == INVALID_INDUSTRYTYPE) { + if (this->index[i + this->vscroll.GetPosition()] == INVALID_INDUSTRYTYPE) { DrawString(20, right, y + offset, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE); continue; } - const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll.pos]); + const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll.GetPosition()]); /* Draw the name of the industry in white is selected, otherwise, in orange */ DrawString(20, right, y + offset, indsp->name, selected ? TC_WHITE : TC_ORANGE); @@ -320,7 +320,7 @@ public: switch (widget) { case DPIW_MATRIX_WIDGET: { const IndustrySpec *indsp; - int y = (pt.y - this->widget[DPIW_MATRIX_WIDGET].top) / 13 + this->vscroll.pos ; + int y = (pt.y - this->widget[DPIW_MATRIX_WIDGET].top) / 13 + this->vscroll.GetPosition() ; if (y >= 0 && y < count) { // Is it within the boundaries of available data? this->selected_index = y; @@ -363,8 +363,8 @@ public: virtual void OnResize(Point delta) { /* Adjust the number of items in the matrix depending of the rezise */ - this->vscroll.cap += delta.y / (int)this->resize.step_height; - this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START); + this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); + this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START); } virtual void OnPlaceObject(Point pt, TileIndex tile) @@ -801,7 +801,7 @@ protected: this->industries.Compact(); this->industries.RebuildDone(); - SetVScrollCount(this, this->industries.Length()); // Update scrollbar as well. + this->vscroll.SetCount(this->industries.Length()); // Update scrollbar as well. } this->last_industry = NULL; this->industries.Sort(); @@ -933,7 +933,7 @@ public: this->BuildSortIndustriesList(); this->InitNested(desc, 0); - this->vscroll.cap = this->nested_array[IDW_INDUSTRY_LIST]->current_y / this->resize.step_height; + this->vscroll.SetCapacity(this->nested_array[IDW_INDUSTRY_LIST]->current_y / this->resize.step_height); } ~IndustryDirectoryWindow() @@ -961,11 +961,11 @@ public: case IDW_INDUSTRY_LIST: { int n = 0; int y = r.top + WD_FRAMERECT_TOP; - for (uint i = this->vscroll.pos; i < this->industries.Length(); i++) { + for (uint i = this->vscroll.GetPosition(); i < this->industries.Length(); i++) { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, this->GetIndustryString(this->industries[i])); y += this->resize.step_height; - if (++n == this->vscroll.cap) break; // max number of industries in 1 window + if (++n == this->vscroll.GetCapacity()) break; // max number of industries in 1 window } } break; } @@ -1024,8 +1024,8 @@ public: int y = (pt.y - this->nested_array[widget]->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; uint16 p; - if (!IsInsideMM(y, 0, this->vscroll.cap)) return; - p = y + this->vscroll.pos; + if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return; + p = y + this->vscroll.GetPosition(); if (p < this->industries.Length()) { if (_ctrl_pressed) { ShowExtraViewPortWindow(this->industries[p]->xy); @@ -1047,7 +1047,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.cap += delta.y / (int)this->resize.step_height; + this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height); } virtual void OnHundredthTick()