(svn r20807) -Codechange: don't clamp the width of the main toolbar to 640 pixels

This commit is contained in:
yexo 2010-09-15 21:10:14 +00:00
parent 7bb0cf9af6
commit 532003504e
3 changed files with 14 additions and 3 deletions

View File

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

View File

@ -14,4 +14,6 @@
void AllocateToolbar();
extern int16 *_preferred_toolbar_size;
#endif /* TOOLBAR_GUI_H */

View File

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