Index: src/station_gui.cpp =================================================================== --- src/station_gui.cpp (revision 27135) +++ src/station_gui.cpp (working copy) @@ -690,7 +690,7 @@ for (uint i = 0; i < _sorted_standard_cargo_specs_size; i++) { NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, WID_STL_CARGOSTART + i); - panel->SetMinimalSize(14, 11); + panel->SetMinimalSizeTrad(14, 11); panel->SetResize(0, 0); panel->SetFill(0, 1); panel->SetDataTip(0, STR_STATION_LIST_USE_CTRL_TO_SELECT_MORE); Index: src/widgets/dropdown.cpp =================================================================== --- src/widgets/dropdown.cpp (revision 27135) +++ src/widgets/dropdown.cpp (working copy) @@ -126,7 +126,7 @@ uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0); NWidgetCore *nwi = this->GetWidget(WID_DM_ITEMS); - nwi->SetMinimalSize(items_width, size.height + 4); + nwi->SetMinimalSizeBase(items_width, size.height + 4); // TODO nwi->colour = wi_colour; nwi = this->GetWidget(WID_DM_SCROLL); Index: src/linkgraph/linkgraph_gui.cpp =================================================================== --- src/linkgraph/linkgraph_gui.cpp (revision 27135) +++ src/linkgraph/linkgraph_gui.cpp (working copy) @@ -327,7 +327,8 @@ NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE); for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS); ++i) { NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST); - wid->SetMinimalSize(50, FONT_HEIGHT_SMALL); + wid->min_x.SetTrad(50); + wid->min_y.SetLines(1, 0, FS_SMALL); wid->SetFill(1, 1); wid->SetResize(0, 0); panel->Add(wid); @@ -347,7 +348,8 @@ row = new NWidgetHorizontal(NC_EQUALSIZE); } NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, i + WID_LGL_CARGO_FIRST); - wid->SetMinimalSize(25, FONT_HEIGHT_SMALL); + wid->min_x.SetTrad(25); + wid->min_y.SetLines(1, 0, FS_SMALL); wid->SetFill(1, 1); wid->SetResize(0, 0); row->Add(wid); Index: src/widget.cpp =================================================================== --- src/widget.cpp (revision 27135) +++ src/widget.cpp (working copy) @@ -26,6 +26,44 @@ #include "safeguards.h" + +NWidgetResizeBase::PixelSize::PixelSize() : + base(0), trad(0), lines(0), lines_spacing_trad(0), lines_size(FS_NORMAL) +{ +} + +void NWidgetResizeBase::PixelSize::Clear() +{ + this->base = this->trad = this->lines = this->lines_spacing_trad = 0; + this->lines_size = FS_NORMAL; +} + +void NWidgetResizeBase::PixelSize::SetBase(uint amount) +{ + this->base = max(this->base, amount); +} + +void NWidgetResizeBase::PixelSize::SetTrad(uint amount) +{ + this->trad = max(this->trad, amount); +} + +void NWidgetResizeBase::PixelSize::SetLines(uint amount, uint spacing_trad, FontSize size) +{ + this->lines = max(this->lines, amount); + this->lines_spacing_trad = max(this->lines_spacing_trad, spacing_trad); + this->lines_size = size; +} + +uint NWidgetResizeBase::PixelSize::Get() const +{ + uint result = max(this->base, ScaleGUITrad(this->trad)); + if (this->lines > 0 || this->lines_spacing_trad > 0) { + result = max(result, ScaleGUITrad(this->lines_spacing_trad) + this->lines * GetCharacterHeight(this->lines_size)); + } + return result; +} + /** * Compute the vertical position of the draggable part of scrollbar * @param sb Scrollbar list data @@ -809,28 +847,6 @@ } /** - * 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->min_x = max(this->min_x, min_x); - this->min_y = 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; -} - -/** * 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. @@ -1436,14 +1452,14 @@ */ NWidgetSpacer::NWidgetSpacer(int length, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0) { - this->SetMinimalSize(length, height); + this->SetMinimalSizeTrad(length, height); this->SetResize(0, 0); } void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array) { - this->smallest_x = this->min_x; - this->smallest_y = this->min_y; + this->smallest_x = this->min_x.Get(); + this->smallest_y = this->min_y.Get(); } void NWidgetSpacer::FillNestedArray(NWidgetBase **array, uint length) @@ -1783,7 +1799,7 @@ this->smallest_x = max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT); } } else { - Dimension d = {this->min_x, this->min_y}; + Dimension d = {this->min_x.Get(), this->min_y.Get()}; Dimension fill = {this->fill_x, this->fill_y}; Dimension resize = {this->resize_x, this->resize_y}; if (w != NULL) { // A non-NULL window pointer acts as switch to turn dynamic widget size on. @@ -1895,8 +1911,8 @@ assert(w->nested_array_size > (uint)this->index); w->nested_array[this->index] = this; } - this->smallest_x = this->min_x; - this->smallest_y = this->min_y; + this->smallest_x = this->min_x.Get(); + this->smallest_y = this->min_y.Get(); } void NWidgetViewport::Draw(const Window *w) @@ -1997,19 +2013,19 @@ assert(w->nested_array_size > (uint)this->index); w->nested_array[this->index] = this; } - this->min_x = 0; - this->min_y = 0; + this->min_x.Clear(); + this->min_y.Clear(); switch (this->type) { case NWID_HSCROLLBAR: - this->SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height); + this->SetMinimalSizeBase(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height); this->SetResize(1, 0); this->SetFill(1, 0); this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST); break; case NWID_VSCROLLBAR: - this->SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3); + this->SetMinimalSizeBase(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3); this->SetResize(0, 1); this->SetFill(0, 1); this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST); @@ -2018,8 +2034,8 @@ default: NOT_REACHED(); } - this->smallest_x = this->min_x; - this->smallest_y = this->min_y; + this->smallest_x = this->min_x.Get(); + this->smallest_y = this->min_y.Get(); } void NWidgetScrollbar::Draw(const Window *w) @@ -2113,8 +2129,6 @@ { assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX); if (index >= 0) this->SetIndex(index); - this->min_x = 0; - this->min_y = 0; this->SetResize(0, 0); switch (tp) { @@ -2145,49 +2159,49 @@ case WWT_CAPTION: this->SetFill(1, 0); this->SetResize(1, 0); - this->min_y = WD_CAPTION_HEIGHT; + this->min_y.SetTrad(WD_CAPTION_HEIGHT); this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS); break; case WWT_STICKYBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_STICKYBOX_WIDTH, WD_CAPTION_HEIGHT); + this->SetMinimalSizeTrad(WD_STICKYBOX_WIDTH, WD_CAPTION_HEIGHT); this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY); break; case WWT_SHADEBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_SHADEBOX_TOP, WD_CAPTION_HEIGHT); + this->SetMinimalSizeTrad(WD_SHADEBOX_TOP, WD_CAPTION_HEIGHT); this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE); break; case WWT_DEBUGBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_DEBUGBOX_TOP, WD_CAPTION_HEIGHT); + this->SetMinimalSizeTrad(WD_DEBUGBOX_TOP, WD_CAPTION_HEIGHT); this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG); break; case WWT_DEFSIZEBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_DEFSIZEBOX_TOP, WD_CAPTION_HEIGHT); + this->SetMinimalSizeTrad(WD_DEFSIZEBOX_TOP, WD_CAPTION_HEIGHT); this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE); break; case WWT_RESIZEBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12); + this->SetMinimalSizeTrad(WD_RESIZEBOX_WIDTH, 12); this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE); break; case WWT_CLOSEBOX: this->SetFill(0, 0); - this->SetMinimalSize(WD_CLOSEBOX_WIDTH, WD_CAPTION_HEIGHT); + this->SetMinimalSizeTrad(WD_CLOSEBOX_WIDTH, WD_CAPTION_HEIGHT); this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW); break; case WWT_DROPDOWN: this->SetFill(0, 0); - this->min_y = WD_DROPDOWN_HEIGHT; + this->min_y.SetTrad(WD_DROPDOWN_HEIGHT); break; default: @@ -2202,7 +2216,7 @@ w->nested_array[this->index] = this; } - Dimension size = {this->min_x, this->min_y}; + Dimension size = {this->min_x.Get(), this->min_y.Get()}; Dimension fill = {this->fill_x, this->fill_y}; Dimension resize = {this->resize_x, this->resize_y}; /* Get padding, and update size with the real content size if appropriate. */ @@ -2624,7 +2638,7 @@ NWidgetResizeBase *nwrb = dynamic_cast(*dest); if (nwrb != NULL) { assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0); - nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y); + nwrb->SetMinimalSizeTrad(parts->u.xy.x, parts->u.xy.y); } break; } @@ -2633,7 +2647,7 @@ NWidgetResizeBase *nwrb = dynamic_cast(*dest); if (nwrb != NULL) { assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END); - nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size); + nwrb->min_y.SetLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size); } break; } @@ -2876,7 +2890,7 @@ } NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum); - panel->SetMinimalSize(sprite_size.width, sprite_size.height); + panel->SetMinimalSizeBase(sprite_size.width, sprite_size.height); panel->SetFill(1, 1); panel->SetResize(1, 0); panel->SetDataTip(0x0, button_tooltip); Index: src/widget_type.h =================================================================== --- src/widget_type.h (revision 27135) +++ src/widget_type.h (working copy) @@ -234,17 +234,65 @@ */ class NWidgetResizeBase : public NWidgetBase { public: + /** + * Class to hold pixel dimensions of various units. + */ + class PixelSize { + public: + PixelSize(); + + /** + * Reset content to zero. + */ + void Clear(); + + /** + * Set amount of pixels at ZOOM_LVL_BEGIN. + * @param amount Amount of full zoom pixels. + */ + void SetBase(uint amount); + + /** + * Set amount of pixels at ZOOM_LVL_GUI. + * @param amount Amount of traditional 1x pixels. + */ + void SetTrad(uint amount); + + /** + * Set amount of pixels in lines of text. + * @param amount Amount of lines. + * @param spacing_trad Additional spacing in traditional 1x pixels. + * @param size Font size. + */ + void SetLines(uint amount, uint spacing_trad, FontSize size = FS_NORMAL); + + /** + * Get amount of pixels at ZOOM_LVL_BEGIN. + * This is the maximum of all amounts ever passed to any of the SetXxx methods. + * @return Amount of real pixels. + */ + uint Get() const; + + private: + uint base; + uint trad; + uint lines; + uint lines_spacing_trad; + FontSize lines_size; + }; + NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y); - void SetMinimalSize(uint min_x, uint min_y); - void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size); + void SetMinimalSizeBase(uint x, uint y) { this->min_x.SetBase(x); this->min_y.SetBase(y); } + void SetMinimalSizeTrad(uint x, uint y) { this->min_x.SetTrad(x); this->min_y.SetTrad(y); } + 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); - uint min_x; ///< Minimal horizontal size of only this widget. - uint min_y; ///< Minimal vertical size of only this widget. + PixelSize min_x; ///< Minimal horizontal size of only this widget. + PixelSize min_y; ///< Minimal vertical size of only this widget. }; /** Nested widget flags that affect display and interaction withe 'real' widgets. */ @@ -940,17 +988,17 @@ /** * Widget part function for setting the minimal size. - * @param x Horizontal minimal size. - * @param y Vertical minimal size. + * @param x_trad Horizontal minimal size (pixels at 1x zoom). + * @param y_trad Vertical minimal size (pixels at 1x zoom). * @ingroup NestedWidgetParts */ -static inline NWidgetPart SetMinimalSize(int16 x, int16 y) +static inline NWidgetPart SetMinimalSize(int16 x_trad, int16 y_trad) { NWidgetPart part; part.type = WPT_MINSIZE; - part.u.xy.x = x; - part.u.xy.y = y; + part.u.xy.x = x_trad; + part.u.xy.y = y_trad; return part; } Index: src/osk_gui.cpp =================================================================== --- src/osk_gui.cpp (revision 27135) +++ src/osk_gui.cpp (working copy) @@ -241,7 +241,8 @@ hor->Add(spc); } NWidgetLeaf *leaf = new NWidgetLeaf(widtype, COLOUR_GREY, widnum, widdata, STR_NULL); - leaf->SetMinimalSize(key_width, height); + leaf->min_x.SetTrad(key_width); // TODO + leaf->min_y.SetBase(height); // TODO hor->Add(leaf); } Index: src/toolbar_gui.cpp =================================================================== --- src/toolbar_gui.cpp (revision 27135) +++ src/toolbar_gui.cpp (working copy) @@ -1350,7 +1350,7 @@ child_wid->current_x = child_wid->smallest_x; } } - w->window_desc->default_width = nbuttons * this->smallest_x; + w->window_desc->pref_width = nbuttons * this->smallest_x; } void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) @@ -1526,7 +1526,7 @@ assert(i < lengthof(this->panel_widths)); this->panel_widths[i++] = child_wid->current_x; - w->window_desc->default_width += child_wid->current_x; + w->window_desc->pref_width += child_wid->current_x; } } Index: src/window.cpp =================================================================== --- src/window.cpp (revision 27135) +++ src/window.cpp (working copy) @@ -87,12 +87,10 @@ char *_windows_file; /** Window description constructor. */ -WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width, int16 def_height, +WindowDesc::WindowDesc(WindowPosition def_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys) : default_pos(def_pos), - default_width(def_width), - default_height(def_height), cls(window_class), parent_cls(parent_class), ini_key(ini_key), @@ -102,7 +100,9 @@ hotkeys(hotkeys), pref_sticky(false), pref_width(0), - pref_height(0) + pref_height(0), + default_width_trad(def_width_trad), + default_height_trad(def_height_trad) { if (_window_descs == NULL) _window_descs = new SmallVector(); *_window_descs->Append() = this; @@ -113,6 +113,16 @@ _window_descs->Erase(_window_descs->Find(this)); } +int16 WindowDesc::GetDefaultWidth() const +{ + return this->pref_width != 0 ? this->pref_width : ScaleGUITrad(this->default_width_trad); +} + +int16 WindowDesc::GetDefaultHeight() const +{ + return this->pref_height != 0 ? this->pref_height : ScaleGUITrad(this->default_height_trad); +} + /** * Load all WindowDesc settings from _windows_file. */ @@ -3388,7 +3398,7 @@ continue; case WC_MAIN_TOOLBAR: - ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false); + ResizeWindow(w, min(neww, w->window_desc->GetDefaultWidth()) - w->width, 0, false); top = w->top; left = PositionMainToolbar(w); // changes toolbar orientation @@ -3400,7 +3410,7 @@ break; case WC_STATUS_BAR: - ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false); + ResizeWindow(w, min(neww, w->window_desc->GetDefaultWidth()) - w->width, 0, false); top = newh - w->height; left = PositionStatusbar(w); Index: src/network/network_chat_gui.cpp =================================================================== --- src/network/network_chat_gui.cpp (revision 27135) +++ src/network/network_chat_gui.cpp (working copy) @@ -17,6 +17,7 @@ #include "../strings_func.h" #include "../blitter/factory.hpp" #include "../console_func.h" +#include "../zoom_func.h" #include "../video/video_driver.hpp" #include "../querystring_gui.h" #include "../town.h" @@ -120,7 +121,7 @@ _chatmsg_list = ReallocT(_chatmsg_list, _settings_client.gui.network_chat_box_height); _chatmsg_box.x = 10; - _chatmsg_box.width = _settings_client.gui.network_chat_box_width; + _chatmsg_box.width = ScaleGUITrad(_settings_client.gui.network_chat_box_width); // TODO NetworkReInitChatBoxSize(); _chatmessage_visible = false; Index: src/network/network_gui.cpp =================================================================== --- src/network/network_gui.cpp (revision 27135) +++ src/network/network_gui.cpp (working copy) @@ -24,6 +24,7 @@ #include "network_udp.h" #include "../window_func.h" #include "../gfx_func.h" +#include "../zoom_func.h" #include "../widgets/dropdown_func.h" #include "../querystring_gui.h" #include "../sortlist_type.h" @@ -108,7 +109,8 @@ 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->min_x.SetBase(ScaleGUITrad(14) + GetSpriteSize(SPR_LOCK).width + GetSpriteSize(SPR_BLOT).width + GetSpriteSize(SPR_FLAGS_BASE).width); // TODO + leaf->min_y.SetTrad(12); leaf->SetFill(0, 1); this->Add(leaf); Index: src/window_gui.h =================================================================== --- src/window_gui.h (revision 27135) +++ src/window_gui.h (working copy) @@ -167,15 +167,13 @@ */ struct WindowDesc : ZeroedMemoryAllocator { - WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width, int16 def_height, + WindowDesc(WindowPosition default_pos, const char *ini_key, int16 def_width_trad, int16 def_height_trad, WindowClass window_class, WindowClass parent_class, uint32 flags, const NWidgetPart *nwid_parts, int16 nwid_length, HotkeyList *hotkeys = NULL); ~WindowDesc(); WindowPosition default_pos; ///< Preferred position of the window. @see WindowPosition() - int16 default_width; ///< Preferred initial width of the window. - int16 default_height; ///< Preferred initial height of the window. WindowClass cls; ///< Class of the window, @see WindowClass. WindowClass parent_cls; ///< Class of the parent window. @see WindowClass const char *ini_key; ///< Key to store window defaults in openttd.cfg. \c NULL if nothing shall be stored. @@ -188,13 +186,16 @@ int16 pref_width; ///< User-preferred width of the window. Zero if unset. int16 pref_height; ///< User-preferred height of the window. Zero if unset. - int16 GetDefaultWidth() const { return this->pref_width != 0 ? this->pref_width : this->default_width; } - int16 GetDefaultHeight() const { return this->pref_height != 0 ? this->pref_height : this->default_height; } + int16 GetDefaultWidth() const; + int16 GetDefaultHeight() const; static void LoadFromConfig(); static void SaveToConfig(); private: + int16 default_width_trad; ///< Preferred initial width of the window (pixels at 1x zoom). + int16 default_height_trad; ///< Preferred initial height of the window (pixels at 1x zoom). + /** * Dummy private copy constructor to prevent compilers from * copying the structure, which fails due to _window_descs. Index: src/graph_gui.cpp =================================================================== --- src/graph_gui.cpp (revision 27135) +++ src/graph_gui.cpp (working copy) @@ -116,7 +116,8 @@ for (int widnum = WID_GL_FIRST_COMPANY; widnum <= WID_GL_LAST_COMPANY; widnum++) { NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum); - panel->SetMinimalSize(246, line_height); + panel->min_x.SetTrad(246); + panel->min_y.SetBase(line_height); panel->SetFill(1, 0); panel->SetDataTip(0x0, STR_GRAPH_KEY_COMPANY_SELECTION_TOOLTIP); vert->Add(panel);