Index: src/toolbar_gui.cpp =================================================================== --- src/toolbar_gui.cpp (revision 13015) +++ src/toolbar_gui.cpp (working copy) @@ -51,6 +51,14 @@ RailType _last_built_railtype; RoadType _last_built_roadtype; +enum ToolbarMode { + TB_NORMAL, + TB_UPPER, + TB_LOWER +}; + +static ToolbarMode _toolbar_mode; + static void SelectSignTool() { if (_cursor.sprite == SPR_CURSOR_SIGN) { @@ -281,7 +289,7 @@ static void ToolbarGraphsClick(Window *w) { - PopupMainToolbMenu(w, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6, 0); + PopupMainToolbMenu(w, 10, STR_0154_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8, 0); } static void MenuClickGraphs(int index) @@ -293,6 +301,9 @@ case 3: ShowPerformanceHistoryGraph(); break; case 4: ShowCompanyValueGraph(); break; case 5: ShowCargoPaymentRates(); break; + /* functions for combined graphs/league button */ + case 6: ShowCompanyLeagueTable(); break; + case 7: ShowPerformanceRatingDetail(); break; } } @@ -534,6 +545,22 @@ } } +/* --- Switch toolbar button --- */ + +static void ToolbarSwitchClick(Window *w) +{ + if (_toolbar_mode != TB_LOWER) { + _toolbar_mode = TB_LOWER; + } else { + _toolbar_mode = TB_UPPER; + } + + CallWindowEventNP(w, WE_RESIZE); + w->HandleButtonClick(27); + SetWindowDirty(w); + SndPlayFx(SND_15_BEEP); +} + /* --- Scenario editor specific handlers. */ static void ToolbarScenDateBackward(Window *w) @@ -632,7 +659,98 @@ { } +/* --- Resizing the toolbar */ +void ResizeToolbar(Window *w) +{ + /* There are 27 buttons plus some spacings if the space allows it */ + uint button_width; + uint spacing; + if (w->width >= 27 * 22) { + button_width = 22; + spacing = w->width - (27 * button_width); + } else { + button_width = w->width / 27; + spacing = 0; + } + uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; + + for (uint i = 0, x = 0, j = 0; i < 27; i++) { + if (extra_spacing_at[j] == i) { + j++; + uint add = spacing / (lengthof(extra_spacing_at) - j); + spacing -= add; + x += add; + } + + w->widget[i].type = WWT_IMGBTN; + w->widget[i].left = x; + x += (spacing != 0) ? button_width : (w->width - x) / (27 - i); + w->widget[i].right = x - 1; + } + + w->widget[27].type = WWT_EMPTY; + _toolbar_mode = TB_NORMAL; +} + +/* --- Split the toolbar */ + +// the button arrangements for each possible size, "upper" and "lower" toolbar +byte arrange14[] = + { 0, 1, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 27, + 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 24, 25, 26, 27, }; +byte arrange15[] = + { 0, 2, 4, 13, 14, 15, 16, 19, 20, 21, 22, 23, 17, 18, 27, + 0, 1, 4, 3, 5, 6, 7, 8, 9, 10, 12, 24, 25, 26, 27, }; +byte arrange16[] = + { 0, 1, 2, 4, 13, 14, 15, 16, 19, 20, 21, 22, 23, 17, 18, 27, + 0, 1, 3, 5, 6, 7, 8, 9, 10, 12, 24, 25, 26, 17, 18, 27, }; +byte arrange17[] = + { 0, 1, 2, 4, 6, 13, 14, 15, 16, 19, 20, 21, 22, 23, 17, 18, 27, + 0, 1, 3, 4, 6, 5, 7, 8, 9, 10, 12, 24, 25, 26, 17, 18, 27, }; +byte arrange18[] = + { 0, 1, 2, 4, 5, 6, 7, 8, 9, 12, 19, 20, 21, 22, 23, 17, 18, 27, + 0, 1, 3, 4, 5, 6, 7, 10, 13, 14, 15, 16, 24, 25, 26, 17, 18, 27, }; +byte arrange19[] = + { 0, 1, 2, 4, 5, 6, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 27, + 0, 1, 3, 4, 7, 8, 9, 10, 12, 25, 19, 20, 21, 22, 23, 26, 17, 18, 27, }; + +byte *arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19 }; + +void SplitToolbar(Window *w) +{ + uint icon_size = 22; + uint button_width = icon_size; + uint max_icons = (w->width + icon_size/2) / icon_size; + + if (w->width / icon_size < 14) { + button_width = w->width / 14; + max_icons = 14; + } else { + w->width = (max_icons - 1) * button_width + icon_size; + } + + assert(max_icons >= 14 && max_icons <= 19); + + uint n = max_icons-14; + + // first hide all icons + for (uint i = 0; i <= 27; i++) { + w->widget[i].type = WWT_EMPTY; + } + + // now activate them all on their proper positions + for (uint i = 0, x = 0; i < max_icons; i++) { + uint icon = arrangements[n][i + ((_toolbar_mode == TB_LOWER) ? max_icons : 0)]; + w->widget[icon].type = WWT_IMGBTN; + w->widget[icon].left = x; + x += (w->width - x) / (max_icons - i); + w->widget[icon].right = x - 1; + } + + w->widget[27].data = (_toolbar_mode == TB_LOWER) ? SPR_IMG_TERRAFORM_UP : SPR_IMG_TERRAFORM_DOWN; +} + /* --- Toolbar handling for the 'normal' case */ typedef void ToolbarButtonProc(Window *w); @@ -665,6 +783,7 @@ ToolbarMusicClick, ToolbarNewspaperClick, ToolbarHelpClick, + ToolbarSwitchClick, }; static void MainToolbarWndProc(Window *w, WindowEvent *e) @@ -758,30 +877,11 @@ break; case WE_RESIZE: { - /* There are 27 buttons plus some spacings if the space allows it */ - uint button_width; - uint spacing; - if (w->width >= 27 * 22) { - button_width = 22; - spacing = w->width - (27 * button_width); + if (w->width <= 19 * 22) { + SplitToolbar(w); } else { - button_width = w->width / 27; - spacing = 0; + ResizeToolbar(w); } - uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; - - for (uint i = 0, x = 0, j = 0; i < 27; i++) { - if (extra_spacing_at[j] == i) { - j++; - uint add = spacing / (lengthof(extra_spacing_at) - j); - spacing -= add; - x += add; - } - - w->widget[i].left = x; - x += (spacing != 0) ? button_width : (w->width - x) / (27 - i); - w->widget[i].right = x - 1; - } } break; case WE_TIMEOUT: @@ -833,6 +933,7 @@ { WWT_IMGBTN, RESIZE_NONE, 14, 0, 0, 0, 21, SPR_IMG_MUSIC, STR_01D4_SHOW_SOUND_MUSIC_WINDOW}, { WWT_IMGBTN, RESIZE_NONE, 14, 0, 0, 0, 21, SPR_IMG_MESSAGES, STR_0203_SHOW_LAST_MESSAGE_NEWS}, { WWT_IMGBTN, RESIZE_NONE, 14, 0, 0, 0, 21, SPR_IMG_QUERY, STR_0186_LAND_BLOCK_INFORMATION}, +{ WWT_IMGBTN, RESIZE_NONE, 15, 0, 0, 0, 21, SPR_IMG_TERRAFORM_UP, STR_EMPTY}, // switch toolbar button. only active when toolbar has been split { WIDGETS_END}, };