summaryrefslogtreecommitdiff
path: root/src/depot_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-08-12 08:37:01 +0000
committerfrosch <frosch@openttd.org>2010-08-12 08:37:01 +0000
commit71ca58c2bb1b72a088acec5b70423a43512ec195 (patch)
treeb0e875a8626ce26d7fed7597328409f2cb937dbe /src/depot_gui.cpp
parent10339c60c0e53ccc90f0cc379763be6582d87bf2 (diff)
downloadopenttd-71ca58c2bb1b72a088acec5b70423a43512ec195.tar.xz
(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.
Diffstat (limited to 'src/depot_gui.cpp')
-rw-r--r--src/depot_gui.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 050632e4a..ac1d48a40 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -222,6 +222,8 @@ struct DepotWindow : Window {
bool generate_list;
VehicleList vehicle_list;
VehicleList wagon_list;
+ Scrollbar *hscroll; ///< Only for trains.
+ Scrollbar *vscroll;
DepotWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window()
{
@@ -233,6 +235,8 @@ struct DepotWindow : Window {
this->type = type;
this->CreateNestedTree(desc);
+ this->hscroll = (this->type == VEH_TRAIN ? this->GetScrollbar(DEPOT_WIDGET_H_SCROLL) : NULL);
+ this->vscroll = this->GetScrollbar(DEPOT_WIDGET_V_SCROLL);
/* Don't show 'rename button' of aircraft hangar */
this->GetWidget<NWidgetStacked>(DEPOT_WIDGET_SHOW_RENAME)->SetDisplayedPlane(type == VEH_AIRCRAFT ? SZSP_NONE : 0);
this->SetupWidgetData(type);
@@ -271,7 +275,7 @@ struct DepotWindow : Window {
uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
- this->sel, free_wagon ? 0 : this->hscroll.GetPosition(), this->vehicle_over);
+ this->sel, free_wagon ? 0 : this->hscroll->GetPosition(), this->vehicle_over);
/* Number of wagons relative to a standard length wagon (rounded up) */
SetDParam(0, CeilDiv(u->tcache.cached_total_length, 8));
@@ -325,7 +329,7 @@ struct DepotWindow : Window {
uint16 rows_in_display = GB(mat_data, MAT_ROW_START, MAT_ROW_BITS);
uint16 boxes_in_each_row = GB(mat_data, MAT_COL_START, MAT_COL_BITS);
- uint16 num = this->vscroll.GetPosition() * boxes_in_each_row;
+ uint16 num = this->vscroll->GetPosition() * boxes_in_each_row;
int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
int y;
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
@@ -341,7 +345,7 @@ struct DepotWindow : Window {
}
}
- maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.GetPosition() * 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 += this->resize.step_height) {
@@ -384,15 +388,15 @@ struct DepotWindow : Window {
} else {
xt = x / this->resize.step_width;
xm = x % this->resize.step_width;
- if (xt >= this->hscroll.GetCapacity()) return MODE_ERROR;
+ if (xt >= this->hscroll->GetCapacity()) return MODE_ERROR;
}
ym = y % this->resize.step_height;
uint row = y / this->resize.step_height;
- if (row >= this->vscroll.GetCapacity()) return MODE_ERROR;
+ if (row >= this->vscroll->GetCapacity()) return MODE_ERROR;
uint boxes_in_each_row = GB(matrix_widget->widget_data, MAT_COL_START, MAT_COL_BITS);
- uint pos = ((row + this->vscroll.GetPosition()) * boxes_in_each_row) + xt;
+ uint pos = ((row + this->vscroll->GetPosition()) * boxes_in_each_row) + xt;
if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
/* Clicking on 'line' / 'block' without a vehicle */
@@ -410,7 +414,7 @@ struct DepotWindow : Window {
if (this->vehicle_list.Length() > pos) {
*veh = this->vehicle_list[pos];
/* Skip vehicles that are scrolled off the list */
- x += this->hscroll.GetPosition();
+ x += this->hscroll->GetPosition();
} else {
pos -= this->vehicle_list.Length();
*veh = this->wagon_list[pos];
@@ -693,10 +697,10 @@ struct DepotWindow : Window {
max_width = max(max_width, width);
}
/* Always have 1 empty row, so people can change the setting of the train */
- this->vscroll.SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
- this->hscroll.SetCount(max_width);
+ this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
+ this->hscroll->SetCount(max_width);
} else {
- this->vscroll.SetCount(CeilDiv(this->vehicle_list.Length(), this->hscroll.GetCapacity()));
+ this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->hscroll->GetCapacity()));
}
/* Setup disabled buttons. */
@@ -1005,13 +1009,13 @@ struct DepotWindow : Window {
virtual void OnResize()
{
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX);
- this->vscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
+ this->vscroll->SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
if (this->type == VEH_TRAIN) {
- this->hscroll.SetCapacity(nwi->current_x - this->header_width - this->count_width);
- nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
+ this->hscroll->SetCapacity(nwi->current_x - this->header_width - this->count_width);
+ nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
} else {
- this->hscroll.SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
- nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
+ this->hscroll->SetCapacityFromWidget(this, DEPOT_WIDGET_MATRIX);
+ nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (this->hscroll->GetCapacity() << MAT_COL_START);
}
}