Mercurial > hg > openttd
changeset 14063:4eb2be463cc4 draft
(svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.
author | alberth <alberth@openttd.org> |
---|---|
date | Tue, 22 Dec 2009 20:43:25 +0000 |
parents | 9103e248263f |
children | 07b6b76bd9df |
files | src/build_vehicle_gui.cpp src/company_gui.cpp src/misc_gui.cpp src/timetable_gui.cpp src/widget.cpp src/widget_type.h src/window.cpp src/window_gui.h |
diffstat | 8 files changed, 30 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -817,7 +817,7 @@ /* 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;
--- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -392,12 +392,12 @@ */ 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 @@ /* 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 @@ */ 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);
--- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1766,7 +1766,7 @@ 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 @@ 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;
--- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -593,7 +593,7 @@ */ 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); } };
--- a/src/widget.cpp +++ b/src/widget.cpp @@ -965,11 +965,11 @@ } /* 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 @@ 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::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 @@ 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;
--- a/src/widget_type.h +++ b/src/widget_type.h @@ -312,15 +312,23 @@ 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:
--- a/src/window.cpp +++ b/src/window.cpp @@ -552,7 +552,7 @@ { 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;
--- a/src/window_gui.h +++ b/src/window_gui.h @@ -540,7 +540,7 @@ /** 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);