(svn r20453) -Codechange: Remove direct accesses to Window::hscroll, vscroll and vscroll2.
Note: All windows get individual members with the same names, which are initialised via Window::GetScrollbar(). This caching is not required at all, but simplifies conversion.
This commit is contained in:
@@ -142,6 +142,7 @@ struct NewGRFParametersWindow : public Window {
|
||||
int timeout; ///< How long before we unpress the last-pressed button?
|
||||
uint clicked_row; ///< The selected parameter
|
||||
int line_height; ///< Height of a row in the matrix widget.
|
||||
Scrollbar *vscroll;
|
||||
|
||||
NewGRFParametersWindow(const WindowDesc *desc, GRFConfig *c) : Window(),
|
||||
grf_config(c),
|
||||
@@ -149,9 +150,10 @@ struct NewGRFParametersWindow : public Window {
|
||||
timeout(0),
|
||||
clicked_row(UINT_MAX)
|
||||
{
|
||||
this->InitNested(desc); // Initializes 'this->line_height' as side effect.
|
||||
|
||||
this->vscroll.SetCount(c->num_valid_params);
|
||||
this->CreateNestedTree(desc);
|
||||
this->vscroll = this->GetScrollbar(GRFPAR_WIDGET_SCROLLBAR);
|
||||
this->FinishInitNested(desc); // Initializes 'this->line_height' as side effect.
|
||||
this->vscroll->SetCount(c->num_valid_params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +210,7 @@ struct NewGRFParametersWindow : public Window {
|
||||
uint text_right = r.right - (rtl ? 54 : WD_FRAMERECT_RIGHT);
|
||||
|
||||
int y = r.top;
|
||||
for (uint i = this->vscroll.GetPosition(); this->vscroll.IsVisible(i) && i < this->grf_config->num_valid_params; i++) {
|
||||
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->grf_config->num_valid_params; i++) {
|
||||
GRFParameterInfo *par_info = (i < this->grf_config->param_info.Length()) ? this->grf_config->param_info[i] : NULL;
|
||||
if (par_info == NULL) par_info = GetDummyParameterInfo(i);
|
||||
uint32 current_value = par_info->GetValue(this->grf_config);
|
||||
@@ -256,7 +258,7 @@ struct NewGRFParametersWindow : public Window {
|
||||
{
|
||||
switch (widget) {
|
||||
case GRFPAR_WIDGET_BACKGROUND: {
|
||||
uint num = this->vscroll.GetScrolledRowFromWidget(pt.y, this, GRFPAR_WIDGET_BACKGROUND);
|
||||
uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, GRFPAR_WIDGET_BACKGROUND);
|
||||
if (num >= this->grf_config->num_valid_params) break;
|
||||
if (this->clicked_row != num) {
|
||||
DeleteChildWindows(WC_QUERY_STRING);
|
||||
@@ -321,8 +323,8 @@ struct NewGRFParametersWindow : public Window {
|
||||
virtual void OnResize()
|
||||
{
|
||||
NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRFPAR_WIDGET_BACKGROUND);
|
||||
this->vscroll.SetCapacity(nwi->current_y / this->line_height);
|
||||
nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
||||
this->vscroll->SetCapacity(nwi->current_y / this->line_height);
|
||||
nwi->widget_data = (this->vscroll->GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
|
||||
}
|
||||
|
||||
virtual void OnTick()
|
||||
@@ -438,6 +440,9 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
bool execute; ///< On pressing 'apply changes' are grf changes applied immediately, or only list is updated.
|
||||
int preset; ///< Selected preset.
|
||||
|
||||
Scrollbar *vscroll;
|
||||
Scrollbar *vscroll2;
|
||||
|
||||
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool execute, GRFConfig **orig_list) : QueryStringBaseWindow(EDITBOX_MAX_SIZE)
|
||||
{
|
||||
this->avail_sel = NULL;
|
||||
@@ -453,7 +458,11 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
CopyGRFConfigList(&this->actives, *orig_list, false);
|
||||
GetGRFPresetList(&_grf_preset_list);
|
||||
|
||||
this->InitNested(desc);
|
||||
this->CreateNestedTree(desc);
|
||||
this->vscroll = this->GetScrollbar(SNGRFS_SCROLLBAR);
|
||||
this->vscroll2 = this->GetScrollbar(SNGRFS_SCROLL2BAR);
|
||||
this->FinishInitNested(desc);
|
||||
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, EDITBOX_MAX_LENGTH);
|
||||
this->SetFocusedWidget(SNGRFS_FILTER);
|
||||
|
||||
@@ -530,8 +539,8 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
|
||||
virtual void OnResize()
|
||||
{
|
||||
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
||||
this->vscroll2.SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
|
||||
this->vscroll->SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
||||
this->vscroll2->SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
|
||||
}
|
||||
|
||||
virtual void SetStringParameters(int widget) const
|
||||
@@ -608,7 +617,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
|
||||
int i = 0;
|
||||
for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {
|
||||
if (this->vscroll.IsVisible(i)) {
|
||||
if (this->vscroll->IsVisible(i)) {
|
||||
const char *text = c->GetName();
|
||||
bool h = (this->active_sel == c);
|
||||
PaletteID pal = this->GetPalette(c);
|
||||
@@ -630,8 +639,8 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
uint step_height = this->GetWidget<NWidgetBase>(SNGRFS_AVAIL_LIST)->resize_y;
|
||||
int offset_y = (step_height - FONT_HEIGHT_NORMAL) / 2;
|
||||
uint y = r.top + WD_FRAMERECT_TOP;
|
||||
uint min_index = this->vscroll2.GetPosition();
|
||||
uint max_index = min(min_index + this->vscroll2.GetCapacity(), this->avails.Length());
|
||||
uint min_index = this->vscroll2->GetPosition();
|
||||
uint max_index = min(min_index + this->vscroll2->GetCapacity(), this->avails.Length());
|
||||
|
||||
for (uint i = min_index; i < max_index; i++) {
|
||||
const GRFConfig *c = this->avails[i];
|
||||
@@ -709,7 +718,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vscroll.ScrollTowards(pos);
|
||||
this->vscroll->ScrollTowards(pos);
|
||||
this->preset = -1;
|
||||
this->InvalidateData();
|
||||
break;
|
||||
@@ -728,14 +737,14 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->vscroll.ScrollTowards(pos);
|
||||
this->vscroll->ScrollTowards(pos);
|
||||
this->preset = -1;
|
||||
this->InvalidateData();
|
||||
break;
|
||||
}
|
||||
|
||||
case SNGRFS_FILE_LIST: { // Select an active GRF.
|
||||
uint i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
|
||||
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, SNGRFS_FILE_LIST);
|
||||
|
||||
GRFConfig *c;
|
||||
for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
|
||||
@@ -779,7 +788,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
}
|
||||
|
||||
case SNGRFS_AVAIL_LIST: { // Select a non-active GRF.
|
||||
uint i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
|
||||
uint i = this->vscroll2->GetScrolledRowFromWidget(pt.y, this, SNGRFS_AVAIL_LIST);
|
||||
this->active_sel = NULL;
|
||||
DeleteWindowByClass(WC_GRF_PARAMETERS);
|
||||
if (i < this->avails.Length()) {
|
||||
@@ -970,11 +979,11 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
int i = 0;
|
||||
for (const GRFConfig *c = this->actives; c != NULL; c = c->next, i++) {}
|
||||
|
||||
this->vscroll.SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
||||
this->vscroll.SetCount(i);
|
||||
this->vscroll->SetCapacityFromWidget(this, SNGRFS_FILE_LIST);
|
||||
this->vscroll->SetCount(i);
|
||||
|
||||
this->vscroll2.SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
|
||||
if (this->avail_pos >= 0) this->vscroll2.ScrollTowards(this->avail_pos);
|
||||
this->vscroll2->SetCapacityFromWidget(this, SNGRFS_AVAIL_LIST);
|
||||
if (this->avail_pos >= 0) this->vscroll2->ScrollTowards(this->avail_pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1044,12 +1053,12 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
|
||||
case WKC_PAGEUP:
|
||||
/* scroll up a page */
|
||||
this->avail_pos = (this->avail_pos < this->vscroll2.GetCapacity()) ? 0 : this->avail_pos - this->vscroll2.GetCapacity();
|
||||
this->avail_pos = (this->avail_pos < this->vscroll2->GetCapacity()) ? 0 : this->avail_pos - this->vscroll2->GetCapacity();
|
||||
break;
|
||||
|
||||
case WKC_PAGEDOWN:
|
||||
/* scroll down a page */
|
||||
this->avail_pos = min(this->avail_pos + this->vscroll2.GetCapacity(), (int)this->avails.Length() - 1);
|
||||
this->avail_pos = min(this->avail_pos + this->vscroll2->GetCapacity(), (int)this->avails.Length() - 1);
|
||||
break;
|
||||
|
||||
case WKC_HOME:
|
||||
@@ -1075,7 +1084,7 @@ struct NewGRFWindow : public QueryStringBaseWindow {
|
||||
if (this->avails.Length() == 0) this->avail_pos = -1;
|
||||
if (this->avail_pos >= 0) {
|
||||
this->avail_sel = this->avails[this->avail_pos];
|
||||
this->vscroll2.ScrollTowards(this->avail_pos);
|
||||
this->vscroll2->ScrollTowards(this->avail_pos);
|
||||
this->InvalidateData(0);
|
||||
}
|
||||
|
||||
@@ -1149,7 +1158,7 @@ private:
|
||||
if (this->avail_pos < 0) this->avail_sel = NULL;
|
||||
}
|
||||
|
||||
this->vscroll2.SetCount(this->avails.Length()); // Update the scrollbar
|
||||
this->vscroll2->SetCount(this->avails.Length()); // Update the scrollbar
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user