summaryrefslogtreecommitdiff
path: root/src/widget.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-10-10 14:20:38 +0000
committeralberth <alberth@openttd.org>2009-10-10 14:20:38 +0000
commitcfbd5ba59b987e3b8b22be43b2af99e0285a5d11 (patch)
tree68c738f76a9ee4552a500f46a3ecfb676556fa63 /src/widget.cpp
parent402d0d05c920f6066d7052f1222d04dad651fcb1 (diff)
downloadopenttd-cfbd5ba59b987e3b8b22be43b2af99e0285a5d11.tar.xz
(svn r17755) -Codechange: Allow for a zero-size display plane in a NWidgetStacked widget to hide its child widgets.
Diffstat (limited to 'src/widget.cpp')
-rw-r--r--src/widget.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 640f650d3..bf11a2912 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -1289,6 +1289,17 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
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 @@ void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint
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::FillNestedArray(NWidgetBase **array, uint 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) {
@@ -1351,7 +1366,7 @@ void NWidgetStacked::Draw(const Window *w)
}
}
- 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 @@ void NWidgetStacked::Draw(const Window *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) {