Mercurial > hg > openttd
changeset 12881:06daf47f0ab2 draft
(svn r17373) -Codechange: make the timetable, station and subsidy GUIs use scrollbar wrappers
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 02 Sep 2009 08:40:31 +0000 |
parents | 09381837656b |
children | 0d902cefe84b |
files | src/station_gui.cpp src/subsidy_gui.cpp src/timetable_gui.cpp |
diffstat | 3 files changed, 43 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -173,6 +173,8 @@ this->stations.Compact(); this->stations.RebuildDone(); + + this->vscroll.SetCount(this->stations.Length()); // Update the scrollbar } /** Sort stations by their name */ @@ -259,7 +261,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ } } } - 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 @@ 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 @@ { 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 @@ 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 @@ select_station_cmd(cmd), area(ta) { - this->vscroll.cap = 6; + this->vscroll.SetCapacity(6); this->resize.step_height = 10; FindStationsNearby<T>(this->area, true); @@ -1235,19 +1235,19 @@ 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<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. */ - 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 @@ { 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 @@ 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)
--- a/src/subsidy_gui.cpp +++ b/src/subsidy_gui.cpp @@ -41,7 +41,7 @@ { 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 @@ 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 @@ 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 @@ } 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 @@ } 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()); } };
--- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -59,7 +59,7 @@ { 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 @@ */ 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 @@ 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 @@ 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 @@ 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 @@ 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); } };