summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rail_gui.cpp34
-rw-r--r--src/settings_gui.cpp14
-rw-r--r--src/signs_gui.cpp18
3 files changed, 32 insertions, 34 deletions
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index a44eed5a5..0c97b4d5e 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -1024,9 +1024,9 @@ public:
if (newstation) {
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
- this->vscroll.count = _railstation.station_count;
- this->vscroll.cap = GB(this->nested_array[BRSW_NEWST_LIST]->widget_data, MAT_ROW_START, MAT_ROW_BITS);
- this->vscroll.pos = Clamp(_railstation.station_type - 2, 0, this->vscroll.count - this->vscroll.cap);
+ this->vscroll.SetCount(_railstation.station_count);
+ this->vscroll.SetCapacity(GB(this->nested_array[BRSW_NEWST_LIST]->widget_data, MAT_ROW_START, MAT_ROW_BITS));
+ this->vscroll.SetPosition(Clamp(_railstation.station_type - 2, 0, this->vscroll.GetCount() - this->vscroll.GetCapacity()));
} else {
/* New stations are not available, so ensure the default station
* type is 'selected'. */
@@ -1150,7 +1150,7 @@ public:
case BRSW_NEWST_LIST: {
uint y = r.top;
- for (uint16 i = this->vscroll.pos; i < _railstation.station_count && i < (uint)(this->vscroll.pos + this->vscroll.cap); i++) {
+ for (uint16 i = this->vscroll.GetPosition(); i < _railstation.station_count && this->vscroll.IsVisible(i); i++) {
const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i);
StringID str = STR_STATION_CLASS_DFLT;
@@ -1308,8 +1308,8 @@ public:
const StationSpec *statspec;
int y = (pt.y - this->nested_array[BRSW_NEWST_LIST]->pos_y) / this->line_height;
- if (y >= this->vscroll.cap) return;
- y += this->vscroll.pos;
+ if (y >= this->vscroll.GetCapacity()) return;
+ y += this->vscroll.GetPosition();
if (y >= _railstation.station_count) return;
/* Check station availability callback */
@@ -1339,8 +1339,8 @@ public:
this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
- this->vscroll.count = _railstation.station_count;
- this->vscroll.pos = _railstation.station_type;
+ this->vscroll.SetCount(_railstation.station_count);
+ this->vscroll.SetPosition(_railstation.station_type);
}
SndPlayFx(SND_15_BEEP);
@@ -1775,24 +1775,24 @@ struct BuildRailWaypointWindow : PickerWindowBase {
BuildRailWaypointWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
{
this->InitNested(desc, TRANSPORT_RAIL);
- this->hscroll.cap = 5;
- this->hscroll.count = _waypoint_count;
+ this->hscroll.SetCapacity(5);
+ this->hscroll.SetCount(_waypoint_count);
};
virtual void OnPaint()
{
- for (uint i = 0; i < this->hscroll.cap; i++) {
- this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.pos + i) == _cur_waypoint_type);
+ for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
+ this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.GetPosition() + i) == _cur_waypoint_type);
}
this->DrawWidgets();
- for (uint i = 0; i < this->hscroll.cap; i++) {
- if (this->hscroll.pos + i < this->hscroll.count) {
- const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.pos + i);
+ for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
+ if (this->hscroll.GetPosition() + i < this->hscroll.GetCount()) {
+ const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.GetPosition() + i);
int bottom = this->nested_array[BRWW_WAYPOINT_1 + i]->pos_y + this->nested_array[BRWW_WAYPOINT_1 + i]->current_y;
- DrawWaypointSprite(this->nested_array[BRWW_WAYPOINT_1 + i]->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll.pos + i, _cur_railtype);
+ DrawWaypointSprite(this->nested_array[BRWW_WAYPOINT_1 + i]->pos_x + TILE_PIXELS, bottom - TILE_PIXELS, this->hscroll.GetPosition() + i, _cur_railtype);
if (statspec != NULL &&
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
@@ -1811,7 +1811,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
case BRWW_WAYPOINT_3:
case BRWW_WAYPOINT_4:
case BRWW_WAYPOINT_5: {
- byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.pos;
+ byte type = widget - BRWW_WAYPOINT_1 + this->hscroll.GetPosition();
/* Check station availability callback */
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 183f6b51a..9610b833a 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1448,9 +1448,8 @@ struct GameSettingsWindow : Window {
this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
this->clicked_entry = NULL; // No numeric setting buttons are depressed
- this->vscroll.pos = 0;
- this->vscroll.cap = (this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
- SetVScrollCount(this, _settings_main_page.Length());
+ this->vscroll.SetCapacity((this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT);
+ this->vscroll.SetCount(_settings_main_page.Length());
this->resize.step_height = SETTING_HEIGHT;
this->resize.height = this->height;
@@ -1464,7 +1463,7 @@ struct GameSettingsWindow : Window {
{
this->DrawWidgets();
_settings_main_page.Draw(settings_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
- this->width - 13, this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
+ this->width - 13, this->vscroll.GetPosition(), this->vscroll.GetPosition() + this->vscroll.GetCapacity());
}
virtual void OnClick(Point pt, int widget)
@@ -1474,7 +1473,7 @@ struct GameSettingsWindow : Window {
int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
if (y < 0) return; // Clicked above first entry
- byte btn = this->vscroll.pos + y / SETTING_HEIGHT; // Compute which setting is selected
+ byte btn = this->vscroll.GetPosition() + y / SETTING_HEIGHT; // Compute which setting is selected
if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting
uint cur_row = 0;
@@ -1488,7 +1487,7 @@ struct GameSettingsWindow : Window {
if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
- SetVScrollCount(this, _settings_main_page.Length());
+ this->vscroll.SetCount(_settings_main_page.Length());
this->SetDirty();
return;
}
@@ -1608,8 +1607,7 @@ struct GameSettingsWindow : Window {
virtual void OnResize(Point delta)
{
- this->vscroll.cap += delta.y / SETTING_HEIGHT;
- SetVScrollCount(this, _settings_main_page.Length());
+ this->vscroll.UpdateCapacity(delta.y / SETTING_HEIGHT);
}
};
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index 1824a7ee3..5c67173fc 100644
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -90,7 +90,7 @@ enum SignListWidgets {
struct SignListWindow : Window, SignList {
SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, 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
@@ -105,20 +105,20 @@ struct SignListWindow : Window, SignList {
BuildSignsList();
SortSignsList();
- SetVScrollCount(this, this->signs.Length());
+ this->vscroll.SetCount(this->signs.Length()); // Update the scrollbar
- SetDParam(0, this->vscroll.count);
+ SetDParam(0, this->vscroll.GetCount());
this->DrawWidgets();
/* No signs? */
int y = this->widget[SLW_LIST].top + 2; // offset from top of widget
- if (this->vscroll.count == 0) {
+ if (this->vscroll.GetCount() == 0) {
DrawString(this->widget[SLW_LIST].left + 2, this->widget[SLW_LIST].right, y, STR_STATION_LIST_NONE);
return;
}
/* Start drawing the signs */
- for (uint16 i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < this->vscroll.count; i++) {
+ for (uint16 i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->vscroll.GetCount(); i++) {
const Sign *si = this->signs[i];
if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, this->widget[SLW_LIST].left + 4, y + 1);
@@ -134,9 +134,9 @@ struct SignListWindow : Window, SignList {
if (widget == SLW_LIST) {
uint32 id_v = (pt.y - this->widget[SLW_LIST].top - 1) / 10;
- if (id_v >= this->vscroll.cap) return;
- id_v += this->vscroll.pos;
- if (id_v >= this->vscroll.count) return;
+ if (id_v >= this->vscroll.GetCapacity()) return;
+ id_v += this->vscroll.GetPosition();
+ if (id_v >= this->vscroll.GetCount()) return;
const Sign *si = this->signs[id_v];
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
@@ -145,7 +145,7 @@ struct SignListWindow : Window, SignList {
virtual void OnResize(Point delta)
{
- this->vscroll.cap += delta.y / 10;
+ this->vscroll.UpdateCapacity(delta.y / 10);
}
virtual void OnInvalidateData(int data)