diff options
author | alberth <alberth@openttd.org> | 2009-12-22 20:43:25 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-12-22 20:43:25 +0000 |
commit | 3323d64f280cea84addc96d0018adaf93bb4e43b (patch) | |
tree | 3b19aa044205e1e454be4842a12f956840d49b0b | |
parent | 7dbc77a1e74be00f520e84fa1605a9ba42a05879 (diff) | |
download | openttd-3323d64f280cea84addc96d0018adaf93bb4e43b.tar.xz |
(svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
-rw-r--r-- | src/build_vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/company_gui.cpp | 12 | ||||
-rw-r--r-- | src/misc_gui.cpp | 6 | ||||
-rw-r--r-- | src/timetable_gui.cpp | 2 | ||||
-rw-r--r-- | src/widget.cpp | 14 | ||||
-rw-r--r-- | src/widget_type.h | 16 | ||||
-rw-r--r-- | src/window.cpp | 2 | ||||
-rw-r--r-- | src/window_gui.h | 2 |
8 files changed, 30 insertions, 26 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 9a8bb4320..50a1ffd49 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -817,7 +817,7 @@ struct BuildVehicleWindow : Window { /* If we are just viewing the list of vehicles, we do not need the Build button. * So we just hide it, and enlarge the Rename buton by the now vacant place. */ - if (this->listview_mode) this->GetWidget<NWidgetStacked>(BUILD_VEHICLE_WIDGET_BUILD_SEL)->SetDisplayedPlane(STACKED_SELECTION_ZERO_SIZE); + if (this->listview_mode) this->GetWidget<NWidgetStacked>(BUILD_VEHICLE_WIDGET_BUILD_SEL)->SetDisplayedPlane(SZSP_NONE); NWidgetCore *widget = this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST); widget->tool_tip = STR_BUY_VEHICLE_TRAIN_LIST_TOOLTIP + type; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 2eaeef22a..a5e308351 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -392,12 +392,12 @@ struct CompanyFinancesWindow : Window { */ void SetupWidgets() { - int plane = this->small ? STACKED_SELECTION_ZERO_SIZE : 0; + int plane = this->small ? SZSP_NONE : 0; this->GetWidget<NWidgetStacked>(CFW_SEL_PANEL)->SetDisplayedPlane(plane); this->GetWidget<NWidgetStacked>(CFW_SEL_MAXLOAN)->SetDisplayedPlane(plane); CompanyID company = (CompanyID)this->window_number; - plane = (company != _local_company) ? STACKED_SELECTION_ZERO_SIZE : 0; + plane = (company != _local_company) ? SZSP_NONE : 0; this->GetWidget<NWidgetStacked>(CFW_SEL_BUTTONS)->SetDisplayedPlane(plane); } @@ -416,7 +416,7 @@ struct CompanyFinancesWindow : Window { /* Check that the loan buttons are shown only when the user owns the company. */ CompanyID company = (CompanyID)this->window_number; - int req_plane = (company != _local_company) ? STACKED_SELECTION_ZERO_SIZE : 0; + int req_plane = (company != _local_company) ? SZSP_NONE : 0; if (req_plane != this->GetWidget<NWidgetStacked>(CFW_SEL_BUTTONS)->shown_plane) { this->SetupWidgets(); this->ReInit(); @@ -1143,9 +1143,9 @@ public: */ void SelectDisplayPlanes(bool advanced) { - this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : STACKED_SELECTION_ZERO_SIZE); - this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : STACKED_SELECTION_ZERO_SIZE); - this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? STACKED_SELECTION_ZERO_SIZE : 0); + this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE); + this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE); + this->GetWidget<NWidgetStacked>(SCMFW_WIDGET_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? SZSP_NONE : 0); this->GetWidget<NWidgetCore>(SCMFW_WIDGET_RANDOM_NEW_FACE)->widget_data = advanced ? STR_MAPGEN_RANDOM : STR_FACE_NEW_FACE_BUTTON; NWidgetCore *wi = this->GetWidget<NWidgetCore>(SCMFW_WIDGET_TOGGLE_LARGE_SMALL_BUTTON); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index d0f0690e0..da2cc86d0 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1766,7 +1766,7 @@ public: InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size, 240); this->CreateNestedTree(desc); - if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(SLWW_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(STACKED_SELECTION_ZERO_SIZE); + if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(SLWW_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL); this->GetWidget<NWidgetCore>(SLWW_WINDOWTITLE)->widget_data = saveload_captions[mode]; this->FinishInitNested(desc, 0); @@ -1862,10 +1862,6 @@ public: virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) { switch (widget) { - case SLWW_CONTENT_DOWNLOAD_SEL: - resize->width = 1; - break; - case SLWW_BACKGROUND: size->height = 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; break; diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 0af26e8b8..f9de4e7eb 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -593,7 +593,7 @@ struct TimetableWindow : Window { */ void UpdateSelectionStates() { - this->GetWidget<NWidgetStacked>(TTV_ARRIVAL_DEPARTURE_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : STACKED_SELECTION_ZERO_SIZE); + this->GetWidget<NWidgetStacked>(TTV_ARRIVAL_DEPARTURE_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : SZSP_NONE); this->GetWidget<NWidgetStacked>(TTV_EXPECTED_SELECTION)->SetDisplayedPlane(_settings_client.gui.timetable_arrival_departure ? 0 : 1); } }; diff --git a/src/widget.cpp b/src/widget.cpp index a79d01197..bf8a7d97b 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -965,11 +965,11 @@ void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array) } /* Zero size plane selected */ - if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) { - Dimension size = {0, 0}; + if (this->shown_plane >= SZSP_BEGIN) { + Dimension size = {0, 0}; Dimension padding = {0, 0}; - Dimension fill = {0, 0}; - Dimension resize = {0, 0}; + Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)}; + Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)}; /* Here we're primarily interested in the value of resize */ if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize); @@ -1006,7 +1006,7 @@ 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); - if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) return; + if (this->shown_plane >= SZSP_BEGIN) return; for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) { uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing); @@ -1029,7 +1029,7 @@ void NWidgetStacked::FillNestedArray(NWidgetBase **array, uint length) void NWidgetStacked::Draw(const Window *w) { - if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) return; + if (this->shown_plane >= SZSP_BEGIN) return; int plane = 0; for (NWidgetBase *child_wid = this->head; child_wid != NULL; plane++, child_wid = child_wid->next) { @@ -1044,7 +1044,7 @@ void NWidgetStacked::Draw(const Window *w) NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y) { - if (this->shown_plane == STACKED_SELECTION_ZERO_SIZE) return NULL; + if (this->shown_plane >= SZSP_BEGIN) return NULL; if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL; int plane = 0; diff --git a/src/widget_type.h b/src/widget_type.h index f54381e61..0119f37da 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -312,15 +312,23 @@ protected: 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. +/** Display planes with zero size for #NWidgetStacked. */ +enum StackedZeroSizePlanes { + SZSP_VERTICAL = INT_MAX / 2, ///< Display plane with zero size horizontally, and filling and resizing vertically. + SZSP_HORIZONTAL, ///< Display plane with zero size vertically, and filling and resizing horizontally. + SZSP_NONE, ///< Display plane with zero size in both directions (none filling and resizing). + + SZSP_BEGIN = SZSP_VERTICAL, ///< First zero-size plane. +}; /** Stacked widgets, widgets all occupying the same space in the window. * #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. + * There are also a number of special planes (defined in #StackedZeroSizePlanes) that have zero size in one direction (and are stretchable in + * the other direction) or have zero size in both directions. They are used to make all child planes of the widget disappear. + * Unlike switching between the regular display planes (that all have the same size), switching from or to one of the zero-sized planes means that + * a #Windows::ReInit() is needed to re-initialize the window since its size changes. */ class NWidgetStacked : public NWidgetContainer { public: diff --git a/src/window.cpp b/src/window.cpp index f0d3ce931..45484cf09 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -552,7 +552,7 @@ void Window::SetShaded(bool make_shaded) { if (this->shade_select == NULL) return; - int desired = make_shaded ? STACKED_SELECTION_ZERO_SIZE : 0; + int desired = make_shaded ? SZSP_NONE : 0; if (this->shade_select->shown_plane != desired) { if (make_shaded) { this->unshaded_size.width = this->width; diff --git a/src/window_gui.h b/src/window_gui.h index d8d56c923..d36b704ad 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -540,7 +540,7 @@ public: /** Is window shaded currently? */ inline bool IsShaded() const { - return this->shade_select != NULL && this->shade_select->shown_plane == STACKED_SELECTION_ZERO_SIZE; + return this->shade_select != NULL && this->shade_select->shown_plane == SZSP_NONE; } void SetShaded(bool make_shaded); |