summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/toolbar_gui.cpp12
-rw-r--r--src/toolbar_gui.h2
-rw-r--r--src/window.cpp3
3 files changed, 14 insertions, 3 deletions
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index be36cbbdb..98a27dcbf 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -929,6 +929,8 @@ static MenuClickedProc * const _menu_clicked_procs[] = {
MenuClickHelp, // 26
};
+int16 *_preferred_toolbar_size = NULL; ///< Pointer to the default size for the main toolbar.
+
/** Full blown container to make it behave exactly as we want :) */
class NWidgetToolbarContainer : public NWidgetContainer {
bool visible[TBN_END]; ///< The visible headers
@@ -960,11 +962,13 @@ public:
this->resize_y = 0; // We never resize in this direction
this->spacers = 0;
+ uint nbuttons = 0;
/* First initialise some variables... */
for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
child_wid->SetupSmallestSize(w, init_array);
this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
if (this->IsButton(child_wid->type)) {
+ nbuttons++;
this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
} else if (child_wid->type == NWID_SPACER) {
this->spacers++;
@@ -978,6 +982,7 @@ public:
child_wid->current_x = child_wid->smallest_x;
}
}
+ *_preferred_toolbar_size = nbuttons * this->smallest_x;
}
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
@@ -1149,6 +1154,7 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
assert(i < lengthof(this->panel_widths));
this->panel_widths[i++] = child_wid->current_x;
+ *_preferred_toolbar_size += child_wid->current_x;
}
}
@@ -1481,7 +1487,7 @@ static const NWidgetPart _nested_toolbar_normal_widgets[] = {
NWidgetFunction(MakeMainToolbar),
};
-static const WindowDesc _toolb_normal_desc(
+static WindowDesc _toolb_normal_desc(
WDP_MANUAL, 640, 22,
WC_MAIN_TOOLBAR, WC_NONE,
WDF_NO_FOCUS,
@@ -1764,7 +1770,7 @@ static const NWidgetPart _nested_toolb_scen_widgets[] = {
NWidgetFunction(MakeScenarioToolbar),
};
-static const WindowDesc _toolb_scen_desc(
+static WindowDesc _toolb_scen_desc(
WDP_MANUAL, 640, 22,
WC_MAIN_TOOLBAR, WC_NONE,
WDF_UNCLICK_BUTTONS | WDF_NO_FOCUS,
@@ -1779,8 +1785,10 @@ void AllocateToolbar()
_last_built_roadtype = ROADTYPE_ROAD;
if (_game_mode == GM_EDITOR) {
+ _preferred_toolbar_size = &_toolb_scen_desc.default_width;
new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
} else {
+ _preferred_toolbar_size = &_toolb_normal_desc.default_width;
new MainToolbarWindow(&_toolb_normal_desc);
}
}
diff --git a/src/toolbar_gui.h b/src/toolbar_gui.h
index 508ba75f8..a731f0123 100644
--- a/src/toolbar_gui.h
+++ b/src/toolbar_gui.h
@@ -14,4 +14,6 @@
void AllocateToolbar();
+extern int16 *_preferred_toolbar_size;
+
#endif /* TOOLBAR_GUI_H */
diff --git a/src/window.cpp b/src/window.cpp
index 49039ec15..57fc81f4c 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -32,6 +32,7 @@
#include "settings_type.h"
#include "newgrf_debug.h"
#include "hotkeys.h"
+#include "toolbar_gui.h"
#include "table/sprites.h"
@@ -2690,7 +2691,7 @@ void RelocateAllWindows(int neww, int newh)
* in a 'backup'-desc that the window should always be centered. */
switch (w->window_class) {
case WC_MAIN_TOOLBAR:
- if (neww - w->width != 0) ResizeWindow(w, min(neww, 640) - w->width, 0);
+ ResizeWindow(w, min(neww, *_preferred_toolbar_size) - w->width, 0);
top = w->top;
left = PositionMainToolbar(w); // changes toolbar orientation