Changeset - r25324:71e56110ba9f
[Not reviewed]
master
0 13 0
Peter Nelson - 4 years ago 2021-04-05 17:43:12
peter1138@openttd.org
Fix: Recalculate padding and minimum sizes when GUI or Font zoom is changed.
13 files changed with 129 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -1282,13 +1282,13 @@ void LoadStringWidthTable(bool monospace
 
	for (FontSize fs = monospace ? FS_MONO : FS_BEGIN; fs < (monospace ? FS_END : FS_MONO); fs++) {
 
		for (uint i = 0; i != 224; i++) {
 
			_stringwidth_table[fs][i] = GetGlyphWidth(fs, i + 32);
 
		}
 
	}
 

	
 
	ReInitAllWindows();
 
	ReInitAllWindows(false);
 
}
 

	
 
/**
 
 * Return width of character glyph.
 
 * @param size  Font of the character
 
 * @param key   Character code glyph
src/gfxinit.cpp
Show inline comments
 
@@ -320,13 +320,13 @@ static bool SwitchNewGRFBlitter()
 
void CheckBlitter()
 
{
 
	if (!SwitchNewGRFBlitter()) return;
 

	
 
	ClearFontCache();
 
	GfxClearSpriteCache();
 
	ReInitAllWindows();
 
	ReInitAllWindows(false);
 
}
 

	
 
/** Initialise and load all the sprites. */
 
void GfxLoadSprites()
 
{
 
	DEBUG(sprite, 2, "Loading sprite set %d", _settings_game.game_creation.landscape);
src/network/network_gui.cpp
Show inline comments
 
@@ -95,13 +95,15 @@ public:
 
		this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_CLIENTS, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION, STR_NETWORK_SERVER_LIST_CLIENTS_CAPTION_TOOLTIP));
 
		this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_MAPSIZE, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION, STR_NETWORK_SERVER_LIST_MAP_SIZE_CAPTION_TOOLTIP));
 
		this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_DATE, STR_NETWORK_SERVER_LIST_DATE_CAPTION, STR_NETWORK_SERVER_LIST_DATE_CAPTION_TOOLTIP));
 
		this->Add(new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_YEARS, STR_NETWORK_SERVER_LIST_YEARS_CAPTION, STR_NETWORK_SERVER_LIST_YEARS_CAPTION_TOOLTIP));
 

	
 
		leaf = new NWidgetLeaf(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_INFO, STR_EMPTY, STR_NETWORK_SERVER_LIST_INFO_ICONS_TOOLTIP);
 
		leaf->SetMinimalSize(14 + GetSpriteSize(SPR_LOCK).width + GetSpriteSize(SPR_BLOT).width + GetSpriteSize(SPR_FLAGS_BASE).width, 12);
 
		leaf->SetMinimalSize(14 + GetSpriteSize(SPR_LOCK, nullptr, ZOOM_LVL_OUT_4X).width
 
		                        + GetSpriteSize(SPR_BLOT, nullptr, ZOOM_LVL_OUT_4X).width
 
		                        + GetSpriteSize(SPR_FLAGS_BASE, nullptr, ZOOM_LVL_OUT_4X).width, 12);
 
		leaf->SetFill(0, 1);
 
		this->Add(leaf);
 

	
 
		/* First and last are always visible, the rest is implicitly zeroed */
 
		this->visible[0] = true;
 
		*lastof(this->visible) = true;
src/newgrf_gui.cpp
Show inline comments
 
@@ -1969,13 +1969,13 @@ static void NewGRFConfirmationCallback(W
 
		nw->active_sel = c;
 
		nw->avails.ForceRebuild();
 
		nw->modified = false;
 

	
 
		w->InvalidateData();
 

	
 
		ReInitAllWindows();
 
		ReInitAllWindows(false);
 
		DeleteWindowByClass(WC_BUILD_OBJECT);
 
	}
 
}
 

	
 

	
 

	
src/osk_gui.cpp
Show inline comments
 
@@ -234,13 +234,13 @@ static void AddKey(NWidgetHorizontal *ho
 
	} else {
 
		if (!hor->IsEmpty()) {
 
			NWidgetSpacer *spc = new NWidgetSpacer(ScaleGUITrad(INTER_KEY_SPACE), height);
 
			hor->Add(spc);
 
		}
 
		NWidgetLeaf *leaf = new NWidgetLeaf(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
 
		leaf->SetMinimalSize(ScaleGUITrad(key_width), height);
 
		leaf->SetMinimalSizeAbsolute(ScaleGUITrad(key_width), height);
 
		hor->Add(leaf);
 
	}
 

	
 
	*biggest_index = std::max(*biggest_index, widnum);
 
}
 

	
src/settings.cpp
Show inline comments
 
@@ -1169,13 +1169,13 @@ static bool SpriteZoomMinChanged(int32 p
 
 * @return Always true.
 
 */
 
static bool InvalidateNewGRFChangeWindows(int32 p1)
 
{
 
	InvalidateWindowClassesData(WC_SAVELOAD);
 
	DeleteWindowByClass(WC_GAME_OPTIONS);
 
	ReInitAllWindows();
 
	ReInitAllWindows(_gui_zoom_cfg);
 
	return true;
 
}
 

	
 
static bool InvalidateCompanyLiveryWindow(int32 p1)
 
{
 
	InvalidateWindowClassesData(WC_COMPANY_COLOUR, -1);
src/settings_gui.cpp
Show inline comments
 
@@ -527,13 +527,13 @@ struct GameOptionsWindow : Window {
 
	void OnDropdownSelect(int widget, int index) override
 
	{
 
		switch (widget) {
 
			case WID_GO_CURRENCY_DROPDOWN: // Currency
 
				if (index == CURRENCY_CUSTOM) ShowCustCurrency();
 
				this->opt->locale.currency = index;
 
				ReInitAllWindows();
 
				ReInitAllWindows(false);
 
				break;
 

	
 
			case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
 
				_settings_client.gui.autosave = index;
 
				this->SetDirty();
 
				break;
 
@@ -542,13 +542,13 @@ struct GameOptionsWindow : Window {
 
				ReadLanguagePack(&_languages[index]);
 
				DeleteWindowByClass(WC_QUERY_STRING);
 
				CheckForMissingGlyphs();
 
				ClearAllCachedNames();
 
				UpdateAllVirtCoords();
 
				CheckBlitter();
 
				ReInitAllWindows();
 
				ReInitAllWindows(false);
 
				break;
 

	
 
			case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
 
				if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
 
					this->SetDirty();
 
				}
 
@@ -570,13 +570,13 @@ struct GameOptionsWindow : Window {
 
					GfxClearSpriteCache();
 
					_gui_zoom_cfg = new_zoom;
 
					UpdateGUIZoom();
 
					UpdateCursorSize();
 
					UpdateAllVirtCoords();
 
					FixTitleGameZoom();
 
					ReInitAllWindows();
 
					ReInitAllWindows(true);
 
				}
 
				break;
 
			}
 

	
 
			case WID_GO_FONT_ZOOM_DROPDOWN: {
 
				int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
 
@@ -584,12 +584,13 @@ struct GameOptionsWindow : Window {
 
					GfxClearSpriteCache();
 
					_font_zoom_cfg = new_zoom;
 
					UpdateGUIZoom();
 
					ClearFontCache();
 
					LoadStringWidthTable();
 
					UpdateAllVirtCoords();
 
					ReInitAllWindows(true);
 
				}
 
				break;
 
			}
 

	
 
			case WID_GO_BASE_GRF_DROPDOWN:
 
				this->SetMediaSet<BaseGraphics>(index);
src/video/video_driver.cpp
Show inline comments
 
@@ -112,13 +112,13 @@ void VideoDriver::RealChangeBlitter(cons
 
	}
 

	
 
	/* Clear caches that might have sprites for another blitter. */
 
	this->ClearSystemSprites();
 
	ClearFontCache();
 
	GfxClearSpriteCache();
 
	ReInitAllWindows();
 
	ReInitAllWindows(false);
 
}
 

	
 
void VideoDriver::Tick()
 
{
 
	if (!this->is_game_threaded && std::chrono::steady_clock::now() >= this->next_game_tick) {
 
		this->GameLoop();
src/widget.cpp
Show inline comments
 
@@ -819,44 +819,78 @@ void NWidgetBase::SetDirty(const Window 
 
 */
 
NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
 
{
 
	return (this->type == tp) ? this : nullptr;
 
}
 

	
 
void NWidgetBase::AdjustPaddingForZoom()
 
{
 
	this->padding_top    = ScaleGUITrad(this->uz_padding_top);
 
	this->padding_right  = ScaleGUITrad(this->uz_padding_right);
 
	this->padding_bottom = ScaleGUITrad(this->uz_padding_bottom);
 
	this->padding_left   = ScaleGUITrad(this->uz_padding_left);
 
}
 

	
 
/**
 
 * Constructor for resizable nested widgets.
 
 * @param tp     Nested widget type.
 
 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
 
 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
 
 */
 
NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
 
{
 
	this->fill_x = fill_x;
 
	this->fill_y = fill_y;
 
}
 

	
 
void NWidgetResizeBase::AdjustPaddingForZoom()
 
{
 
	if (!this->absolute) {
 
		this->min_x = ScaleGUITrad(this->uz_min_x);
 
		this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
 
	}
 
	NWidgetBase::AdjustPaddingForZoom();
 
}
 

	
 
/**
 
 * Set minimal size of the widget.
 
 * @param min_x Horizontal minimal size of the widget.
 
 * @param min_y Vertical minimal size of the widget.
 
 */
 
void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
 
{
 
	this->uz_min_x = std::max(this->uz_min_x, min_x);
 
	this->uz_min_y = std::max(this->uz_min_y, min_y);
 
	this->min_x = ScaleGUITrad(this->uz_min_x);
 
	this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
 
}
 

	
 
/**
 
 * Set absolute (post-scaling) minimal size of the widget.
 
 * @param min_x Horizontal minimal size of the widget.
 
 * @param min_y Vertical minimal size of the widget.
 
 */
 
void NWidgetResizeBase::SetMinimalSizeAbsolute(uint min_x, uint min_y)
 
{
 
	this->absolute = true;
 
	this->min_x = std::max(this->min_x, min_x);
 
	this->min_y = std::max(this->min_y, min_y);
 
}
 

	
 
/**
 
 * Set minimal text lines for the widget.
 
 * @param min_lines Number of text lines of the widget.
 
 * @param spacing   Extra spacing (eg WD_FRAMERECT_TOP + _BOTTOM) of the widget.
 
 * @param size      Font size of text.
 
 */
 
void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
 
{
 
	this->min_y = min_lines * GetCharacterHeight(size) + spacing;
 
	this->uz_text_lines = min_lines;
 
	this->uz_text_spacing = spacing;
 
	this->uz_text_size = size;
 
	this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
 
}
 

	
 
/**
 
 * Set the filling of the widget from initial size.
 
 * @param fill_x Horizontal fill step size, \c 0 means no filling is allowed.
 
 * @param fill_y Vertical fill step size, \c 0 means no filling is allowed.
 
@@ -988,12 +1022,20 @@ NWidgetBase *NWidgetContainer::GetWidget
 
		NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
 
		if (nwid != nullptr) return nwid;
 
	}
 
	return nullptr;
 
}
 

	
 
void NWidgetContainer::AdjustPaddingForZoom()
 
{
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->AdjustPaddingForZoom();
 
	}
 
	NWidgetBase::AdjustPaddingForZoom();
 
}
 

	
 
/**
 
 * Append widget \a wid to container.
 
 * @param wid Widget to append.
 
 */
 
void NWidgetContainer::Add(NWidgetBase *wid)
 
{
 
@@ -1029,12 +1071,20 @@ NWidgetStacked::NWidgetStacked() : NWidg
 

	
 
void NWidgetStacked::SetIndex(int index)
 
{
 
	this->index = index;
 
}
 

	
 
void NWidgetStacked::AdjustPaddingForZoom()
 
{
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->AdjustPaddingForZoom();
 
	}
 
	NWidgetContainer::AdjustPaddingForZoom();
 
}
 

	
 
void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
 
{
 
	if (this->index >= 0 && init_array) { // Fill w->nested_array[]
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 
@@ -1142,26 +1192,38 @@ void NWidgetStacked::SetDisplayedPlane(i
 

	
 
NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
 
{
 
	this->flags = flags;
 
}
 

	
 
void NWidgetPIPContainer::AdjustPaddingForZoom()
 
{
 
	this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
 
	this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
 
	this->pip_post = ScaleGUITrad(this->uz_pip_post);
 
	NWidgetContainer::AdjustPaddingForZoom();
 
}
 

	
 
/**
 
 * Set additional pre/inter/post space for the container.
 
 *
 
 * @param pip_pre   Additional space in front of the first child widget (above
 
 *                  for the vertical container, at the left for the horizontal container).
 
 * @param pip_inter Additional space between two child widgets.
 
 * @param pip_post  Additional space after the last child widget (below for the
 
 *                  vertical container, at the right for the horizontal container).
 
 */
 
void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
 
{
 
	this->pip_pre = pip_pre;
 
	this->pip_inter = pip_inter;
 
	this->pip_post = pip_post;
 
	this->uz_pip_pre = pip_pre;
 
	this->uz_pip_inter = pip_inter;
 
	this->uz_pip_post = pip_post;
 

	
 
	this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
 
	this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
 
	this->pip_post = ScaleGUITrad(this->uz_pip_post);
 
}
 

	
 
void NWidgetPIPContainer::Draw(const Window *w)
 
{
 
	for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
 
		child_wid->Draw(w);
 
@@ -1810,12 +1872,18 @@ void NWidgetBackground::SetPIP(uint8 pip
 
	if (this->child == nullptr) {
 
		this->child = new NWidgetVertical();
 
	}
 
	this->child->SetPIP(pip_pre, pip_inter, pip_post);
 
}
 

	
 
void NWidgetBackground::AdjustPaddingForZoom()
 
{
 
	if (child != nullptr) child->AdjustPaddingForZoom();
 
	NWidgetCore::AdjustPaddingForZoom();
 
}
 

	
 
void NWidgetBackground::SetupSmallestSize(Window *w, bool init_array)
 
{
 
	if (init_array && this->index >= 0) {
 
		assert(w->nested_array_size > (uint)this->index);
 
		w->nested_array[this->index] = this;
 
	}
 
@@ -2134,17 +2202,17 @@ void NWidgetScrollbar::SetupSmallestSize
 
	}
 
	this->min_x = 0;
 
	this->min_y = 0;
 

	
 
	switch (this->type) {
 
		case NWID_HSCROLLBAR:
 
			this->SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
 
			this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
 
			break;
 

	
 
		case NWID_VSCROLLBAR:
 
			this->SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
 
			this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 

	
 
	this->smallest_x = this->min_x;
 
@@ -2765,13 +2833,13 @@ static int MakeNWidget(const NWidgetPart
 
			}
 

	
 
			case WPT_MINSIZE: {
 
				NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
 
				if (nwrb != nullptr) {
 
					assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
 
					nwrb->SetMinimalSize(ScaleGUITrad(parts->u.xy.x), ScaleGUITrad(parts->u.xy.y));
 
					nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y);
 
				}
 
				break;
 
			}
 

	
 
			case WPT_MINTEXTLINES: {
 
				NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
 
@@ -2811,21 +2879,21 @@ static int MakeNWidget(const NWidgetPart
 
					nwc->tool_tip = parts->u.data_tip.tooltip;
 
				}
 
				break;
 
			}
 

	
 
			case WPT_PADDING:
 
				if (*dest != nullptr) (*dest)->SetPadding(ScaleGUITrad(parts->u.padding.top), ScaleGUITrad(parts->u.padding.right), ScaleGUITrad(parts->u.padding.bottom), ScaleGUITrad(parts->u.padding.left));
 
				if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left);
 
				break;
 

	
 
			case WPT_PIPSPACE: {
 
				NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
 
				if (nwc != nullptr) nwc->SetPIP(ScaleGUITrad(parts->u.pip.pre), ScaleGUITrad(parts->u.pip.inter), ScaleGUITrad(parts->u.pip.post));
 
				if (nwc != nullptr) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
 

	
 
				NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
 
				if (nwb != nullptr) nwb->SetPIP(ScaleGUITrad(parts->u.pip.pre), ScaleGUITrad(parts->u.pip.inter), ScaleGUITrad(parts->u.pip.post));
 
				if (nwb != nullptr) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
 
				break;
 
			}
 

	
 
			case WPT_SCROLLBAR: {
 
				NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
 
				if (nwc != nullptr) {
 
@@ -3016,13 +3084,13 @@ NWidgetBase *MakeCompanyButtonRows(int *
 
{
 
	assert(max_length >= 1);
 
	NWidgetVertical *vert = nullptr; // Storage for all rows.
 
	NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
 
	int hor_length = 0;
 

	
 
	Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
 
	Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
 
	sprite_size.width  += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
 
	sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
 

	
 
	for (int widnum = widget_first; widnum <= widget_last; widnum++) {
 
		/* Ensure there is room in 'hor' for another button. */
 
		if (hor_length == max_length) {
src/widget_type.h
Show inline comments
 
@@ -124,12 +124,13 @@ class Scrollbar;
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetBase : public ZeroedMemoryAllocator {
 
public:
 
	NWidgetBase(WidgetType tp);
 

	
 
	virtual void AdjustPaddingForZoom();
 
	virtual void SetupSmallestSize(Window *w, bool init_array) = 0;
 
	virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) = 0;
 

	
 
	virtual void FillNestedArray(NWidgetBase **array, uint length) = 0;
 

	
 
	virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
 
@@ -145,16 +146,17 @@ public:
 
	 * @param right  Amount of additional space right of the widget.
 
	 * @param bottom Amount of additional space below the widget.
 
	 * @param left   Amount of additional space left of the widget.
 
	 */
 
	inline void SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
 
	{
 
		this->padding_top = top;
 
		this->padding_right = right;
 
		this->padding_bottom = bottom;
 
		this->padding_left = left;
 
		this->uz_padding_top = top;
 
		this->uz_padding_right = right;
 
		this->uz_padding_bottom = bottom;
 
		this->uz_padding_left = left;
 
		this->AdjustPaddingForZoom();
 
	}
 

	
 
	inline uint GetHorizontalStepSize(SizingType sizing) const;
 
	inline uint GetVerticalStepSize(SizingType sizing) const;
 

	
 
	virtual void Draw(const Window *w) = 0;
 
@@ -192,12 +194,17 @@ public:
 

	
 
	uint8 padding_top;    ///< Paddings added to the top of the widget. Managed by parent container widget.
 
	uint8 padding_right;  ///< Paddings added to the right of the widget. Managed by parent container widget. (parent container may swap this with padding_left for RTL)
 
	uint8 padding_bottom; ///< Paddings added to the bottom of the widget. Managed by parent container widget.
 
	uint8 padding_left;   ///< Paddings added to the left of the widget. Managed by parent container widget. (parent container may swap this with padding_right for RTL)
 

	
 
	uint8 uz_padding_top;    ///< Unscaled top padding, for resize calculation.
 
	uint8 uz_padding_right;  ///< Unscaled right padding, for resize calculation.
 
	uint8 uz_padding_bottom; ///< Unscaled bottom padding, for resize calculation.
 
	uint8 uz_padding_left;   ///< Unscaled left padding, for resize calculation.
 

	
 
protected:
 
	inline void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height);
 
};
 

	
 
/**
 
 * Get the horizontal sizing step.
 
@@ -243,21 +250,31 @@ inline void NWidgetBase::StoreSizePositi
 
 * @ingroup NestedWidgets
 
 */
 
class NWidgetResizeBase : public NWidgetBase {
 
public:
 
	NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetMinimalSize(uint min_x, uint min_y);
 
	void SetMinimalSizeAbsolute(uint min_x, uint min_y);
 
	void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size);
 
	void SetFill(uint fill_x, uint fill_y);
 
	void SetResize(uint resize_x, uint resize_y);
 

	
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 

	
 
	uint min_x; ///< Minimal horizontal size of only this widget.
 
	uint min_y; ///< Minimal vertical size of only this widget.
 

	
 
	bool absolute; ///< Set if minimum size is fixed and should not be resized.
 
	uint uz_min_x; ///< Unscaled Minimal horizontal size of only this widget.
 
	uint uz_min_y; ///< Unscaled Minimal vertical size of only this widget.
 

	
 
	uint8 uz_text_lines;   ///< 'Unscaled' text lines, stored for resize calculation.
 
	uint8 uz_text_spacing; ///< 'Unscaled' text padding, stored for resize calculation.
 
	FontSize uz_text_size; ///< 'Unscaled' font size, stored for resize calculation.
 
};
 

	
 
/** Nested widget flags that affect display and interaction with 'real' widgets. */
 
enum NWidgetDisplay {
 
	/* Generic. */
 
	NDB_LOWERED         = 0, ///< Widget is lowered (pressed down) bit.
 
@@ -382,12 +399,13 @@ inline bool NWidgetCore::IsDisabled() co
 
 */
 
class NWidgetContainer : public NWidgetBase {
 
public:
 
	NWidgetContainer(WidgetType tp);
 
	~NWidgetContainer();
 

	
 
	void AdjustPaddingForZoom() override;
 
	void Add(NWidgetBase *wid);
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	/** Return whether the container is empty. */
 
	inline bool IsEmpty() { return head == nullptr; }
 

	
 
@@ -420,12 +438,13 @@ enum StackedZeroSizePlanes {
 
class NWidgetStacked : public NWidgetContainer {
 
public:
 
	NWidgetStacked();
 

	
 
	void SetIndex(int index);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 
@@ -447,22 +466,27 @@ DECLARE_ENUM_AS_BIT_SET(NWidContainerFla
 

	
 
/** Container with pre/inter/post child space. */
 
class NWidgetPIPContainer : public NWidgetContainer {
 
public:
 
	NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags = NC_NONE);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
 

	
 
	void Draw(const Window *w) override;
 
	NWidgetCore *GetWidgetFromPos(int x, int y) override;
 

	
 
protected:
 
	NWidContainerFlags flags; ///< Flags of the container.
 
	uint8 pip_pre;            ///< Amount of space before first widget.
 
	uint8 pip_inter;          ///< Amount of space between widgets.
 
	uint8 pip_post;           ///< Amount of space after last widget.
 

	
 
	uint8 uz_pip_pre;         ///< Unscaled space before first widget.
 
	uint8 uz_pip_inter;       ///< Unscaled space between widgets.
 
	uint8 uz_pip_post;        ///< Unscaled space after last widget.
 
};
 

	
 
/**
 
 * Horizontal container.
 
 * @ingroup NestedWidgets
 
 */
 
@@ -562,12 +586,13 @@ public:
 
	NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child = nullptr);
 
	~NWidgetBackground();
 

	
 
	void Add(NWidgetBase *nwid);
 
	void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post);
 

	
 
	void AdjustPaddingForZoom() override;
 
	void SetupSmallestSize(Window *w, bool init_array) override;
 
	void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override;
 

	
 
	void FillNestedArray(NWidgetBase **array, uint length) override;
 

	
 
	void Draw(const Window *w) override;
src/widgets/dropdown.cpp
Show inline comments
 
@@ -150,13 +150,13 @@ struct DropdownWindow : Window {
 
		this->CreateNestedTree();
 

	
 
		this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
 

	
 
		uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
 
		nwi->SetMinimalSize(items_width, size.height + 4);
 
		nwi->SetMinimalSizeAbsolute(items_width, size.height + 4);
 
		nwi->colour = wi_colour;
 

	
 
		nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
 
		nwi->colour = wi_colour;
 

	
 
		this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
src/window.cpp
Show inline comments
 
@@ -3409,21 +3409,22 @@ void HideVitalWindows()
 
{
 
	DeleteWindowById(WC_MAIN_TOOLBAR, 0);
 
	DeleteWindowById(WC_STATUS_BAR, 0);
 
}
 

	
 
/** Re-initialize all windows. */
 
void ReInitAllWindows()
 
void ReInitAllWindows(bool zoom_changed)
 
{
 
	NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
 
	NWidgetScrollbar::InvalidateDimensionCache();
 

	
 
	extern void InitDepotWindowBlockSizes();
 
	InitDepotWindowBlockSizes();
 

	
 
	for (Window *w : Window::IterateFromBack()) {
 
		if (zoom_changed) w->nested_root->AdjustPaddingForZoom();
 
		w->ReInit();
 
	}
 

	
 
	void NetworkReInitChatBoxSize();
 
	NetworkReInitChatBoxSize();
 

	
src/window_func.h
Show inline comments
 
@@ -40,13 +40,17 @@ void DeleteNonVitalWindows();
 
void DeleteAllNonVitalWindows();
 
void DeleteAllMessages();
 
void DeleteConstructionWindows();
 
void HideVitalWindows();
 
void ShowVitalWindows();
 

	
 
void ReInitAllWindows();
 
/**
 
 * Re-initialize all windows.
 
 * @param zoom_changed Set if windows are being re-initialized due to a zoom level changed.
 
 */
 
void ReInitAllWindows(bool zoom_changed);
 

	
 
void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, byte widget_index);
 
void SetWindowDirty(WindowClass cls, WindowNumber number);
 
void SetWindowClassesDirty(WindowClass cls);
 

	
 
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force = true);
0 comments (0 inline, 0 general)