Changeset - r28350:2ccb2f8f699f
[Not reviewed]
master
0 4 0
Peter Nelson - 4 months ago 2023-12-29 14:52:42
peter1138@openttd.org
Codechange: Rename nested array to widget lookup.

This changes from naming storage-type to naming functionality.

* `FillNestedArray` is renamed to `FillWidgetLookup`.
* `Window::nested_array` is renamed to `Window::widget_lookup`.
* `array` parameter renamed as well.
4 files changed with 45 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -903,7 +903,7 @@ void Window::DrawSortButtonState(int wid
 
{
 
	if (state == SBS_OFF) return;
 

	
 
	assert(this->nested_array != nullptr);
 
	assert(this->widget_lookup != nullptr);
 
	Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect();
 

	
 
	/* Sort button uses the same sprites as vertical scrollbar */
 
@@ -1023,8 +1023,8 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
 */
 

	
 
/**
 
 * @fn void NWidgetBase::FillNestedArray(NWidgetBase **array, uint length)
 
 * Fill the Window::nested_array array with pointers to nested widgets in the tree.
 
 * @fn void NWidgetBase::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
 * Fill the Window::widget_lookup array with pointers to nested widgets in the tree.
 
 * @param array Base pointer of the array.
 
 * @param length Length of the array.
 
 */
 
@@ -1276,9 +1276,9 @@ void NWidgetCore::SetAlignment(StringAli
 
	this->align = align;
 
}
 

	
 
void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
 
void NWidgetCore::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
	if (this->index >= 0 && (uint)(this->index) < length) widget_lookup[this->index] = this;
 
}
 

	
 
NWidgetCore *NWidgetCore::GetWidgetFromPos(int x, int y)
 
@@ -1345,10 +1345,10 @@ void NWidgetContainer::Add(NWidgetBase *
 
	}
 
}
 

	
 
void NWidgetContainer::FillNestedArray(NWidgetBase **array, uint length)
 
void NWidgetContainer::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
{
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->FillNestedArray(array, length);
 
		child_wid->FillWidgetLookup(widget_lookup, length);
 
	}
 
}
 

	
 
@@ -1452,10 +1452,10 @@ void NWidgetStacked::AssignSizePosition(
 
	}
 
}
 

	
 
void NWidgetStacked::FillNestedArray(NWidgetBase **array, uint length)
 
void NWidgetStacked::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
	NWidgetContainer::FillNestedArray(array, length);
 
	if (this->index >= 0 && (uint)(this->index) < length) widget_lookup[this->index] = this;
 
	NWidgetContainer::FillWidgetLookup(widget_lookup, length);
 
}
 

	
 
void NWidgetStacked::Draw(const Window *w)
 
@@ -1925,7 +1925,7 @@ void NWidgetSpacer::SetupSmallestSize(Wi
 
	this->smallest_y = this->min_y;
 
}
 

	
 
void NWidgetSpacer::FillNestedArray(NWidgetBase **, uint)
 
void NWidgetSpacer::FillWidgetLookup(NWidgetBase **, uint)
 
{
 
}
 

	
 
@@ -2065,10 +2065,10 @@ void NWidgetMatrix::AssignSizePosition(S
 
	this->SetCount(this->count);
 
}
 

	
 
void NWidgetMatrix::FillNestedArray(NWidgetBase **array, uint length)
 
void NWidgetMatrix::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
	NWidgetContainer::FillNestedArray(array, length);
 
	if (this->index >= 0 && (uint)(this->index) < length) widget_lookup[this->index] = this;
 
	NWidgetContainer::FillWidgetLookup(widget_lookup, length);
 
}
 

	
 
NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
 
@@ -2335,10 +2335,10 @@ void NWidgetBackground::AssignSizePositi
 
	}
 
}
 

	
 
void NWidgetBackground::FillNestedArray(NWidgetBase **array, uint length)
 
void NWidgetBackground::FillWidgetLookup(NWidgetBase **widget_lookup, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
	if (this->child != nullptr) this->child->FillNestedArray(array, length);
 
	if (this->index >= 0 && (uint)(this->index) < length) widget_lookup[this->index] = this;
 
	if (this->child != nullptr) this->child->FillWidgetLookup(widget_lookup, length);
 
}
 

	
 
void NWidgetBackground::Draw(const Window *w)
src/widget_type.h
Show inline comments
 
@@ -136,7 +136,7 @@ public:
 
	virtual void SetupSmallestSize(Window *w) = 0;
 
	virtual void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) = 0;
 

	
 
	virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
 
	virtual void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) = 0;
 

	
 
	virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
 
	virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
 
@@ -337,7 +337,7 @@ public:
 
	inline void SetDisabled(bool disabled);
 
	inline bool IsDisabled() const;
 

	
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
	bool IsHighlighted() const override;
 
	TextColour GetHighlightColour() const override;
 
@@ -419,7 +419,7 @@ public:
 

	
 
	void AdjustPaddingForZoom() override;
 
	void Add(NWidgetBase *wid);
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
@@ -462,7 +462,7 @@ 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 FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
@@ -470,7 +470,7 @@ public:
 
	bool SetDisplayedPlane(int plane);
 

	
 
	int shown_plane; ///< Plane being displayed (for #NWID_SELECTION only).
 
	int index;       ///< If non-negative, index in the #Window::nested_array.
 
	int index;       ///< If non-negative, index in the #Window::widget_lookup.
 
};
 

	
 
/** Nested widget container flags, */
 
@@ -564,12 +564,12 @@ public:
 

	
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 

	
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
	void Draw(const Window *w) override;
 
protected:
 
	int index;      ///< If non-negative, index in the #Window::nested_array.
 
	int index;      ///< If non-negative, index in the #Window::widget_lookup.
 
	Colours colour; ///< Colour of this widget.
 
	int clicked;    ///< The currently clicked widget.
 
	int count;      ///< Amount of valid widgets.
 
@@ -593,7 +593,7 @@ public:
 
	NWidgetSpacer(int width, int height);
 

	
 
	void SetupSmallestSize(Window *w) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	void SetDirty(const Window *w) const override;
 
@@ -617,7 +617,7 @@ public:
 
	void SetupSmallestSize(Window *w) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 

	
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 
	void FillWidgetLookup(NWidgetBase **widget_lookup, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
src/window.cpp
Show inline comments
 
@@ -496,7 +496,7 @@ bool Window::SetFocusedWidget(int widget
 
	/* Do nothing if widget_index is already focused, or if it wasn't a valid widget. */
 
	if ((uint)widget_index >= this->nested_array_size) return false;
 

	
 
	assert(this->nested_array[widget_index] != nullptr); // Setting focus to a non-existing widget is a bad idea.
 
	assert(this->widget_lookup[widget_index] != nullptr); // Setting focus to a non-existing widget is a bad idea.
 
	if (this->nested_focus != nullptr) {
 
		if (this->GetWidget<NWidgetCore>(widget_index) == this->nested_focus) return false;
 

	
 
@@ -532,8 +532,8 @@ void Window::OnFocusLost(bool)
 
void Window::RaiseButtons(bool autoraise)
 
{
 
	for (uint i = 0; i < this->nested_array_size; i++) {
 
		if (this->nested_array[i] == nullptr) continue;
 
		WidgetType type = this->nested_array[i]->type;
 
		if (this->widget_lookup[i] == nullptr) continue;
 
		WidgetType type = this->widget_lookup[i]->type;
 
		if (((type & ~WWB_PUSHBUTTON) < WWT_LAST || type == NWID_PUSHBUTTON_DROPDOWN) &&
 
				(!autoraise || (type & WWB_PUSHBUTTON) || type == WWT_EDITBOX) && this->IsWidgetLowered(i)) {
 
			this->RaiseWidget(i);
 
@@ -556,9 +556,9 @@ void Window::RaiseButtons(bool autoraise
 
void Window::SetWidgetDirty(byte widget_index) const
 
{
 
	/* Sometimes this function is called before the window is even fully initialized */
 
	if (this->nested_array == nullptr) return;
 

	
 
	this->nested_array[widget_index]->SetDirty(this);
 
	if (this->widget_lookup == nullptr) return;
 

	
 
	this->widget_lookup[widget_index]->SetDirty(this);
 
}
 

	
 
/**
 
@@ -1092,7 +1092,7 @@ Window::~Window()
 

	
 
	if (this->viewport != nullptr) DeleteWindowViewport(this);
 

	
 
	free(this->nested_array); // Contents is released through deletion of #nested_root.
 
	free(this->widget_lookup); // Contents is released through deletion of #nested_root.
 
	delete this->nested_root;
 
}
 

	
 
@@ -1366,7 +1366,7 @@ static void BringWindowToFront(Window *w
 
 * @param window_number Number being assigned to the new window
 
 * @return Window pointer of the newly created window
 
 * @pre If nested widgets are used (\a widget is \c nullptr), #nested_root and #nested_array_size must be initialized.
 
 *      In addition, #nested_array is either \c nullptr, or already initialized.
 
 *      In addition, #widget_lookup is either \c nullptr, or already initialized.
 
 */
 
void Window::InitializeData(WindowNumber window_number)
 
{
 
@@ -1722,9 +1722,9 @@ static Point LocalGetWindowPlacement(con
 

	
 
/**
 
 * Perform the first part of the initialization of a nested widget tree.
 
 * Construct a nested widget tree in #nested_root, and optionally fill the #nested_array array to provide quick access to the uninitialized widgets.
 
 * Construct a nested widget tree in #nested_root, and optionally fill the #widget_lookup array to provide quick access to the uninitialized widgets.
 
 * This is mainly useful for setting very basic properties.
 
 * @param fill_nested Fill the #nested_array (enabling is expensive!).
 
 * @param fill_nested Fill the #widget_lookup (enabling is expensive!).
 
 * @note Filling the nested array requires an additional traversal through the nested widget tree, and is best performed by #FinishInitNested rather than here.
 
 */
 
void Window::CreateNestedTree()
 
@@ -1733,8 +1733,8 @@ void Window::CreateNestedTree()
 
	this->nested_root = MakeWindowNWidgetTree(this->window_desc->nwid_begin, this->window_desc->nwid_end, &biggest_index, &this->shade_select);
 
	this->nested_array_size = (uint)(biggest_index + 1);
 

	
 
	this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
	this->nested_root->FillNestedArray(this->nested_array, this->nested_array_size);
 
	this->widget_lookup = CallocT<NWidgetBase *>(this->nested_array_size);
 
	this->nested_root->FillWidgetLookup(this->widget_lookup, this->nested_array_size);
 
}
 

	
 
/**
 
@@ -1841,7 +1841,7 @@ static void DecreaseWindowCounters()
 
		if (_scroller_click_timeout == 0) {
 
			/* Unclick scrollbar buttons if they are pressed. */
 
			for (uint i = 0; i < w->nested_array_size; i++) {
 
				NWidgetBase *nwid = w->nested_array[i];
 
				NWidgetBase *nwid = w->widget_lookup[i];
 
				if (nwid != nullptr && (nwid->type == NWID_HSCROLLBAR || nwid->type == NWID_VSCROLLBAR)) {
 
					NWidgetScrollbar *sb = static_cast<NWidgetScrollbar*>(nwid);
 
					if (sb->disp_flags & (ND_SCROLLBAR_UP | ND_SCROLLBAR_DOWN)) {
src/window_gui.h
Show inline comments
 
@@ -260,7 +260,7 @@ public:
 
	const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c nullptr if no nested widget has focus.
 
	std::map<int, QueryString*> querystrings; ///< QueryString associated to WWT_EDITBOX widgets.
 
	NWidgetBase *nested_root;        ///< Root of the nested tree.
 
	NWidgetBase **nested_array;      ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead.
 
	NWidgetBase **widget_lookup;      ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead.
 
	uint nested_array_size;          ///< Size of the nested array.
 
	NWidgetStacked *shade_select;    ///< Selection widget (#NWID_SELECTION) to use for shading the window. If \c nullptr, window cannot shade.
 
	Dimension unshaded_size;         ///< Last known unshaded size (only valid while shaded).
 
@@ -329,7 +329,7 @@ public:
 
	inline void SetWidgetDisabledState(byte widget_index, bool disab_stat)
 
	{
 
		assert(widget_index < this->nested_array_size);
 
		if (this->nested_array[widget_index] != nullptr) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
 
		if (this->widget_lookup[widget_index] != nullptr) this->GetWidget<NWidgetCore>(widget_index)->SetDisabled(disab_stat);
 
	}
 

	
 
	/**
 
@@ -520,7 +520,7 @@ public:
 

	
 
	/**
 
	 * Notification that the nested widget tree gets initialized. The event can be used to perform general computations.
 
	 * @note #nested_root and/or #nested_array (normally accessed via #GetWidget()) may not exist during this call.
 
	 * @note #nested_root and/or #widget_lookup (normally accessed via #GetWidget()) may not exist during this call.
 
	 */
 
	virtual void OnInit() { }
 

	
 
@@ -894,8 +894,8 @@ inline bool AllEqual(It begin, It end, P
 
template <class NWID>
 
inline NWID *Window::GetWidget(uint widnum)
 
{
 
	if (widnum >= this->nested_array_size || this->nested_array[widnum] == nullptr) return nullptr;
 
	NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]);
 
	if (widnum >= this->nested_array_size || this->widget_lookup[widnum] == nullptr) return nullptr;
 
	NWID *nwid = dynamic_cast<NWID *>(this->widget_lookup[widnum]);
 
	assert(nwid != nullptr);
 
	return nwid;
 
}
 
@@ -905,7 +905,7 @@ template <>
 
inline const NWidgetBase *Window::GetWidget<NWidgetBase>(uint widnum) const
 
{
 
	if (widnum >= this->nested_array_size) return nullptr;
 
	return this->nested_array[widnum];
 
	return this->widget_lookup[widnum];
 
}
 

	
 
/**
0 comments (0 inline, 0 general)