Mercurial > hg > openttd
changeset 13246:6ed0d462f914 draft
(svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
author | alberth <alberth@openttd.org> |
---|---|
date | Sat, 10 Oct 2009 14:20:38 +0000 |
parents | 507592717f3a |
children | fa47ce23bcfd |
files | src/widget.cpp src/widget_type.h |
diffstat | 2 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/widget.cpp +++ b/src/widget.cpp @@ -1289,6 +1289,17 @@ 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; @@ -1313,6 +1324,8 @@ 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); @@ -1341,6 +1354,8 @@ 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) { @@ -1351,7 +1366,7 @@ } } - 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); @@ -1360,6 +1375,8 @@ 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) {
--- a/src/widget_type.h +++ b/src/widget_type.h @@ -376,8 +376,15 @@ 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: