(svn r18606) -Codechange: Introduce several forms of zero-size stacked display planes.

This commit is contained in:
alberth 2009-12-22 20:43:25 +00:00
parent 7dbc77a1e7
commit 3323d64f28
8 changed files with 30 additions and 26 deletions

View File

@ -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;

View File

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

View File

@ -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;

View File

@ -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);
}
};

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

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