Changeset - r15205:df5b761dc391
[Not reviewed]
master
0 2 0
alberth - 14 years ago 2010-05-16 19:17:02
alberth@openttd.org
(svn r19844) -Fix: Move NWidgetBase::StoreSizePosition() to an include file, and use proper inline macro.
2 files changed with 32 insertions and 31 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -704,32 +704,12 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
 * Fill the Window::nested_array array with pointers to nested widgets in the tree.
 
 * @param array Base pointer of the array.
 
 * @param length Length of the array.
 
 */
 

	
 
/**
 
 * Store size and position.
 
 * @param sizing       Type of resizing to perform.
 
 * @param x            Horizontal offset of the widget relative to the left edge of the window.
 
 * @param y            Vertical offset of the widget relative to the top edge of the window.
 
 * @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)
 
{
 
	this->pos_x = x;
 
	this->pos_y = y;
 
	if (sizing == ST_SMALLEST) {
 
		this->smallest_x = given_width;
 
		this->smallest_y = given_height;
 
	}
 
	this->current_x = given_width;
 
	this->current_y = given_height;
 
}
 

	
 
/**
 
 * @fn void NWidgetBase::Draw(const Window *w)
 
 * Draw the widgets of the tree.
 
 * The function calls #Window::DrawWidget for each widget with a non-negative index, after the widget itself is painted.
 
 * @param w Window that owns the tree.
 
 */
 

	
 
@@ -817,13 +797,13 @@ void NWidgetResizeBase::SetResize(uint r
 
	this->resize_x = resize_x;
 
	this->resize_y = resize_y;
 
}
 

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

	
 
/**
 
 * Initialization of a 'real' widget.
 
 * @param tp          Type of the widget.
 
 * @param colour      Colour of the widget.
 
@@ -998,13 +978,13 @@ void NWidgetStacked::SetupSmallestSize(W
 
	}
 
}
 

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

	
 
	if (this->shown_plane >= SZSP_BEGIN) return;
 

	
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
 
		uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
 
@@ -1174,13 +1154,13 @@ void NWidgetHorizontal::SetupSmallestSiz
 

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

	
 
	uint additional_length = given_width - this->smallest_x; // Additional width given to us.
 
	StoreSizePosition(sizing, x, y, given_width, given_height);
 
	this->StoreSizePosition(sizing, x, y, given_width, given_height);
 

	
 
	/* In principle, the additional horizontal space is distributed evenly over the available resizable childs. Due to step sizes, this may not always be feasible.
 
	 * To make resizing work as good as possible, first childs with biggest step sizes are done. These may get less due to rounding down.
 
	 * This additional space is then given to childs with smaller step sizes. This will give a good result when resize steps of each child is a multiple
 
	 * of the child with the smallest non-zero stepsize.
 
	 *
 
@@ -1326,13 +1306,13 @@ void NWidgetVertical::SetupSmallestSize(
 

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

	
 
	int additional_length = given_height - this->smallest_y; // Additional height given to us.
 
	StoreSizePosition(sizing, x, y, given_width, given_height);
 
	this->StoreSizePosition(sizing, x, y, given_width, given_height);
 

	
 
	/* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the childs with the biggest resize steps.
 
	 * It also stores computed widths and heights into current_x and current_y values of the child.
 
	 */
 

	
 
	/* First loop: Find biggest stepsize, find number of childs that want a piece of the pie, handle horizontal size for all childs, handle vertical size for non-resizing childs. */
 
@@ -1525,13 +1505,13 @@ void NWidgetBackground::SetupSmallestSiz
 
		this->resize_y = resize.height;
 
	}
 
}
 

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

	
 
	if (this->child != NULL) {
 
		uint x_offset = (rtl ? this->child->padding_right : this->child->padding_left);
 
		uint width = given_width - this->child->padding_right - this->child->padding_left;
 
		uint height = given_height - this->child->padding_top - this->child->padding_bottom;
 
		this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, rtl);
src/widget_type.h
Show inline comments
 
@@ -134,22 +134,22 @@ public:
 
	 * Set additional space (padding) around the widget.
 
	 * @param top    Amount of additional space above the widget.
 
	 * @param right  Amount of additional space right of the widget.
 
	 * @param bottom Amount of additional space below the widget.
 
	 * @param left   Amount of additional space left of the widget.
 
	 */
 
	inline void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
 
	FORCEINLINE void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
 
	{
 
		this->padding_top = top;
 
		this->padding_right = right;
 
		this->padding_bottom = bottom;
 
		this->padding_left = left;
 
	};
 

	
 
	inline uint GetHorizontalStepSize(SizingType sizing) const;
 
	inline uint GetVerticalStepSize(SizingType sizing) const;
 
	FORCEINLINE uint GetHorizontalStepSize(SizingType sizing) const;
 
	FORCEINLINE uint GetVerticalStepSize(SizingType sizing) const;
 

	
 
	virtual void Draw(const Window *w) = 0;
 
	virtual void SetDirty(const Window *w) const;
 

	
 
	WidgetType type;      ///< Type of the widget / nested widget.
 
	uint fill_x;          ///< Horizontal fill stepsize (from initial size, \c 0 means not resizable).
 
@@ -174,33 +174,54 @@ public:
 
	uint8 padding_top;    ///< Paddings added to the top of the widget. Managed by parent container widget.
 
	uint8 padding_right;  ///< Paddings added to the right of the widget. Managed by parent container widget.
 
	uint8 padding_bottom; ///< Paddings added to the bottom of the widget. Managed by parent container widget.
 
	uint8 padding_left;   ///< Paddings added to the left of the widget. Managed by parent container widget.
 

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

	
 
/**
 
 * Get the horizontal sizing step.
 
 * @param sizing Type of resize being performed.
 
 */
 
inline uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
 
FORCEINLINE uint NWidgetBase::GetHorizontalStepSize(SizingType sizing) const
 
{
 
	return (sizing == ST_RESIZE) ? this->resize_x : this->fill_x;
 
}
 

	
 
/**
 
 * Get the vertical sizing step.
 
 * @param sizing Type of resize being performed.
 
 */
 
inline uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
 
FORCEINLINE uint NWidgetBase::GetVerticalStepSize(SizingType sizing) const
 
{
 
	return (sizing == ST_RESIZE) ? this->resize_y : this->fill_y;
 
}
 

	
 
/**
 
 * Store size and position.
 
 * @param sizing       Type of resizing to perform.
 
 * @param x            Horizontal offset of the widget relative to the left edge of the window.
 
 * @param y            Vertical offset of the widget relative to the top edge of the window.
 
 * @param given_width  Width allocated to the widget.
 
 * @param given_height Height allocated to the widget.
 
 */
 
FORCEINLINE void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
 
{
 
	this->pos_x = x;
 
	this->pos_y = y;
 
	if (sizing == ST_SMALLEST) {
 
		this->smallest_x = given_width;
 
		this->smallest_y = given_height;
 
	}
 
	this->current_x = given_width;
 
	this->current_y = given_height;
 
}
 

	
 

	
 
/** Base class for a resizable nested widget.
 
 * @ingroup NestedWidgets */
 
class NWidgetResizeBase : public NWidgetBase {
 
public:
 
	NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
 

	
0 comments (0 inline, 0 general)