Changeset - r27925:68a3401ad732
[Not reviewed]
master
0 6 0
Rubidium - 9 months ago 2023-09-17 04:40:28
rubidium@openttd.org
Codechange: introduce and use function to raise and dirty a set of widgets when they are lowered
6 files changed with 31 insertions and 36 deletions:
0 comments (0 inline, 0 general)
src/genworld_gui.cpp
Show inline comments
 
@@ -884,16 +884,10 @@ struct GenerateLandscapeWindow : public 
 

	
 
	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};
 
		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};
 

	
 
		const int *widget = (mode == GLWM_HEIGHTMAP) ? heightmap_raise_widgets : newgame_raise_widgets;
 

	
 
		for (; *widget != WIDGET_LIST_END; widget++) {
 
			if (this->IsWidgetLowered(*widget)) {
 
				this->RaiseWidget(*widget);
 
				this->SetWidgetDirty(*widget);
 
			}
 
		if (mode == GLWM_HEIGHTMAP) {
 
			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 {
 
			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);
 
		}
 
	}
 

	
 
@@ -1232,13 +1226,7 @@ struct CreateScenarioWindow : public Win
 

	
 
	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};
 
		for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
 
			if (this->IsWidgetLowered(*widget)) {
 
				this->RaiseWidget(*widget);
 
				this->SetWidgetDirty(*widget);
 
			}
 
		}
 
		this->RaiseWidgetsWhenLowered(WID_CS_START_DATE_DOWN, WID_CS_START_DATE_UP, WID_CS_FLAT_LAND_HEIGHT_DOWN, WID_CS_FLAT_LAND_HEIGHT_UP);
 
	}
 

	
 
	void OnDropdownSelect(int widget, int index) override
src/industry_gui.cpp
Show inline comments
 
@@ -2922,10 +2922,7 @@ struct IndustryCargoesWindow : public Wi
 
	{
 
		if (!gui_scope) return;
 
		if (data == NUM_INDUSTRYTYPES) {
 
			if (this->IsWidgetLowered(WID_IC_NOTIFY)) {
 
				this->RaiseWidget(WID_IC_NOTIFY);
 
				this->SetWidgetDirty(WID_IC_NOTIFY);
 
			}
 
			this->RaiseWidgetWhenLowered(WID_IC_NOTIFY);
 
			return;
 
		}
 

	
src/network/network_gui.cpp
Show inline comments
 
@@ -1180,13 +1180,7 @@ struct NetworkStartServerWindow : public
 

	
 
	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};
 
		for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
 
			if (this->IsWidgetLowered(*widget)) {
 
				this->RaiseWidget(*widget);
 
				this->SetWidgetDirty(*widget);
 
			}
 
		}
 
		this->RaiseWidgetsWhenLowered(WID_NSS_CLIENTS_BTND, WID_NSS_CLIENTS_BTNU, WID_NSS_COMPANIES_BTND, WID_NSS_COMPANIES_BTNU);
 
	}
 

	
 
	void OnQueryTextFinished(char *str) override
src/terraform_gui.cpp
Show inline comments
 
@@ -649,10 +649,7 @@ struct ScenarioEditorLandscapeGeneration
 
	{
 
		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 (this->IsWidgetLowered(i)) {
 
				this->RaiseWidget(i);
 
				this->SetWidgetDirty(i);
 
			}
 
			this->RaiseWidgetWhenLowered(i);
 
		}
 
	}
 

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

	
src/window_gui.h
Show inline comments
 
@@ -414,6 +414,18 @@ public:
 
	}
 

	
 
	/**
 
	 * 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.
 
	 * @param widget_index index of this widget in the window
 
	 * @return status of the widget ie: lowered = true, raised= false
 
@@ -458,6 +470,16 @@ public:
 
	{
 
		(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 DrawWidgets() const;
0 comments (0 inline, 0 general)