summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-02 07:17:15 +0000
committerrubidium <rubidium@openttd.org>2009-09-02 07:17:15 +0000
commite69e3378b02b143f646dcd4ea3542dd1fb4bd7aa (patch)
treeb499099e506adb7e26325b96a7051f310131769c /src
parent4b9b85812781d4e1c23e503bde4ed5de9cdabca4 (diff)
downloadopenttd-e69e3378b02b143f646dcd4ea3542dd1fb4bd7aa.tar.xz
(svn r17367) -Codechange: make the autoreplace, bridge and build vehicle GUIs use the scrollbar wrappers
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_gui.cpp30
-rw-r--r--src/bridge_gui.cpp29
-rw-r--r--src/build_vehicle_gui.cpp14
-rw-r--r--src/window_gui.h2
4 files changed, 38 insertions, 37 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 357a28474..49c00f4fe 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -176,7 +176,7 @@ class ReplaceVehicleWindow : public Window {
if (this->update_left == true) {
/* We need to rebuild the left list */
GenerateReplaceVehList(this, true);
- SetVScrollCount(this, this->list[0].Length());
+ this->vscroll.SetCount(this->list[0].Length());
if (this->init_lists && this->sel_engine[0] == INVALID_ENGINE && this->list[0].Length() != 0) {
this->sel_engine[0] = this->list[0][0];
}
@@ -190,7 +190,7 @@ class ReplaceVehicleWindow : public Window {
this->sel_engine[1] = INVALID_ENGINE;
} else {
GenerateReplaceVehList(this, false);
- SetVScroll2Count(this, this->list[1].Length());
+ this->vscroll2.SetCount(this->list[1].Length());
if (this->init_lists && this->sel_engine[1] == INVALID_ENGINE && this->list[1].Length() != 0) {
this->sel_engine[1] = this->list[1][0];
}
@@ -213,10 +213,10 @@ public:
this->sel_engine[1] = INVALID_ENGINE;
this->resize.step_height = GetVehicleListHeight(vehicletype);
- this->vscroll.cap = this->resize.step_height == 14 ? 8 : 4;
+ this->vscroll.SetCapacity(this->resize.step_height == 14 ? 8 : 4);
Widget *widget = this->widget;
- widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+ widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
if (vehicletype != VEH_TRAIN) {
/* Since it's not a train we will hide the train only widgets. */
@@ -229,7 +229,7 @@ public:
WIDGET_LIST_END);
}
- ResizeWindow(this, 0, this->resize.step_height * this->vscroll.cap);
+ ResizeWindow(this, 0, this->resize.step_height * this->vscroll.GetCapacity());
/* Set the minimum window size to the current window size */
this->resize.width = this->width;
@@ -237,7 +237,7 @@ public:
this->owner = _local_company;
this->sel_group = id_g;
- this->vscroll2.cap = this->vscroll.cap; // these two are always the same
+ this->vscroll2.SetCapacity(this->vscroll.GetCapacity()); // these two are always the same
this->FindWindowPlacementAndResize(desc);
}
@@ -311,8 +311,8 @@ public:
for (byte i = 0; i < 2; i++) {
uint widget = (i == 0) ? RVW_WIDGET_LEFT_MATRIX : RVW_WIDGET_RIGHT_MATRIX;
GUIEngineList *list = &this->list[i]; // which list to draw
- EngineID start = i == 0 ? this->vscroll.pos : this->vscroll2.pos; // what is the offset for the start (scrolling)
- EngineID end = min((i == 0 ? this->vscroll.cap : this->vscroll2.cap) + start, list->Length());
+ EngineID start = i == 0 ? this->vscroll.GetPosition() : this->vscroll2.GetPosition(); // what is the offset for the start (scrolling)
+ EngineID end = min((i == 0 ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity()) + start, list->Length());
/* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, this->widget[widget].left + 2, this->widget[widget].right, this->widget[widget].top + 1, list, start, end, this->sel_engine[i], i == 0 ? this->widget[RVW_WIDGET_LEFT_MATRIX].right - 2 : 0, selected_group);
@@ -374,8 +374,8 @@ public:
case RVW_WIDGET_LEFT_MATRIX:
case RVW_WIDGET_RIGHT_MATRIX: {
uint i = (pt.y - 14) / this->resize.step_height;
- uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.pos : this->vscroll2.pos;
- uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.cap : this->vscroll2.cap;
+ uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetPosition() : this->vscroll2.GetPosition();
+ uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity();
byte click_side = widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1;
size_t engine_count = this->list[click_side].Length();
@@ -401,8 +401,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.pos = 0;
- this->vscroll2.pos = 0;
+ this->vscroll.SetPosition(0);
+ this->vscroll2.SetPosition(0);
/* Rebuild the lists */
this->update_left = true;
this->update_right = true;
@@ -411,12 +411,12 @@ public:
}
virtual void OnResize(Point delta) {
- this->vscroll.cap += delta.y / (int)this->resize.step_height;
- this->vscroll2.cap += delta.y / (int)this->resize.step_height;
+ this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height);
+ this->vscroll2.UpdateCapacity(delta.y / (int)this->resize.step_height);
Widget *widget = this->widget;
- widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+ widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
if (delta.x != 0) {
/* We changed the width of the window so we have to resize the lists.
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index aa385a6cc..590f6f48e 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -143,16 +143,16 @@ public:
this->bridges->NeedResort();
this->SortBridgeList();
- this->vscroll.count = bl->Length();
- this->vscroll.cap = this->nested_array[BBSW_BRIDGE_LIST]->current_y / this->resize.step_height;
- if (this->last_size < this->vscroll.cap) this->last_size = this->vscroll.cap;
- if (this->last_size > this->vscroll.count) this->last_size = this->vscroll.count;
+ this->vscroll.SetCount(bl->Length());
+ this->vscroll.SetCapacity(this->nested_array[BBSW_BRIDGE_LIST]->current_y / this->resize.step_height);
+ if (this->last_size < this->vscroll.GetCapacity()) this->last_size = this->vscroll.GetCapacity();
+ if (this->last_size > this->vscroll.GetCount()) this->last_size = this->vscroll.GetCount();
/* Resize the bridge selection window if we used a bigger one the last time. */
- if (this->last_size > this->vscroll.cap) {
- ResizeWindow(this, 0, (this->last_size - this->vscroll.cap) * this->resize.step_height);
- this->vscroll.cap = this->last_size;
+ if (this->last_size > this->vscroll.GetCapacity()) {
+ ResizeWindow(this, 0, (this->last_size - this->vscroll.GetCapacity()) * this->resize.step_height);
+ this->vscroll.SetCapacity(this->last_size);
}
- this->nested_array[BBSW_BRIDGE_LIST]->widget_data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+ this->nested_array[BBSW_BRIDGE_LIST]->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
~BuildBridgeWindow()
@@ -220,7 +220,7 @@ public:
case BBSW_BRIDGE_LIST: {
uint y = r.top;
- for (int i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < (int)this->bridges->Length(); i++) {
+ for (int i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < (int)this->bridges->Length(); i++) {
const BridgeSpec *b = this->bridges->Get(i)->spec;
SetDParam(2, this->bridges->Get(i)->cost);
@@ -254,8 +254,8 @@ public:
default: break;
case BBSW_BRIDGE_LIST: {
uint i = ((int)pt.y - this->nested_array[BBSW_BRIDGE_LIST]->pos_y) / this->resize.step_height;
- if (i < this->vscroll.cap) {
- i += this->vscroll.pos;
+ if (i < this->vscroll.GetCapacity()) {
+ i += this->vscroll.GetPosition();
if (i < this->bridges->Length()) {
this->BuildBridge(i);
delete this;
@@ -285,11 +285,10 @@ public:
virtual void OnResize(Point delta)
{
- this->vscroll.cap += delta.y / (int)this->resize.step_height;
- this->nested_array[BBSW_BRIDGE_LIST]->widget_data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
- SetVScrollCount(this, this->bridges->Length());
+ this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height);
+ this->nested_array[BBSW_BRIDGE_LIST]->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
- this->last_size = max(this->vscroll.cap, this->last_size);
+ this->last_size = max(this->vscroll.GetCapacity(), this->last_size);
}
};
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 84ca486bb..7a5b1ba97 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -785,7 +785,7 @@ struct BuildVehicleWindow : Window {
ResizeWindow(this, 0, vlh - 14);
this->resize.step_height = vlh;
- this->vscroll.cap = 1;
+ this->vscroll.SetCapacity(1);
this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (1 << MAT_ROW_START) | (1 << MAT_COL_START);
this->resize.width = this->width;
@@ -1052,7 +1052,7 @@ struct BuildVehicleWindow : Window {
break;
case BUILD_VEHICLE_WIDGET_LIST: {
- uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.pos;
+ uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.GetPosition();
size_t num_items = this->eng_list.Length();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
this->SetDirty();
@@ -1104,9 +1104,9 @@ struct BuildVehicleWindow : Window {
{
this->GenerateBuildList();
- uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.Length());
+ uint max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->eng_list.Length());
- SetVScrollCount(this, this->eng_list.Length());
+ this->vscroll.SetCount(this->eng_list.Length());
if (this->vehicle_type == VEH_TRAIN) {
if (this->filter.railtype == RAILTYPE_END) {
SetDParam(0, STR_BUILD_VEHICLE_TRAIN_ALL_CAPTION);
@@ -1124,7 +1124,7 @@ struct BuildVehicleWindow : Window {
this->DrawWidgets();
- DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].right, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.pos, max, this->sel_engine, 0, DEFAULT_GROUP);
+ DrawEngineList(this->vehicle_type, this->widget[BUILD_VEHICLE_WIDGET_LIST].left + 2, this->widget[BUILD_VEHICLE_WIDGET_LIST].right, this->widget[BUILD_VEHICLE_WIDGET_LIST].top + 1, &this->eng_list, this->vscroll.GetPosition(), max, this->sel_engine, 0, DEFAULT_GROUP);
if (this->sel_engine != INVALID_ENGINE) {
const Widget *wi = &this->widget[BUILD_VEHICLE_WIDGET_PANEL];
@@ -1186,8 +1186,8 @@ struct BuildVehicleWindow : Window {
}
if (delta.y == 0) return;
- this->vscroll.cap += delta.y / (int)GetVehicleListHeight(this->vehicle_type);
- this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+ this->vscroll.UpdateCapacity(delta.y / (int)GetVehicleListHeight(this->vehicle_type));
+ this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
}
};
diff --git a/src/window_gui.h b/src/window_gui.h
index 2276092cb..312b954bf 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -264,6 +264,7 @@ public:
*/
void UpdateCapacity(int difference)
{
+ if (difference == 0) return;
this->SetCapacity(this->cap + difference);
}
@@ -285,6 +286,7 @@ public:
*/
void UpdatePosition(int difference)
{
+ if (difference == 0) return;
this->SetPosition(Clamp(this->pos + difference, 0, this->count - this->cap));
}
};