Changeset - r28063:5d6ac34fa921
[Not reviewed]
master
0 6 0
Peter Nelson - 13 months ago 2023-11-01 18:44:23
peter1138@openttd.org
Codechange: Assign/StoreSizePosition x/y can be negative. (#11416)

AssignSizePosition is used with negative values when an NWidgetMatrix is
scrolled, but they were passed as unsigned and then stored as signed.

Widget pos_x/pos_y were already made signed.
6 files changed with 22 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -129,7 +129,7 @@ public:
 
		this->smallest_x = this->head->smallest_x + this->tail->smallest_x; // First and last are always shown, rest not
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
 
	{
 
		assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 

	
src/newgrf_gui.cpp
Show inline comments
 
@@ -1667,7 +1667,7 @@ public:
 
		this->smallest_y = ComputeMaxSize(min_acs_height, this->smallest_y + this->resize_y - 1, this->resize_y);
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
 
	{
 
		this->StoreSizePosition(sizing, x, y, given_width, given_height);
 

	
src/smallmap_gui.cpp
Show inline comments
 
@@ -1740,7 +1740,7 @@ public:
 
		this->resize_y = std::min(display->resize_y, bar->resize_y);
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
 
	{
 
		this->pos_x = x;
 
		this->pos_y = y;
src/toolbar_gui.cpp
Show inline comments
 
@@ -1424,7 +1424,7 @@ public:
 
		_toolbar_width = nbuttons * this->smallest_x;
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
 
	{
 
		assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 

	
src/widget.cpp
Show inline comments
 
@@ -1008,7 +1008,7 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
 */
 

	
 
/**
 
 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
 * Assign size and position to the widget.
 
 * @param sizing       Type of resizing to perform.
 
 * @param x            Horizontal offset of the widget relative to the left edge of the window.
 
@@ -1163,7 +1163,7 @@ bool NWidgetResizeBase::UpdateVerticalSi
 
	return true;
 
}
 

	
 
void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool)
 
void NWidgetResizeBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool)
 
{
 
	this->StoreSizePosition(sizing, x, y, given_width, given_height);
 
}
 
@@ -1400,7 +1400,7 @@ void NWidgetStacked::SetupSmallestSize(W
 
	}
 
}
 

	
 
void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
void NWidgetStacked::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
{
 
	assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 
	this->StoreSizePosition(sizing, x, y, given_width, given_height);
 
@@ -1570,7 +1570,7 @@ void NWidgetHorizontal::SetupSmallestSiz
 
	this->pip_pre = this->pip_inter = this->pip_post = 0;
 
}
 

	
 
void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
{
 
	assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 

	
 
@@ -1678,7 +1678,7 @@ NWidgetHorizontalLTR::NWidgetHorizontalL
 
	this->type = NWID_HORIZONTAL_LTR;
 
}
 

	
 
void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool)
 
void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool)
 
{
 
	NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
 
}
 
@@ -1755,7 +1755,7 @@ void NWidgetVertical::SetupSmallestSize(
 
	this->pip_pre = this->pip_inter = this->pip_post = 0;
 
}
 

	
 
void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
{
 
	assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 

	
 
@@ -1981,7 +1981,7 @@ void NWidgetMatrix::SetupSmallestSize(Wi
 
	this->resize_y = resize.height;
 
}
 

	
 
void NWidgetMatrix::AssignSizePosition(SizingType, uint x, uint y, uint given_width, uint given_height, bool)
 
void NWidgetMatrix::AssignSizePosition(SizingType, int x, int y, uint given_width, uint given_height, bool)
 
{
 
	assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
 

	
 
@@ -2249,7 +2249,7 @@ void NWidgetBackground::SetupSmallestSiz
 
	}
 
}
 

	
 
void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
void NWidgetBackground::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
 
{
 
	this->StoreSizePosition(sizing, x, y, given_width, given_height);
 

	
src/widget_type.h
Show inline comments
 
@@ -127,7 +127,7 @@ public:
 

	
 
	virtual void AdjustPaddingForZoom();
 
	virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
 
	virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 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;
 

	
 
@@ -204,7 +204,7 @@ public:
 
	RectPadding uz_padding; ///< Unscaled padding, for resize calculation.
 

	
 
protected:
 
	inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
 
	inline void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height);
 
};
 

	
 
/**
 
@@ -233,7 +233,7 @@ inline uint NWidgetBase::GetVerticalStep
 
 * @param given_width  Width allocated to the widget.
 
 * @param given_height Height allocated to the widget.
 
 */
 
inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
 
inline void NWidgetBase::StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
 
{
 
	this->pos_x = x;
 
	this->pos_y = y;
 
@@ -263,7 +263,7 @@ public:
 

	
 
	bool UpdateVerticalSize(uint min_y);
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 

	
 
	uint min_x; ///< Minimal horizontal size of only this widget.
 
	uint min_y; ///< Minimal vertical size of only this widget.
 
@@ -452,7 +452,7 @@ public:
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) 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 Draw(const Window *w) override;
 
@@ -503,7 +503,7 @@ public:
 
	NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
};
 

	
 
/**
 
@@ -514,7 +514,7 @@ class NWidgetHorizontalLTR : public NWid
 
public:
 
	NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE);
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
};
 

	
 
/**
 
@@ -526,7 +526,7 @@ public:
 
	NWidgetVertical(NWidContainerFlags flags = NC_NONE);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 
	void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override;
 
};
 

	
 
/**
 
@@ -548,7 +548,7 @@ public:
 
	void SetScrollbar(Scrollbar *sb);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) 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;
 

	
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
@@ -599,7 +599,7 @@ public:
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) 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;
 

	
0 comments (0 inline, 0 general)