File diff r13693:eeeac228d9d9 → r13694:4523784084b5
src/widget.cpp
Show inline comments
 
@@ -738,16 +738,16 @@ NWidgetBase *NWidgetBase::GetWidgetOfTyp
 
	return (this->type == tp) ? this : NULL;
 
}
 

	
 
/**
 
 * Constructor for resizable nested widgets.
 
 * @param tp     Nested widget type.
 
 * @param fill_x Allow horizontal filling from initial size.
 
 * @param fill_y Allow vertical filling from initial size.
 
 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
 
 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
 
 */
 
NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, bool fill_x, bool fill_y) : NWidgetBase(tp)
 
NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
 
{
 
	this->fill_x = fill_x;
 
	this->fill_y = fill_y;
 
}
 

	
 
/**
 
@@ -771,16 +771,16 @@ void NWidgetResizeBase::SetMinimalTextLi
 
{
 
	this->min_y = min_lines * GetCharacterHeight(size) + spacing;
 
}
 

	
 
/**
 
 * Set the filling of the widget from initial size.
 
 * @param fill_x Allow horizontal filling from initial size.
 
 * @param fill_y Allow vertical filling from initial size.
 
 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
 
 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
 
 */
 
void NWidgetResizeBase::SetFill(bool fill_x, bool fill_y)
 
void NWidgetResizeBase::SetFill(uint fill_x, uint fill_y)
 
{
 
	this->fill_x = fill_x;
 
	this->fill_y = fill_y;
 
}
 

	
 
/**
 
@@ -805,13 +805,13 @@ void NWidgetResizeBase::AssignSizePositi
 
 * @param colour      Colour of the widget.
 
 * @param fill_x      Default horizontal filling.
 
 * @param fill_y      Default vertical filling.
 
 * @param widget_data Data component of the widget. @see Widget::data
 
 * @param tool_tip    Tool tip of the widget. @see Widget::tootips
 
 */
 
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, bool fill_x, bool fill_y, uint16 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
 
NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint16 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
 
{
 
	this->colour = colour;
 
	this->index = -1;
 
	this->widget_data = widget_data;
 
	this->tool_tip = tool_tip;
 
}
 
@@ -952,14 +952,14 @@ void NWidgetStacked::SetupSmallestSize(W
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 

	
 
	/* Zero size plane selected */
 
	if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) {
 
		this->fill_x = false;
 
		this->fill_y = false;
 
		this->fill_x = 0;
 
		this->fill_y = 0;
 

	
 
		Dimension size = {0, 0};
 
		Dimension resize = {0, 0};
 
		Dimension padding = {0, 0};
 
		/* Here we're primarily interested in the value of resize */
 
		w->UpdateWidgetSize(this->index, &size, padding, &resize);
 
@@ -971,23 +971,23 @@ void NWidgetStacked::SetupSmallestSize(W
 
		return;
 
	}
 

	
 
	/* First sweep, recurse down and compute minimal size and filling. */
 
	this->smallest_x = 0;
 
	this->smallest_y = 0;
 
	this->fill_x = (this->head != NULL);
 
	this->fill_y = (this->head != NULL);
 
	this->fill_x = (this->head != NULL) ? 1 : 0;
 
	this->fill_y = (this->head != NULL) ? 1 : 0;
 
	this->resize_x = (this->head != NULL) ? 1 : 0;
 
	this->resize_y = (this->head != NULL) ? 1 : 0;
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		child_wid->SetupSmallestSize(w, init_array);
 

	
 
		this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
 
		this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
 
		this->fill_x &= child_wid->fill_x;
 
		this->fill_y &= child_wid->fill_y;
 
		this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
 
		this->fill_y = LeastCommonMultiple(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 rtl)
 
@@ -1096,29 +1096,29 @@ NWidgetCore *NWidgetPIPContainer::GetWid
 
NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
 
{
 
}
 

	
 
void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
 
{
 
	this->smallest_x = 0;   // Sum of minimal size of all childs.
 
	this->smallest_y = 0;   // Biggest child.
 
	this->fill_x = false;   // true if at least one child allows fill_x.
 
	this->fill_y = true;    // true if all childs allow fill_y.
 
	this->resize_x = 0;     // smallest non-zero child widget resize step.
 
	this->resize_y = 1;     // smallest common child resize step
 
	this->smallest_x = 0; // Sum of minimal size of all childs.
 
	this->smallest_y = 0; // Biggest child.
 
	this->fill_x = 0;     // smallest non-zero child widget fill step.
 
	this->fill_y = 1;     // smallest common child fill step.
 
	this->resize_x = 0;   // smallest non-zero child widget resize step.
 
	this->resize_y = 1;   // smallest common child resize step.
 

	
 
	/* 1. Forward call, collect biggest nested array index, and longest child length. */
 
	uint longest = 0; // Longest child found.
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		child_wid->SetupSmallestSize(w, init_array);
 
		longest = max(longest, child_wid->smallest_x);
 
	}
 
	/* 2. For containers that must maintain equal width, extend child minimal size. */
 
	if (this->flags & NC_EQUALSIZE) {
 
		for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
			if (child_wid->fill_x) child_wid->smallest_x = longest;
 
			if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
 
		}
 
	}
 
	/* 3. Move PIP space to the childs, compute smallest, fill, and resize values of the container. */
 
	if (this->head != NULL) this->head->padding_left += this->pip_pre;
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		if (child_wid->next != NULL) {
 
@@ -1126,14 +1126,16 @@ void NWidgetHorizontal::SetupSmallestSiz
 
		} else {
 
			child_wid->padding_right += this->pip_post;
 
		}
 

	
 
		this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
 
		this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
 
		this->fill_x |= child_wid->fill_x;
 
		this->fill_y &= child_wid->fill_y;
 
		if (child_wid->fill_x > 0) {
 
			if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
 
		}
 
		this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
 

	
 
		if (child_wid->resize_x > 0) {
 
			if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x;
 
		}
 
		this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
 
	}
 
@@ -1225,29 +1227,29 @@ void NWidgetHorizontalLTR::AssignSizePos
 
NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
 
{
 
}
 

	
 
void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
 
{
 
	this->smallest_x = 0;   // Biggest child.
 
	this->smallest_y = 0;   // Sum of minimal size of all childs.
 
	this->fill_x = true;    // true if all childs allow fill_x.
 
	this->fill_y = false;   // true if at least one child allows fill_y.
 
	this->resize_x = 1;     // smallest common child resize step
 
	this->resize_y = 0;     // smallest non-zero child widget resize step.
 
	this->smallest_x = 0; // Biggest child.
 
	this->smallest_y = 0; // Sum of minimal size of all childs.
 
	this->fill_x = 1;     // smallest common child fill step.
 
	this->fill_y = 0;     // smallest non-zero child widget fill step.
 
	this->resize_x = 1;   // smallest common child resize step.
 
	this->resize_y = 0;   // smallest non-zero child widget resize step.
 

	
 
	/* 1. Forward call, collect biggest nested array index, and longest child length. */
 
	uint highest = 0; // Highest child found.
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		child_wid->SetupSmallestSize(w, init_array);
 
		highest = max(highest, child_wid->smallest_y);
 
	}
 
	/* 2. For containers that must maintain equal width, extend child minimal size. */
 
	if (this->flags & NC_EQUALSIZE) {
 
		for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
			if (child_wid->fill_y) child_wid->smallest_y = highest;
 
			if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
 
		}
 
	}
 
	/* 3. Move PIP space to the childs, compute smallest, fill, and resize values of the container. */
 
	if (this->head != NULL) this->head->padding_top += this->pip_pre;
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
 
		if (child_wid->next != NULL) {
 
@@ -1255,14 +1257,16 @@ void NWidgetVertical::SetupSmallestSize(
 
		} else {
 
			child_wid->padding_bottom += this->pip_post;
 
		}
 

	
 
		this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
 
		this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
 
		this->fill_y |= child_wid->fill_y;
 
		this->fill_x &= child_wid->fill_x;
 
		if (child_wid->fill_y > 0) {
 
			if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
 
		}
 
		this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
 

	
 
		if (child_wid->resize_y > 0) {
 
			if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y;
 
		}
 
		this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
 
	}
 
@@ -1330,13 +1334,13 @@ void NWidgetVertical::AssignSizePosition
 

	
 
/**
 
 * Generic spacer widget.
 
 * @param length Horizontal size of the spacer widget.
 
 * @param height Vertical size of the spacer widget.
 
 */
 
NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, false, false)
 
NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
 
{
 
	this->SetMinimalSize(length, height);
 
	this->SetResize(0, 0);
 
}
 

	
 
void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array)
 
@@ -1370,13 +1374,13 @@ NWidgetCore *NWidgetSpacer::GetWidgetFro
 
 * @param colour Colour of the parent widget.
 
 * @param index  Index in the widget array used by the window system.
 
 * @param child  Child container widget (if supplied). If not supplied, a
 
 *               vertical container will be inserted while adding the first
 
 *               child widget.
 
 */
 
NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, true, true, 0x0, STR_NULL)
 
NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL)
 
{
 
	assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
 
	if (index >= 0) this->SetIndex(index);
 
	this->child = child;
 
}
 

	
 
@@ -1552,13 +1556,13 @@ NWidgetBase *NWidgetBackground::GetWidge
 
	NWidgetBase *nwid = NULL;
 
	if (this->child != NULL) nwid = this->child->GetWidgetOfType(tp);
 
	if (nwid == NULL && this->type == tp) nwid = this;
 
	return nwid;
 
}
 

	
 
NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, true, true, 0x0, STR_NULL)
 
NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
 
{
 
	this->SetIndex(index);
 
}
 

	
 
void NWidgetViewport::SetupSmallestSize(Window *w, bool init_array)
 
{
 
@@ -1639,86 +1643,86 @@ Dimension NWidgetLeaf::closebox_dimensio
 
 * @param tp     Type of leaf widget.
 
 * @param colour Colour of the leaf widget.
 
 * @param index  Index in the widget array used by the window system.
 
 * @param data   Data of the widget.
 
 * @param tip    Tooltip of the widget.
 
 */
 
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, true, true, data, tip)
 
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
 
{
 
	this->SetIndex(index);
 
	this->SetMinimalSize(0, 0);
 
	this->SetResize(0, 0);
 

	
 
	switch (tp) {
 
		case WWT_EMPTY:
 
			break;
 

	
 
		case WWT_PUSHBTN:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			break;
 

	
 
		case WWT_IMGBTN:
 
		case WWT_PUSHIMGBTN:
 
		case WWT_IMGBTN_2:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			break;
 

	
 
		case WWT_TEXTBTN:
 
		case WWT_PUSHTXTBTN:
 
		case WWT_TEXTBTN_2:
 
		case WWT_LABEL:
 
		case WWT_TEXT:
 
		case WWT_MATRIX:
 
		case WWT_EDITBOX:
 
		case NWID_BUTTON_DROPDOWN:
 
		case NWID_BUTTON_ARROW:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			break;
 

	
 
		case WWT_SCROLLBAR:
 
		case WWT_SCROLL2BAR:
 
			this->SetFill(false, true);
 
			this->SetFill(0, 1);
 
			this->SetResize(0, 1);
 
			this->min_x = WD_VSCROLLBAR_WIDTH;
 
			this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
 
			break;
 

	
 
		case WWT_CAPTION:
 
			this->SetFill(true, false);
 
			this->SetFill(1, 0);
 
			this->SetResize(1, 0);
 
			this->min_y = WD_CAPTION_HEIGHT;
 
			this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
 
			break;
 

	
 
		case WWT_HSCROLLBAR:
 
			this->SetFill(true, false);
 
			this->SetFill(1, 0);
 
			this->SetResize(1, 0);
 
			this->min_y = WD_HSCROLLBAR_HEIGHT;
 
			this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
 
			break;
 

	
 
		case WWT_STICKYBOX:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_STICKYBOX_WIDTH, 14);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
 
			break;
 

	
 
		case WWT_RESIZEBOX:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
 
			break;
 

	
 
		case WWT_CLOSEBOX:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_CLOSEBOX_WIDTH, 14);
 
			this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW);
 
			break;
 

	
 
		case WWT_DROPDOWN:
 
			this->SetFill(false, false);
 
			this->SetFill(0, 0);
 
			this->min_y = WD_DROPDOWN_HEIGHT;
 
			break;
 

	
 
		default:
 
			NOT_REACHED();
 
	}
 
@@ -2125,13 +2129,13 @@ static int MakeNWidget(const NWidgetPart
 
				}
 
				break;
 
			}
 

	
 
			case WPT_FILL: {
 
				NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
 
				if (nwrb != NULL) nwrb->SetFill(parts->u.xy.x != 0, parts->u.xy.y != 0);
 
				if (nwrb != NULL) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
 
				break;
 
			}
 

	
 
			case WPT_DATATIP: {
 
				NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
 
				if (nwc != NULL) {