Changeset - r13236:0570294be840
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-10-10 14:20:38
alberth@openttd.org
(svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
2 files changed with 26 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -1286,12 +1286,23 @@ void NWidgetStacked::SetupSmallestSize(W
 
{
 
	if (this->index >= 0 && init_array) { // Fill w->nested_array[]
 
		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->smallest_x = 0;
 
		this->smallest_y = 0;
 
		this->fill_x = false;
 
		this->fill_y = false;
 
		this->resize_x = 0;
 
		this->resize_y = 0;
 
		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->resize_x = (this->head != NULL) ? 1 : 0;
 
@@ -1310,12 +1321,14 @@ void NWidgetStacked::SetupSmallestSize(W
 

	
 
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)
 
{
 
	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);
 

	
 
	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);
 
@@ -1338,31 +1351,35 @@ void NWidgetStacked::FillNestedArray(NWi
 
	if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
 
	NWidgetContainer::FillNestedArray(array, length);
 
}
 

	
 
void NWidgetStacked::Draw(const Window *w)
 
{
 
	if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) return;
 

	
 
	if (this->type == NWID_SELECTION) {
 
		int plane = 0;
 
		for (NWidgetBase *child_wid = this->head; child_wid != NULL; plane++, child_wid = child_wid->next) {
 
			if (plane == this->shown_plane) {
 
				child_wid->Draw(w);
 
				return;
 
			}
 
		}
 
	}
 

	
 
	assert(this->type == NWID_LAYERED); // Currently, NWID_SELECTION is not supported.
 
	assert(this->type == NWID_LAYERED);
 
	/* Render from back to front. */
 
	for (NWidgetBase *child_wid = this->tail; child_wid != NULL; child_wid = child_wid->prev) {
 
		child_wid->Draw(w);
 
	}
 
}
 

	
 
NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
 
{
 
	if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) return NULL;
 

	
 
	if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
 
	int plane = 0;
 
	for (NWidgetBase *child_wid = this->head; child_wid != NULL; plane++, child_wid = child_wid->next) {
 
		if (plane == this->shown_plane) {
 
			return child_wid->GetWidgetFromPos(x, y);
 
		}
src/widget_type.h
Show inline comments
 
@@ -373,14 +373,21 @@ public:
 

	
 
protected:
 
	NWidgetBase *head; ///< Pointer to first widget in container.
 
	NWidgetBase *tail; ///< Pointer to last widget in container.
 
};
 

	
 
static const int STACKED_SELECTION_ZERO_SIZE = INT_MAX; ///< Display plane value for getting a zero-size widget.
 

	
 
/** Stacked widgets, widgets all occupying the same space in the window.
 
 * @note the semantics difference between #NWID_SELECTION and #NWID_LAYERED is currently not used.
 
 * #NWID_SELECTION allows for selecting one of several panels (planes) to tbe displayed. All planes must have the same size.
 
 * Since all planes are also initialized, switching between different planes can be done while the window is displayed.
 
 *
 
 * There is also a special plane #STACKED_SELECTION_ZERO_SIZE which always has zero size, and is not resizable or fillable. It is used to make all child
 
 * planes of the widget disappear. Unlike the regular display planes, switching from or to the #STACKED_SELECTION_ZERO_SIZE plane means that a
 
 * #Windows::ReInit() is needed to re-initialize the window.
 
 */
 
class NWidgetStacked : public NWidgetContainer {
 
public:
 
	NWidgetStacked(WidgetType tp);
 

	
 
	void SetIndex(int index);
0 comments (0 inline, 0 general)