From 7aa9f8e3fb29d70635d5cef8cc67133cf7718061 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 2 Sep 2009 08:40:31 +0000 Subject: (svn r17373) -Codechange: make the timetable, station and subsidy GUIs use scrollbar wrappers --- src/station_gui.cpp | 46 +++++++++++++++++++++++----------------------- src/subsidy_gui.cpp | 25 +++++++++++++------------ src/timetable_gui.cpp | 14 +++++++------- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 424e8e7c7..c2861429a 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -173,6 +173,8 @@ protected: this->stations.Compact(); this->stations.RebuildDone(); + + this->vscroll.SetCount(this->stations.Length()); // Update the scrollbar } /** Sort stations by their name */ @@ -259,7 +261,7 @@ public: CompanyStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) { this->owner = (Owner)this->window_number; - this->vscroll.cap = 12; + this->vscroll.SetCapacity(12); this->resize.step_height = 10; this->resize.height = this->height - 10 * 7; // minimum if 5 in the list @@ -335,11 +337,9 @@ public: this->BuildStationsList(owner); this->SortStationsList(); - SetVScrollCount(this, this->stations.Length()); - /* draw widgets, with company's name in the caption */ SetDParam(0, owner); - SetDParam(1, this->vscroll.count); + SetDParam(1, this->vscroll.GetCount()); this->DrawWidgets(); @@ -370,15 +370,15 @@ public: cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1; 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); 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 - 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]; int x; @@ -409,9 +409,9 @@ public: case SLW_LIST: { 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 @@ -568,7 +568,7 @@ public: virtual void OnResize(Point delta) { - this->vscroll.cap += delta.y / 10; + this->vscroll.UpdateCapacity(delta.y / 10); } virtual void OnInvalidateData(int data) @@ -789,7 +789,7 @@ struct StationViewWindow : public Window { { Owner owner = Station::Get(window_number)->owner; if (owner != OWNER_NONE) this->owner = owner; - this->vscroll.cap = 5; + this->vscroll.SetCapacity(5); this->resize.step_height = 10; 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 */ 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 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; - int maxrows = this->vscroll.cap; + int maxrows = this->vscroll.GetCapacity(); StringID str; @@ -979,7 +979,7 @@ struct StationViewWindow : public Window { { switch (widget) { 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; case SVW_LOCATION: @@ -1053,7 +1053,7 @@ struct StationViewWindow : public Window { virtual void OnResize(Point delta) { 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), area(ta) { - this->vscroll.cap = 6; + this->vscroll.SetCapacity(6); this->resize.step_height = 10; FindStationsNearby(this->area, true); @@ -1235,19 +1235,19 @@ struct SelectStationWindow : Window { virtual void OnPaint() { - SetVScrollCount(this, _stations_nearby_list.Length() + 1); + this->vscroll.SetCount(_stations_nearby_list.Length() + 1); this->DrawWidgets(); 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); y += 10; } - for (uint i = max(1, this->vscroll.pos); i <= _stations_nearby_list.Length(); ++i, y += 10) { + for (uint i = max(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. */ - 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]); SetDParam(0, st->index); @@ -1260,7 +1260,7 @@ struct SelectStationWindow : Window { { 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); if (distant_join) st_index--; @@ -1287,7 +1287,7 @@ struct SelectStationWindow : Window { 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) diff --git a/src/subsidy_gui.cpp b/src/subsidy_gui.cpp index a57f87584..fec94b8bc 100644 --- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -41,7 +41,7 @@ struct SubsidyListWindow : Window { { this->InitNested(desc, window_number); 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) @@ -49,9 +49,9 @@ struct SubsidyListWindow : Window { if (widget != SLW_PANEL) return; 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; const Subsidy *s; @@ -168,17 +168,18 @@ struct SubsidyListWindow : Window { int y = r.top + WD_FRAMERECT_TOP; 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 */ - 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++; uint num = 0; const Subsidy *s; FOR_ALL_SUBSIDIES(s) { if (!s->IsAwarded()) { - if (IsInsideMM(pos, 0, this->vscroll.cap)) { + if (IsInsideMM(pos, 0, cap)) { /* Displays the two offered towns */ SetupSubsidyDecodeParam(s, 1); SetDParam(7, _date - ymd.day + s->remaining * 32); @@ -190,19 +191,19 @@ struct SubsidyListWindow : Window { } 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++; } /* Section for drawing the already granted subisidies */ 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++; num = 0; FOR_ALL_SUBSIDIES(s) { if (s->IsAwarded()) { - if (IsInsideMM(pos, 0, this->vscroll.cap)) { + if (IsInsideMM(pos, 0, cap)) { SetupSubsidyDecodeParam(s, 1); SetDParam(7, s->awarded); SetDParam(8, _date - ymd.day + s->remaining * 32); @@ -216,19 +217,19 @@ struct SubsidyListWindow : Window { } 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++; } } 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) { - SetVScrollCount(this, this->CountLines()); + this->vscroll.SetCount(this->CountLines()); } }; diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 10ced998b..46db9d703 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -59,7 +59,7 @@ struct TimetableWindow : Window { { this->vehicle = Vehicle::Get(window_number); this->owner = this->vehicle->owner; - this->vscroll.cap = 8; + this->vscroll.SetCapacity(8); this->resize.step_height = 10; this->sel_index = -1; @@ -75,9 +75,9 @@ struct TimetableWindow : Window { */ 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; } @@ -148,7 +148,7 @@ struct TimetableWindow : Window { const Vehicle *v = this->vehicle; int selected = this->sel_index; - SetVScrollCount(this, v->GetNumOrders() * 2); + this->vscroll.SetCount(v->GetNumOrders() * 2); if (v->owner == _local_company) { bool disable = true; @@ -179,7 +179,7 @@ struct TimetableWindow : Window { this->DrawWidgets(); int y = 15; - int i = this->vscroll.pos; + int i = this->vscroll.GetPosition(); VehicleOrderID order_id = (i + 1) / 2; bool final_order = false; @@ -187,7 +187,7 @@ struct TimetableWindow : Window { while (order != NULL) { /* 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) { 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) { /* 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); } }; -- cgit v1.2.3-54-g00ecf