(svn r17373) -Codechange: make the timetable, station and subsidy GUIs use scrollbar wrappers

This commit is contained in:
rubidium 2009-09-02 08:40:31 +00:00
parent 1dfa38bb1f
commit 7aa9f8e3fb
3 changed files with 43 additions and 42 deletions

View File

@ -173,6 +173,8 @@ protected:
this->stations.Compact(); this->stations.Compact();
this->stations.RebuildDone(); this->stations.RebuildDone();
this->vscroll.SetCount(this->stations.Length()); // Update the scrollbar
} }
/** Sort stations by their name */ /** Sort stations by their name */
@ -259,7 +261,7 @@ public:
CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
{ {
this->owner = (Owner)this->window_number; this->owner = (Owner)this->window_number;
this->vscroll.cap = 12; this->vscroll.SetCapacity(12);
this->resize.step_height = 10; this->resize.step_height = 10;
this->resize.height = this->height - 10 * 7; // minimum if 5 in the list this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
@ -335,11 +337,9 @@ public:
this->BuildStationsList(owner); this->BuildStationsList(owner);
this->SortStationsList(); this->SortStationsList();
SetVScrollCount(this, this->stations.Length());
/* draw widgets, with company's name in the caption */ /* draw widgets, with company's name in the caption */
SetDParam(0, owner); SetDParam(0, owner);
SetDParam(1, this->vscroll.count); SetDParam(1, this->vscroll.GetCount());
this->DrawWidgets(); this->DrawWidgets();
@ -370,15 +370,15 @@ public:
cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1; cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
DrawString(71 + cg_ofst, 71 + cg_ofst + 12, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK); DrawString(71 + cg_ofst, 71 + cg_ofst + 12, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
if (this->vscroll.count == 0) { // company has no stations if (this->vscroll.GetCount() == 0) { // company has no stations
DrawString(xb, this->width, 40, STR_STATION_LIST_NONE); DrawString(xb, this->width, 40, STR_STATION_LIST_NONE);
return; return;
} }
int max = min(this->vscroll.pos + this->vscroll.cap, this->stations.Length()); int max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->stations.Length());
y = 40; // start of the list-widget y = 40; // start of the list-widget
for (int i = this->vscroll.pos; i < max; ++i) { // do until max number of stations of owner for (int i = this->vscroll.GetPosition(); i < max; ++i) { // do until max number of stations of owner
const Station *st = this->stations[i]; const Station *st = this->stations[i];
int x; int x;
@ -409,9 +409,9 @@ public:
case SLW_LIST: { case SLW_LIST: {
uint32 id_v = (pt.y - 41) / 10; uint32 id_v = (pt.y - 41) / 10;
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->stations.Length()) return; // click out of list bound if (id_v >= this->stations.Length()) return; // click out of list bound
@ -568,7 +568,7 @@ public:
virtual void OnResize(Point delta) virtual void OnResize(Point delta)
{ {
this->vscroll.cap += delta.y / 10; this->vscroll.UpdateCapacity(delta.y / 10);
} }
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data)
@ -789,7 +789,7 @@ struct StationViewWindow : public Window {
{ {
Owner owner = Station::Get(window_number)->owner; Owner owner = Station::Get(window_number)->owner;
if (owner != OWNER_NONE) this->owner = owner; if (owner != OWNER_NONE) this->owner = owner;
this->vscroll.cap = 5; this->vscroll.SetCapacity(5);
this->resize.step_height = 10; this->resize.step_height = 10;
this->FindWindowPlacementAndResize(desc); this->FindWindowPlacementAndResize(desc);
@ -852,7 +852,7 @@ struct StationViewWindow : public Window {
} }
} }
} }
SetVScrollCount(this, (int)cargolist.size() + 1); // update scrollbar this->vscroll.SetCount((int)cargolist.size() + 1); // update scrollbar
/* disable some buttons */ /* disable some buttons */
this->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_company); this->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_company);
@ -867,10 +867,10 @@ struct StationViewWindow : public Window {
int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
int y = 15; int y = 15;
int pos = this->vscroll.pos; ///< = this->vscroll.pos int pos = this->vscroll.GetPosition();
uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4; uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4;
int maxrows = this->vscroll.cap; int maxrows = this->vscroll.GetCapacity();
StringID str; StringID str;
@ -979,7 +979,7 @@ struct StationViewWindow : public Window {
{ {
switch (widget) { switch (widget) {
case SVW_WAITING: case SVW_WAITING:
this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.pos); this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.GetPosition());
break; break;
case SVW_LOCATION: case SVW_LOCATION:
@ -1053,7 +1053,7 @@ struct StationViewWindow : public Window {
virtual void OnResize(Point delta) virtual void OnResize(Point delta)
{ {
if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME); if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME);
this->vscroll.cap += delta.y / (int)this->resize.step_height; this->vscroll.UpdateCapacity(delta.y / (int)this->resize.step_height);
} }
}; };
@ -1224,7 +1224,7 @@ struct SelectStationWindow : Window {
select_station_cmd(cmd), select_station_cmd(cmd),
area(ta) area(ta)
{ {
this->vscroll.cap = 6; this->vscroll.SetCapacity(6);
this->resize.step_height = 10; this->resize.step_height = 10;
FindStationsNearby<T>(this->area, true); FindStationsNearby<T>(this->area, true);
@ -1235,19 +1235,19 @@ struct SelectStationWindow : Window {
virtual void OnPaint() virtual void OnPaint()
{ {
SetVScrollCount(this, _stations_nearby_list.Length() + 1); this->vscroll.SetCount(_stations_nearby_list.Length() + 1);
this->DrawWidgets(); this->DrawWidgets();
uint y = 17; uint y = 17;
if (this->vscroll.pos == 0) { if (this->vscroll.GetPosition() == 0) {
DrawString(3, this->widget[JSW_PANEL].right - 2, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION); DrawString(3, this->widget[JSW_PANEL].right - 2, y, T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CREATE_SPLITTED_WAYPOINT : STR_JOIN_STATION_CREATE_SPLITTED_STATION);
y += 10; y += 10;
} }
for (uint i = max<uint>(1, this->vscroll.pos); i <= _stations_nearby_list.Length(); ++i, y += 10) { for (uint i = max<uint>(1, this->vscroll.GetPosition()); i <= _stations_nearby_list.Length(); ++i, y += 10) {
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
if (i - this->vscroll.pos >= this->vscroll.cap) break; if (i - this->vscroll.GetPosition() >= this->vscroll.GetCapacity()) break;
const T *st = T::Get(_stations_nearby_list[i - 1]); const T *st = T::Get(_stations_nearby_list[i - 1]);
SetDParam(0, st->index); SetDParam(0, st->index);
@ -1260,7 +1260,7 @@ struct SelectStationWindow : Window {
{ {
if (widget != JSW_PANEL) return; if (widget != JSW_PANEL) return;
uint32 st_index = (pt.y - 16) / 10 + this->vscroll.pos; uint32 st_index = (pt.y - 16) / 10 + this->vscroll.GetPosition();
bool distant_join = (st_index > 0); bool distant_join = (st_index > 0);
if (distant_join) st_index--; if (distant_join) st_index--;
@ -1287,7 +1287,7 @@ struct SelectStationWindow : Window {
virtual void OnResize(Point delta) virtual void OnResize(Point delta)
{ {
this->vscroll.cap = (this->widget[JSW_PANEL].bottom - this->widget[JSW_PANEL].top) / 10; this->vscroll.UpdateCapacity((this->widget[JSW_PANEL].bottom - this->widget[JSW_PANEL].top) / 10);
} }
virtual void OnInvalidateData(int data) virtual void OnInvalidateData(int data)

View File

@ -41,7 +41,7 @@ struct SubsidyListWindow : Window {
{ {
this->InitNested(desc, window_number); this->InitNested(desc, window_number);
this->OnInvalidateData(0); this->OnInvalidateData(0);
this->vscroll.cap = this->nested_array[SLW_PANEL]->current_y / this->resize.step_height; this->vscroll.SetCapacity(this->nested_array[SLW_PANEL]->current_y / this->resize.step_height);
} }
virtual void OnClick(Point pt, int widget) virtual void OnClick(Point pt, int widget)
@ -49,9 +49,9 @@ struct SubsidyListWindow : Window {
if (widget != SLW_PANEL) return; if (widget != SLW_PANEL) return;
int y = (pt.y - this->nested_array[SLW_PANEL]->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height; int y = (pt.y - this->nested_array[SLW_PANEL]->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height;
if (!IsInsideMM(y, 0, this->vscroll.cap)) return; if (!IsInsideMM(y, 0, this->vscroll.GetCapacity())) return;
y += this->vscroll.pos; y += this->vscroll.GetPosition();
int num = 0; int num = 0;
const Subsidy *s; const Subsidy *s;
@ -168,17 +168,18 @@ struct SubsidyListWindow : Window {
int y = r.top + WD_FRAMERECT_TOP; int y = r.top + WD_FRAMERECT_TOP;
int x = r.left + WD_FRAMERECT_LEFT; int x = r.left + WD_FRAMERECT_LEFT;
int pos = -this->vscroll.pos; int pos = -this->vscroll.GetPosition();
const int cap = this->vscroll.GetCapacity();
/* Section for drawing the offered subisidies */ /* Section for drawing the offered subisidies */
if (IsInsideMM(pos, 0, this->vscroll.cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE); if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE);
pos++; pos++;
uint num = 0; uint num = 0;
const Subsidy *s; const Subsidy *s;
FOR_ALL_SUBSIDIES(s) { FOR_ALL_SUBSIDIES(s) {
if (!s->IsAwarded()) { if (!s->IsAwarded()) {
if (IsInsideMM(pos, 0, this->vscroll.cap)) { if (IsInsideMM(pos, 0, cap)) {
/* Displays the two offered towns */ /* Displays the two offered towns */
SetupSubsidyDecodeParam(s, 1); SetupSubsidyDecodeParam(s, 1);
SetDParam(7, _date - ymd.day + s->remaining * 32); SetDParam(7, _date - ymd.day + s->remaining * 32);
@ -190,19 +191,19 @@ struct SubsidyListWindow : Window {
} }
if (num == 0) { if (num == 0) {
if (IsInsideMM(pos, 0, this->vscroll.cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE);
pos++; pos++;
} }
/* Section for drawing the already granted subisidies */ /* Section for drawing the already granted subisidies */
pos++; pos++;
if (IsInsideMM(pos, 0, this->vscroll.cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_TITLE); if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_TITLE);
pos++; pos++;
num = 0; num = 0;
FOR_ALL_SUBSIDIES(s) { FOR_ALL_SUBSIDIES(s) {
if (s->IsAwarded()) { if (s->IsAwarded()) {
if (IsInsideMM(pos, 0, this->vscroll.cap)) { if (IsInsideMM(pos, 0, cap)) {
SetupSubsidyDecodeParam(s, 1); SetupSubsidyDecodeParam(s, 1);
SetDParam(7, s->awarded); SetDParam(7, s->awarded);
SetDParam(8, _date - ymd.day + s->remaining * 32); SetDParam(8, _date - ymd.day + s->remaining * 32);
@ -216,19 +217,19 @@ struct SubsidyListWindow : Window {
} }
if (num == 0) { if (num == 0) {
if (IsInsideMM(pos, 0, this->vscroll.cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE);
pos++; pos++;
} }
} }
virtual void OnResize(Point delta) 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 OnInvalidateData(int data) virtual void OnInvalidateData(int data)
{ {
SetVScrollCount(this, this->CountLines()); this->vscroll.SetCount(this->CountLines());
} }
}; };

View File

@ -59,7 +59,7 @@ struct TimetableWindow : Window {
{ {
this->vehicle = Vehicle::Get(window_number); this->vehicle = Vehicle::Get(window_number);
this->owner = this->vehicle->owner; this->owner = this->vehicle->owner;
this->vscroll.cap = 8; this->vscroll.SetCapacity(8);
this->resize.step_height = 10; this->resize.step_height = 10;
this->sel_index = -1; this->sel_index = -1;
@ -75,9 +75,9 @@ struct TimetableWindow : Window {
*/ */
int sel = (y - 15) / 10; int sel = (y - 15) / 10;
if ((uint)sel >= this->vscroll.cap) return INVALID_ORDER; if ((uint)sel >= this->vscroll.GetCapacity()) return INVALID_ORDER;
sel += this->vscroll.pos; sel += this->vscroll.GetPosition();
return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER; return (sel < v->GetNumOrders() * 2 && sel >= 0) ? sel : INVALID_ORDER;
} }
@ -148,7 +148,7 @@ struct TimetableWindow : Window {
const Vehicle *v = this->vehicle; const Vehicle *v = this->vehicle;
int selected = this->sel_index; int selected = this->sel_index;
SetVScrollCount(this, v->GetNumOrders() * 2); this->vscroll.SetCount(v->GetNumOrders() * 2);
if (v->owner == _local_company) { if (v->owner == _local_company) {
bool disable = true; bool disable = true;
@ -179,7 +179,7 @@ struct TimetableWindow : Window {
this->DrawWidgets(); this->DrawWidgets();
int y = 15; int y = 15;
int i = this->vscroll.pos; int i = this->vscroll.GetPosition();
VehicleOrderID order_id = (i + 1) / 2; VehicleOrderID order_id = (i + 1) / 2;
bool final_order = false; bool final_order = false;
@ -187,7 +187,7 @@ struct TimetableWindow : Window {
while (order != NULL) { while (order != NULL) {
/* Don't draw anything if it extends past the end of the window. */ /* Don't draw anything if it extends past the end of the window. */
if (i - this->vscroll.pos >= this->vscroll.cap) break; if (!this->vscroll.IsVisible(i)) break;
if (i % 2 == 0) { if (i % 2 == 0) {
DrawOrderString(v, order, order_id, y, i == selected, true, this->widget[TTV_TIMETABLE_PANEL].right - 4); DrawOrderString(v, order, order_id, y, i == selected, true, this->widget[TTV_TIMETABLE_PANEL].right - 4);
@ -335,7 +335,7 @@ struct TimetableWindow : Window {
virtual void OnResize(Point delta) virtual void OnResize(Point delta)
{ {
/* Update the scroll + matrix */ /* Update the scroll + matrix */
this->vscroll.cap = (this->widget[TTV_TIMETABLE_PANEL].bottom - this->widget[TTV_TIMETABLE_PANEL].top) / 10; this->vscroll.UpdateCapacity(delta.y / 10);
} }
}; };