Changeset - r13666:d9a01e26bf6c
[Not reviewed]
master
0 5 0
alberth - 15 years ago 2009-11-20 20:10:06
alberth@openttd.org
(svn r18201) -Codechange (r18092): No need anymore for initializing nested widgets for Widget* arrays.
5 files changed with 35 insertions and 47 deletions:
0 comments (0 inline, 0 general)
src/network/network_gui.cpp
Show inline comments
 
@@ -164,13 +164,13 @@ public:
 
		for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
			child_wid->current_x = child_wid->smallest_x;
 
			child_wid->current_y = this->smallest_y;
 
		}
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
	void 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);
 

	
 
		this->pos_x = x;
 
		this->pos_y = y;
 
		this->current_x = given_width;
 
@@ -195,13 +195,13 @@ public:
 
		/* Now assign the widgets to their rightful place */
 
		uint position = 0; // Place to put next child relative to origin of the container.
 
		uint i = rtl ? lengthof(this->visible) - 1 : 0;
 
		child_wid = rtl ? this->tail : this->head;
 
		while (child_wid != NULL) {
 
			if (this->visible[i]) {
 
				child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, allow_resize_x, (this->resize_y > 0), rtl);
 
				child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
 
				position += child_wid->current_x;
 
			}
 

	
 
			child_wid = rtl ? child_wid->prev : child_wid->next;
 
			i += rtl ? -1 : 1;
 
		}
src/toolbar_gui.cpp
Show inline comments
 
@@ -937,13 +937,13 @@ public:
 
			if (!this->IsButton(child_wid->type)) {
 
				child_wid->current_x = child_wid->smallest_x;
 
			}
 
		}
 
	}
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
	void 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);
 

	
 
		this->pos_x = x;
 
		this->pos_y = y;
 
		this->current_x = given_width;
 
@@ -989,13 +989,13 @@ public:
 
			/* Buttons can be scaled, the others not. */
 
			if (this->IsButton(child_wid->type)) {
 
				child_wid->current_x = button_space / (button_count - button_i);
 
				button_space -= child_wid->current_x;
 
				button_i++;
 
			}
 
			child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, allow_resize_x, (this->resize_y > 0), rtl);
 
			child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
 
			position += child_wid->current_x;
 

	
 
			if (rtl) {
 
				cur_wid--;
 
			} else {
 
				cur_wid++;
src/widget.cpp
Show inline comments
 
@@ -617,16 +617,15 @@ void Window::DrawSortButtonState(int wid
 
 * - Containers only know what their children are, \e fill_x, \e fill_y, \e resize_x, and \e resize_y are not initialized.
 
 *
 
 * Computations in the nested widgets take place as follows:
 
 * <ol>
 
 * <li> A bottom-up sweep by recursively calling NWidgetBase::SetupSmallestSize() to initialize the smallest size (\e smallest_x, \e smallest_y) and
 
 *      to propagate filling and resize steps upwards to the root of the tree.
 
 * <li> A top-down sweep by recursively calling NWidgetBase::AssignSizePosition() with #ST_ARRAY or #ST_SMALLEST to make the smallest sizes consistent over
 
 * <li> A top-down sweep by recursively calling NWidgetBase::AssignSizePosition() with #ST_SMALLEST to make the smallest sizes consistent over
 
 *      the entire tree, and to assign the top-left (\e pos_x, \e pos_y) position of each widget in the tree. This step uses \e fill_x and \e fill_y at each
 
 *      node in the tree to decide how to fill each widget towards consistent sizes. Also the current size (\e current_x and \e current_y) is set.
 
 *      For generating a widget array (#ST_ARRAY), resize step sizes are made consistent.
 
 * <li> After initializing the smallest size in the widget tree with #ST_SMALLEST, the tree can be resized (the current size modified) by calling
 
 *      NWidgetBase::AssignSizePosition() at the root with #ST_RESIZE and the new size of the window. For proper functioning, the new size should be the smallest
 
 *      size + a whole number of resize steps in both directions (ie you can only resize in steps of length resize_{x,y} from smallest_{x,y}).
 
 * </ol>
 
 * After the second step, the current size of the widgets are set to the smallest size.
 
 *
 
@@ -660,21 +659,19 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
 * @param init_array Initialize the \c w->nested_array as well. Should only be set if \a w != NULL.
 
 *
 
 * @note After the computation, the results can be queried by accessing the #smallest_x and #smallest_y data members of the widget.
 
 */
 

	
 
/**
 
 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
 * @fn void NWidgetBase::AssignSizePosition(SizingType sizing, uint x, uint 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.
 
 * @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.
 
 * @param allow_resize_x Horizontal resizing is allowed (only used when \a sizing is #ST_ARRAY).
 
 * @param allow_resize_y Vertical resizing is allowed (only used when \a sizing in #ST_ARRAY).
 
 * @param rtl            Adapt for right-to-left languages (position contents of horizontal containers backwards).
 
 *
 
 * Afterwards, \e pos_x and \e pos_y contain the top-left position of the widget, \e smallest_x and \e smallest_y contain
 
 * the smallest size such that all widgets of the window are consistent, and \e current_x and \e current_y contain the current size.
 
 */
 

	
 
@@ -689,27 +686,23 @@ NWidgetBase::NWidgetBase(WidgetType tp) 
 
 * 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.
 
 * @param allow_resize_x Horizontal resizing is allowed (only used when \a sizing is #ST_ARRAY).
 
 * @param allow_resize_y Vertical resizing is allowed (only used when \a sizing in #ST_ARRAY).
 
 */
 
inline void NWidgetBase::StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y)
 
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_ARRAY || sizing == ST_SMALLEST) {
 
	if (sizing == ST_SMALLEST) {
 
		this->smallest_x = given_width;
 
		this->smallest_y = given_height;
 
	}
 
	this->current_x = given_width;
 
	this->current_y = given_height;
 
	if (sizing == ST_ARRAY && !allow_resize_x) this->resize_x = 0;
 
	if (sizing == ST_ARRAY && !allow_resize_y) this->resize_y = 0;
 
}
 

	
 
/**
 
 * @fn void 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.
 
@@ -798,15 +791,15 @@ void NWidgetResizeBase::SetFill(bool fil
 
void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
 
{
 
	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 allow_resize_x, bool allow_resize_y, bool rtl)
 
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, allow_resize_x, allow_resize_y);
 
	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.
 
@@ -1006,29 +999,29 @@ void NWidgetStacked::SetupSmallestSize(W
 
		this->fill_y &= child_wid->fill_y;
 
		this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
 
		this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
 
	}
 
}
 

	
 
void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
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, allow_resize_x, allow_resize_y);
 
	StoreSizePosition(sizing, x, y, given_width, given_height);
 

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

	
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		uint hor_step = child_wid->GetHorizontalStepSize(sizing);
 
		uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
 
		uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left) + ComputeOffset(child_width, given_width - child_wid->padding_left - child_wid->padding_right);
 

	
 
		uint vert_step = child_wid->GetVerticalStepSize(sizing);
 
		uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
 
		uint child_pos_y = child_wid->padding_top + ComputeOffset(child_height,  given_height - child_wid->padding_top - child_wid->padding_bottom);
 

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

	
 
void NWidgetStacked::FillNestedArray(NWidgetBase **array, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
@@ -1157,18 +1150,18 @@ void NWidgetHorizontal::SetupSmallestSiz
 
		this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
 
	}
 
	/* We need to zero the PIP settings so we can re-initialize the tree. */
 
	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 allow_resize_x, bool allow_resize_y, bool rtl)
 
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, allow_resize_x, allow_resize_y);
 
	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.
 
	 *
 
@@ -1213,36 +1206,34 @@ void NWidgetHorizontal::AssignSizePositi
 
		biggest_stepsize = next_biggest_stepsize;
 
	}
 
	assert(num_changing_childs == 0);
 

	
 
	/* Third loop: Compute position and call the child. */
 
	uint position = 0; // Place to put next child relative to origin of the container.
 
	allow_resize_x = (this->resize_x > 0);
 
	NWidgetBase *child_wid = rtl ? this->tail : this->head;
 
	while (child_wid != NULL) {
 
		uint child_width = child_wid->current_x;
 
		uint child_x = x + position + (rtl ? child_wid->padding_right : child_wid->padding_left);
 
		uint child_y = y + child_wid->padding_top + ComputeOffset(child_wid->current_y,  given_height - child_wid->padding_top - child_wid->padding_bottom);
 

	
 
		child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, allow_resize_x, (this->resize_y > 0), rtl);
 
		child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
 
		position += child_width + child_wid->padding_right + child_wid->padding_left;
 
		if (child_wid->resize_x > 0) allow_resize_x = false; // Widget array allows only one child resizing
 

	
 
		child_wid = rtl ? child_wid->prev : child_wid->next;
 
	}
 
}
 

	
 
/** Horizontal left-to-right container widget. */
 
NWidgetHorizontalLTR::NWidgetHorizontalLTR(NWidContainerFlags flags) : NWidgetHorizontal(flags)
 
{
 
	this->type = NWID_HORIZONTAL_LTR;
 
}
 

	
 
void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
 
{
 
	NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, allow_resize_x, allow_resize_y, false);
 
	NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
 
}
 

	
 
/** Vertical container widget. */
 
NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
 
{
 
}
 
@@ -1288,18 +1279,18 @@ void NWidgetVertical::SetupSmallestSize(
 
		this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
 
	}
 
	/* We need to zero the PIP settings so we can re-initialize the tree. */
 
	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 allow_resize_x, bool allow_resize_y, bool rtl)
 
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, allow_resize_x, allow_resize_y);
 
	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. */
 
@@ -1337,21 +1328,19 @@ void NWidgetVertical::AssignSizePosition
 
		biggest_stepsize = next_biggest_stepsize;
 
	}
 
	assert(num_changing_childs == 0);
 

	
 
	/* Third loop: Compute position and call the child. */
 
	uint position = 0; // Place to put next child relative to origin of the container.
 
	allow_resize_y = (this->resize_y > 0);
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left) +
 
									ComputeOffset(child_wid->current_x, given_width - child_wid->padding_left - child_wid->padding_right);
 
		uint child_height = child_wid->current_y;
 

	
 
		child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, (this->resize_x > 0), allow_resize_y, rtl);
 
		child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
 
		position += child_height + child_wid->padding_top + child_wid->padding_bottom;
 
		if (child_wid->resize_y > 0) allow_resize_y = false; // Widget array allows only one child resizing
 
	}
 
}
 

	
 
/**
 
 * Generic spacer widget.
 
 * @param length Horizontal size of the spacer widget.
 
@@ -1491,21 +1480,21 @@ void NWidgetBackground::SetupSmallestSiz
 
		this->smallest_y = d.height;
 
		this->resize_x = resize.width;
 
		this->resize_y = resize.height;
 
	}
 
}
 

	
 
void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl)
 
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, allow_resize_x, allow_resize_y);
 
	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, (this->resize_x > 0), (this->resize_y > 0), rtl);
 
		this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, rtl);
 
	}
 
}
 

	
 
void NWidgetBackground::FillNestedArray(NWidgetBase **array, uint length)
 
{
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
src/widget_type.h
Show inline comments
 
@@ -151,13 +151,12 @@ enum WidgetType {
 
	WWT_PUSHTXTBTN  = WWT_TEXTBTN | WWB_PUSHBUTTON,
 
	WWT_PUSHIMGBTN  = WWT_IMGBTN  | WWB_PUSHBUTTON,
 
};
 

	
 
/** Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition() */
 
enum SizingType {
 
	ST_ARRAY,    ///< Initialize nested widget tree to generate a #Widget * array.
 
	ST_SMALLEST, ///< Initialize nested widget tree to smallest size. Also updates \e current_x and \e current_y.
 
	ST_RESIZE,   ///< Resize the nested widget tree.
 
};
 

	
 
/* Forward declarations. */
 
class NWidgetCore;
 
@@ -171,13 +170,13 @@ class Scrollbar;
 
 */
 
class NWidgetBase : public ZeroedMemoryAllocator {
 
public:
 
	NWidgetBase(WidgetType tp);
 

	
 
	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 allow_resize_x, bool allow_resize_y, bool rtl) = 0;
 
	virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 0;
 

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

	
 
	virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
 
	virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
 

	
 
@@ -225,13 +224,13 @@ 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, bool allow_resize_x, bool allow_resize_y);
 
	inline 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.
 
 */
 
@@ -259,13 +258,13 @@ public:
 

	
 
	void SetMinimalSize(uint min_x, uint min_y);
 
	void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
 
	void SetFill(bool fill_x, bool fill_y);
 
	void SetResize(uint resize_x, uint resize_y);
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl);
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
 

	
 
	uint min_x; ///< Minimal horizontal size of only this widget.
 
	uint min_y; ///< Minimal vertical size of only this widget.
 
};
 

	
 
/** Nested widget flags that affect display and interaction withe 'real' widgets. */
 
@@ -380,13 +379,13 @@ class NWidgetStacked : public NWidgetCon
 
public:
 
	NWidgetStacked();
 

	
 
	void SetIndex(int index);
 

	
 
	void SetupSmallestSize(Window *w, bool init_array);
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool allow_resize_x, bool allow_resize_y, bool rtl);
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl);
 
	/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
 

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

	
 
	void SetDisplayedPlane(int plane);
 
@@ -425,32 +424,32 @@ protected:
 
 * @ingroup NestedWidgets */
 
class NWidgetHorizontal : public NWidgetPIPContainer {
 
public:
 
	NWidgetHorizontal(NWidContainerFlags flags = NC_NONE);
 

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

	
 
/** Horizontal container that doesn't change the direction of the widgets for RTL languages.
 
 * @ingroup NestedWidgets */
 
class NWidgetHorizontalLTR : public NWidgetHorizontal {
 
public:
 
	NWidgetHorizontalLTR(NWidContainerFlags flags = NC_NONE);
 

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

	
 
/** Vertical container.
 
 * @ingroup NestedWidgets */
 
class NWidgetVertical : public NWidgetPIPContainer {
 
public:
 
	NWidgetVertical(NWidContainerFlags flags = NC_NONE);
 

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

	
 

	
 
/** Spacer widget.
 
 * @ingroup NestedWidgets */
 
class NWidgetSpacer : public NWidgetResizeBase {
 
@@ -473,13 +472,13 @@ public:
 
	~NWidgetBackground();
 

	
 
	void Add(NWidgetBase *nwid);
 
	void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
 

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

	
 
	/* virtual */ void FillNestedArray(NWidgetBase **array, uint length);
 

	
 
	/* virtual */ void Draw(const Window *w);
 
	/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
 
	/* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
src/window.cpp
Show inline comments
 
@@ -495,13 +495,13 @@ void Window::ReInit(int rx, int ry)
 
	/* Save current size. */
 
	int window_width  = this->width;
 
	int window_height = this->height;
 

	
 
	/* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
 
	this->nested_root->SetupSmallestSize(this, false);
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, _dynlang.text_dir == TD_RTL);
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _dynlang.text_dir == TD_RTL);
 
	this->width  = this->nested_root->smallest_x;
 
	this->height = this->nested_root->smallest_y;
 
	this->resize.width  = this->nested_root->smallest_x;
 
	this->resize.height = this->nested_root->smallest_y;
 
	this->resize.step_width  = this->nested_root->resize_x;
 
	this->resize.step_height = this->nested_root->resize_y;
 
@@ -781,13 +781,13 @@ void Window::InitializeData(WindowClass 
 
		this->nested_array = CallocT<NWidgetBase *>(this->nested_array_size);
 
		this->nested_root->SetupSmallestSize(this, true);
 
	} else {
 
		this->nested_root->SetupSmallestSize(this, false);
 
	}
 
	/* Initialize to smallest size. */
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, _dynlang.text_dir == TD_RTL);
 
	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, _dynlang.text_dir == TD_RTL);
 

	
 
	/* Further set up window properties,
 
	 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
 
	this->resize.step_width  = (this->nested_root != NULL) ? this->nested_root->resize_x : 1;
 
	this->resize.step_height = (this->nested_root != NULL) ? this->nested_root->resize_y : 1;
 

	
 
@@ -1354,13 +1354,13 @@ void ResizeWindow(Window *w, int delta_x
 

	
 
	uint new_xinc = max(0, (w->nested_root->resize_x == 0) ? 0 : (int)(w->nested_root->current_x - w->nested_root->smallest_x) + delta_x);
 
	uint new_yinc = max(0, (w->nested_root->resize_y == 0) ? 0 : (int)(w->nested_root->current_y - w->nested_root->smallest_y) + delta_y);
 
	assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
 
	assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
 

	
 
	w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, false, false, _dynlang.text_dir == TD_RTL);
 
	w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, _dynlang.text_dir == TD_RTL);
 
	w->width  = w->nested_root->current_x;
 
	w->height = w->nested_root->current_y;
 
	w->SetDirty();
 
}
 

	
 
/** Return the top of the main view available for general use.
0 comments (0 inline, 0 general)