1
0
Fork 0

Codechange: introduce and use function to raise and dirty a set of widgets when they are lowered

pull/11312/head
Rubidium 2023-09-17 06:40:28 +02:00 committed by rubidium42
parent 6580ff1adb
commit 7ef22af2bb
6 changed files with 31 additions and 36 deletions

View File

@ -884,16 +884,10 @@ struct GenerateLandscapeWindow : public Window {
void OnTimeout() override void OnTimeout() override
{ {
static const int newgame_raise_widgets[] = {WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END}; if (mode == GLWM_HEIGHTMAP) {
static const int heightmap_raise_widgets[] = {WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN, WIDGET_LIST_END}; this->RaiseWidgetsWhenLowered(WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
} else {
const int *widget = (mode == GLWM_HEIGHTMAP) ? heightmap_raise_widgets : newgame_raise_widgets; this->RaiseWidgetsWhenLowered(WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
for (; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
} }
} }
@ -1232,13 +1226,7 @@ struct CreateScenarioWindow : public Window
void OnTimeout() override void OnTimeout() override
{ {
static const int raise_widgets[] = {WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END}; this->RaiseWidgetsWhenLowered(WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP);
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
}
} }
void OnDropdownSelect(int widget, int index) override void OnDropdownSelect(int widget, int index) override

View File

@ -2922,10 +2922,7 @@ struct IndustryCargoesWindow : public Window {
{ {
if (!gui_scope) return; if (!gui_scope) return;
if (data == NUM_INDUSTRYTYPES) { if (data == NUM_INDUSTRYTYPES) {
if (this->IsWidgetLowered(WID_IC_NOTIFY)) { this->RaiseWidgetWhenLowered(WID_IC_NOTIFY);
this->RaiseWidget(WID_IC_NOTIFY);
this->SetWidgetDirty(WID_IC_NOTIFY);
}
return; return;
} }

View File

@ -1180,13 +1180,7 @@ struct NetworkStartServerWindow : public Window {
void OnTimeout() override void OnTimeout() override
{ {
static const int raise_widgets[] = {WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU, WIDGET_LIST_END}; this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU);
for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
if (this->IsWidgetLowered(*widget)) {
this->RaiseWidget(*widget);
this->SetWidgetDirty(*widget);
}
}
} }
void OnQueryTextFinished(char *str) override void OnQueryTextFinished(char *str) override

View File

@ -649,10 +649,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
{ {
for (uint i = WID_ETT_START; i < this->nested_array_size; i++) { for (uint i = WID_ETT_START; i < this->nested_array_size; i++) {
if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons if (i == WID_ETT_BUTTONS_START) i = WID_ETT_BUTTONS_END; // skip the buttons
if (this->IsWidgetLowered(i)) { this->RaiseWidgetWhenLowered(i);
this->RaiseWidget(i);
this->SetWidgetDirty(i);
}
} }
} }

View File

@ -2128,10 +2128,7 @@ struct MainToolbarWindow : Window {
/* We do not want to automatically raise the pause, fast forward and /* We do not want to automatically raise the pause, fast forward and
* switchbar buttons; they have to stay down when pressed etc. */ * switchbar buttons; they have to stay down when pressed etc. */
for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) { for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
if (this->IsWidgetLowered(i)) { this->RaiseWidgetWhenLowered(i);
this->RaiseWidget(i);
this->SetWidgetDirty(i);
}
} }
} }

View File

@ -413,6 +413,18 @@ public:
SetWidgetLoweredState(widget_index, false); SetWidgetLoweredState(widget_index, false);
} }
/**
* Marks a widget as raised and dirty (redraw), when it is marked as lowered.
* @param widget_index index of this widget in the window
*/
inline void RaiseWidgetWhenLowered(byte widget_index)
{
if (this->IsWidgetLowered(widget_index)) {
this->RaiseWidget(widget_index);
this->SetWidgetDirty(widget_index);
}
}
/** /**
* Gets the lowered state of a widget. * Gets the lowered state of a widget.
* @param widget_index index of this widget in the window * @param widget_index index of this widget in the window
@ -458,6 +470,16 @@ public:
{ {
(SetWidgetLoweredState(widgets, lowered_stat), ...); (SetWidgetLoweredState(widgets, lowered_stat), ...);
} }
/**
* Raises the widgets and sets widgets dirty that are lowered.
* @param widgets list of widgets
*/
template<typename... Args>
void RaiseWidgetsWhenLowered(Args... widgets) {
(this->RaiseWidgetWhenLowered(widgets), ...);
}
void SetWidgetDirty(byte widget_index) const; void SetWidgetDirty(byte widget_index) const;
void DrawWidgets() const; void DrawWidgets() const;