Changeset - r28762:67d8065b03e1
[Not reviewed]
master
0 2 0
Peter Nelson - 10 months ago 2024-02-14 17:23:03
peter1138@openttd.org
Codechange: Update window's widget lookup map when switching displayed plane.
2 files changed with 9 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -1259,26 +1259,31 @@ void NWidgetStacked::AssignSizePosition(
 
		uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
 

	
 
		uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
 
		uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
 
		uint child_pos_y = child_wid->padding.top;
 

	
 
		child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
 
	}
 
}
 

	
 
void NWidgetStacked::FillWidgetLookup(WidgetLookup &widget_lookup)
 
{
 
	/* We need to update widget_lookup later. */
 
	this->widget_lookup = &widget_lookup;
 

	
 
	if (this->index >= 0) widget_lookup[this->index] = this;
 
	NWidgetContainer::FillWidgetLookup(widget_lookup);
 
	/* In case widget IDs are repeated, make sure Window::GetWidget works on displayed widgets. */
 
	if (static_cast<size_t>(this->shown_plane) < this->children.size()) this->children[shown_plane]->FillWidgetLookup(widget_lookup);
 
}
 

	
 
void NWidgetStacked::Draw(const Window *w)
 
{
 
	if (this->shown_plane >= SZSP_BEGIN) return;
 

	
 
	assert(static_cast<size_t>(this->shown_plane) < this->children.size());
 
	this->children[shown_plane]->Draw(w);
 
	DrawOutline(w, this);
 
}
 

	
 
NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
 
@@ -1291,24 +1296,26 @@ NWidgetCore *NWidgetStacked::GetWidgetFr
 
	return this->children[shown_plane]->GetWidgetFromPos(x, y);
 
}
 

	
 
/**
 
 * Select which plane to show (for #NWID_SELECTION only).
 
 * @param plane Plane number to display.
 
 * @return true iff the shown plane changed.
 
 */
 
bool NWidgetStacked::SetDisplayedPlane(int plane)
 
{
 
	if (this->shown_plane == plane) return false;
 
	this->shown_plane = plane;
 
	/* In case widget IDs are repeated, make sure Window::GetWidget works on displayed widgets. */
 
	if (static_cast<size_t>(this->shown_plane) < this->children.size()) this->children[shown_plane]->FillWidgetLookup(*this->widget_lookup);
 
	return true;
 
}
 

	
 
NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
 
{
 
	this->flags = flags;
 
}
 

	
 
void NWidgetPIPContainer::AdjustPaddingForZoom()
 
{
 
	this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
 
	this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
src/widget_type.h
Show inline comments
 
@@ -488,24 +488,26 @@ public:
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
	void FillWidgetLookup(WidgetLookup &widget_lookup) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 

	
 
	bool SetDisplayedPlane(int plane);
 

	
 
	int shown_plane; ///< Plane being displayed (for #NWID_SELECTION only).
 
	const WidgetID index; ///< If non-negative, index in the #Window::widget_lookup.
 
private:
 
	WidgetLookup *widget_lookup; ///< Window's widget lookup, updated in SetDisplayedPlane().
 
};
 

	
 
/** Nested widget container flags, */
 
enum NWidContainerFlags {
 
	NCB_EQUALSIZE = 0, ///< Containers should keep all their (resizing) children equally large.
 
	NCB_BIGFIRST  = 1, ///< Allocate space to biggest resize first.
 

	
 
	NC_NONE = 0,                       ///< All flags cleared.
 
	NC_EQUALSIZE = 1 << NCB_EQUALSIZE, ///< Value of the #NCB_EQUALSIZE flag.
 
	NC_BIGFIRST  = 1 << NCB_BIGFIRST,  ///< Value of the #NCB_BIGFIRST flag.
 
};
 
DECLARE_ENUM_AS_BIT_SET(NWidContainerFlags)
0 comments (0 inline, 0 general)