mirror of https://github.com/OpenTTD/OpenTTD
(svn r17372) -Codechange: make the settings, rail and sign GUIs use the scrollbar wrappers
parent
7aeaa4f132
commit
1dfa38bb1f
|
@ -1024,9 +1024,9 @@ public:
|
||||||
if (newstation) {
|
if (newstation) {
|
||||||
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
|
_railstation.station_count = GetNumCustomStations(_railstation.station_class);
|
||||||
|
|
||||||
this->vscroll.count = _railstation.station_count;
|
this->vscroll.SetCount(_railstation.station_count);
|
||||||
this->vscroll.cap = GB(this->nested_array[BRSW_NEWST_LIST]->widget_data, MAT_ROW_START, MAT_ROW_BITS);
|
this->vscroll.SetCapacity(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.SetPosition(Clamp(_railstation.station_type - 2, 0, this->vscroll.GetCount() - this->vscroll.GetCapacity()));
|
||||||
} else {
|
} else {
|
||||||
/* New stations are not available, so ensure the default station
|
/* New stations are not available, so ensure the default station
|
||||||
* type is 'selected'. */
|
* type is 'selected'. */
|
||||||
|
@ -1150,7 +1150,7 @@ public:
|
||||||
|
|
||||||
case BRSW_NEWST_LIST: {
|
case BRSW_NEWST_LIST: {
|
||||||
uint y = r.top;
|
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);
|
const StationSpec *statspec = GetCustomStationSpec(_railstation.station_class, i);
|
||||||
|
|
||||||
StringID str = STR_STATION_CLASS_DFLT;
|
StringID str = STR_STATION_CLASS_DFLT;
|
||||||
|
@ -1308,8 +1308,8 @@ public:
|
||||||
const StationSpec *statspec;
|
const StationSpec *statspec;
|
||||||
int y = (pt.y - this->nested_array[BRSW_NEWST_LIST]->pos_y) / this->line_height;
|
int y = (pt.y - this->nested_array[BRSW_NEWST_LIST]->pos_y) / this->line_height;
|
||||||
|
|
||||||
if (y >= this->vscroll.cap) return;
|
if (y >= this->vscroll.GetCapacity()) return;
|
||||||
y += this->vscroll.pos;
|
y += this->vscroll.GetPosition();
|
||||||
if (y >= _railstation.station_count) return;
|
if (y >= _railstation.station_count) return;
|
||||||
|
|
||||||
/* Check station availability callback */
|
/* Check station availability callback */
|
||||||
|
@ -1339,8 +1339,8 @@ public:
|
||||||
|
|
||||||
this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
|
this->CheckSelectedSize(GetCustomStationSpec(_railstation.station_class, _railstation.station_type));
|
||||||
|
|
||||||
this->vscroll.count = _railstation.station_count;
|
this->vscroll.SetCount(_railstation.station_count);
|
||||||
this->vscroll.pos = _railstation.station_type;
|
this->vscroll.SetPosition(_railstation.station_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
SndPlayFx(SND_15_BEEP);
|
SndPlayFx(SND_15_BEEP);
|
||||||
|
@ -1775,24 +1775,24 @@ struct BuildRailWaypointWindow : PickerWindowBase {
|
||||||
BuildRailWaypointWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
|
BuildRailWaypointWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
|
||||||
{
|
{
|
||||||
this->InitNested(desc, TRANSPORT_RAIL);
|
this->InitNested(desc, TRANSPORT_RAIL);
|
||||||
this->hscroll.cap = 5;
|
this->hscroll.SetCapacity(5);
|
||||||
this->hscroll.count = _waypoint_count;
|
this->hscroll.SetCount(_waypoint_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void OnPaint()
|
virtual void OnPaint()
|
||||||
{
|
{
|
||||||
for (uint i = 0; i < this->hscroll.cap; i++) {
|
for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
|
||||||
this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.pos + i) == _cur_waypoint_type);
|
this->SetWidgetLoweredState(i + BRWW_WAYPOINT_1, (this->hscroll.GetPosition() + i) == _cur_waypoint_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
|
|
||||||
for (uint i = 0; i < this->hscroll.cap; i++) {
|
for (uint i = 0; i < this->hscroll.GetCapacity(); i++) {
|
||||||
if (this->hscroll.pos + i < this->hscroll.count) {
|
if (this->hscroll.GetPosition() + i < this->hscroll.GetCount()) {
|
||||||
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, this->hscroll.pos + i);
|
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;
|
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 &&
|
if (statspec != NULL &&
|
||||||
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
|
HasBit(statspec->callbackmask, CBM_STATION_AVAIL) &&
|
||||||
|
@ -1811,7 +1811,7 @@ struct BuildRailWaypointWindow : PickerWindowBase {
|
||||||
case BRWW_WAYPOINT_3:
|
case BRWW_WAYPOINT_3:
|
||||||
case BRWW_WAYPOINT_4:
|
case BRWW_WAYPOINT_4:
|
||||||
case BRWW_WAYPOINT_5: {
|
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 */
|
/* Check station availability callback */
|
||||||
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
|
const StationSpec *statspec = GetCustomStationSpec(STAT_CLASS_WAYP, type);
|
||||||
|
|
|
@ -1448,9 +1448,8 @@ struct GameSettingsWindow : Window {
|
||||||
|
|
||||||
this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
|
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->clicked_entry = NULL; // No numeric setting buttons are depressed
|
||||||
this->vscroll.pos = 0;
|
this->vscroll.SetCapacity((this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT);
|
||||||
this->vscroll.cap = (this->widget[SETTINGSEL_OPTIONSPANEL].bottom - this->widget[SETTINGSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
|
this->vscroll.SetCount(_settings_main_page.Length());
|
||||||
SetVScrollCount(this, _settings_main_page.Length());
|
|
||||||
|
|
||||||
this->resize.step_height = SETTING_HEIGHT;
|
this->resize.step_height = SETTING_HEIGHT;
|
||||||
this->resize.height = this->height;
|
this->resize.height = this->height;
|
||||||
|
@ -1464,7 +1463,7 @@ struct GameSettingsWindow : Window {
|
||||||
{
|
{
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
_settings_main_page.Draw(settings_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
|
_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)
|
virtual void OnClick(Point pt, int widget)
|
||||||
|
@ -1474,7 +1473,7 @@ struct GameSettingsWindow : Window {
|
||||||
int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
|
int y = pt.y - SETTINGTREE_TOP_OFFSET; // Shift y coordinate
|
||||||
if (y < 0) return; // Clicked above first entry
|
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
|
if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return; // Clicked too low at the setting
|
||||||
|
|
||||||
uint cur_row = 0;
|
uint cur_row = 0;
|
||||||
|
@ -1488,7 +1487,7 @@ struct GameSettingsWindow : Window {
|
||||||
if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
|
if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
|
||||||
pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
|
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();
|
this->SetDirty();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1608,8 +1607,7 @@ struct GameSettingsWindow : Window {
|
||||||
|
|
||||||
virtual void OnResize(Point delta)
|
virtual void OnResize(Point delta)
|
||||||
{
|
{
|
||||||
this->vscroll.cap += delta.y / SETTING_HEIGHT;
|
this->vscroll.UpdateCapacity(delta.y / SETTING_HEIGHT);
|
||||||
SetVScrollCount(this, _settings_main_page.Length());
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ enum SignListWidgets {
|
||||||
struct SignListWindow : Window, SignList {
|
struct SignListWindow : Window, SignList {
|
||||||
SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
|
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.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
|
||||||
|
|
||||||
|
@ -105,20 +105,20 @@ struct SignListWindow : Window, SignList {
|
||||||
BuildSignsList();
|
BuildSignsList();
|
||||||
SortSignsList();
|
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();
|
this->DrawWidgets();
|
||||||
|
|
||||||
/* No signs? */
|
/* No signs? */
|
||||||
int y = this->widget[SLW_LIST].top + 2; // offset from top of widget
|
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);
|
DrawString(this->widget[SLW_LIST].left + 2, this->widget[SLW_LIST].right, y, STR_STATION_LIST_NONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start drawing the signs */
|
/* 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];
|
const Sign *si = this->signs[i];
|
||||||
|
|
||||||
if (si->owner != OWNER_NONE) DrawCompanyIcon(si->owner, this->widget[SLW_LIST].left + 4, y + 1);
|
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) {
|
if (widget == SLW_LIST) {
|
||||||
uint32 id_v = (pt.y - this->widget[SLW_LIST].top - 1) / 10;
|
uint32 id_v = (pt.y - this->widget[SLW_LIST].top - 1) / 10;
|
||||||
|
|
||||||
if (id_v >= this->vscroll.cap) return;
|
if (id_v >= this->vscroll.GetCapacity()) return;
|
||||||
id_v += this->vscroll.pos;
|
id_v += this->vscroll.GetPosition();
|
||||||
if (id_v >= this->vscroll.count) return;
|
if (id_v >= this->vscroll.GetCount()) return;
|
||||||
|
|
||||||
const Sign *si = this->signs[id_v];
|
const Sign *si = this->signs[id_v];
|
||||||
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
|
||||||
|
@ -145,7 +145,7 @@ struct SignListWindow : Window, SignList {
|
||||||
|
|
||||||
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)
|
||||||
|
|
Loading…
Reference in New Issue