(svn r17367) -Codechange: make the autoreplace, bridge and build vehicle GUIs use the scrollbar wrappers

This commit is contained in:
rubidium 2009-09-02 07:17:15 +00:00
parent 4b9b858127
commit e69e3378b0
4 changed files with 38 additions and 37 deletions

View File

@ -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.

View File

@ -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);
}
};

View File

@ -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);
}
};

View File

@ -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));
}
};