diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 2435a02b0f..788bc1ac7d 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -893,6 +893,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * int sprite_width = sprite_left + sprite_right; int sprite_x = rtl ? r - sprite_right - 1 : l + sprite_left + 1; + int sprite_y_offset = sprite_y_offsets[type] + step_size / 2; Dimension replace_icon = {0, 0}; int count_width = 0; @@ -908,6 +909,10 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * int count_left = l; int count_right = rtl ? text_left : r - WD_FRAMERECT_RIGHT - replace_icon.width - 8; + int normal_text_y_offset = (step_size - FONT_HEIGHT_NORMAL) / 2; + int small_text_y_offset = step_size - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1; + int replace_icon_y_offset = (step_size - replace_icon.height) / 2 - 1; + for (; min < max; min++, y += step_size) { const EngineID engine = (*eng_list)[min]; /* Note: num_engines is only used in the autoreplace GUI, so it is correct to use _local_company here. */ @@ -923,8 +928,8 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList * DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE); if (show_count) { SetDParam(0, num_engines); - DrawString(count_left, count_right, Center(y, step_size, FONT_HEIGHT_SMALL), STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE); - if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, Center(y, step_size, replace_icon.height)); + DrawString(count_left, count_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT | SA_FORCE); + if (EngineHasReplacementForCompany(Company::Get(_local_company), engine, selected_group)) DrawSprite(SPR_GROUP_REPLACE_ACTIVE, num_engines == 0 ? PALETTE_CRASH : PAL_NONE, replace_icon_left, y + replace_icon_y_offset); } } } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 1af2d14e41..ca7f98fb4d 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -641,7 +641,7 @@ public: case WID_SL_LOAD_NETWORK_BUTTON: { char savePath[PATH_MAX]; - FiosMakeSavegameName(savePath, NETWORK_SAVE_FILENAME, sizeof(savePath)); + FiosMakeSavegameName(savePath, NETWORK_SAVE_FILENAME, lastof(savePath)); #ifdef __ANDROID__ if (!SDL_ANDROID_CloudLoad(savePath, NULL, "OpenTTD")) { break; diff --git a/src/gfx.cpp b/src/gfx.cpp index 80964ed218..ec45926a71 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1206,7 +1206,7 @@ void ScreenSizeChanged() /* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ _cursor.visible = false; - NWidgetScrollbar::ResetAllWidgetMinSizes(); + ResetAllWidgetMinSizes(); } void UndrawMouseCursor() diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index abe07de276..3de8b986b9 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -607,8 +607,7 @@ public: case ContentInfo::DOES_NOT_EXIST: sprite = SPR_BLOT; pal = PALETTE_TO_RED; break; default: NOT_REACHED(); } - - DrawSprite(sprite, pal, Center(nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), nwi_checkbox->current_x, sprite_dim.width), Center(y, this->resize.step_height, sprite_dim.height + (pal == PAL_NONE ? 0 : -2))); + DrawSprite(sprite, pal, nwi_checkbox->pos_x + (pal == PAL_NONE ? 2 : 3), y + sprite_y_offset + (pal == PAL_NONE ? 1 : 0)); StringID str = STR_CONTENT_TYPE_BASE_GRAPHICS + ci->type - CONTENT_TYPE_BASE_GRAPHICS; DrawString(nwi_type->pos_x, nwi_type->pos_x + nwi_type->current_x - 1, y + text_y_offset, str, TC_BLACK, SA_HOR_CENTER); diff --git a/src/openttd.cpp b/src/openttd.cpp index 816488530d..55d3ade155 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1176,7 +1176,7 @@ void SwitchToMode(SwitchMode new_mode) lastPart++; } MakeScreenshot(SC_VIEWPORT, NETWORK_SAVE_SCREENSHOT_FILE); - FioFindFullPath(screenshotFile, sizeof(screenshotFile), SCREENSHOT_DIR, NETWORK_SAVE_SCREENSHOT_FILE_PNG); + FioFindFullPath(screenshotFile, lastof(screenshotFile), SCREENSHOT_DIR, NETWORK_SAVE_SCREENSHOT_FILE_PNG); uint64_t playedTime = abs(_date - DAYS_TILL(_settings_newgame.game_creation.starting_year)) * 1000; int ret = SDL_ANDROID_CloudSave(_file_to_saveload.name, lastPart, "OpenTTD", lastPart, screenshotFile, playedTime); if (_settings_client.gui.save_to_network == 2) { diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 7b9cbaee41..ddcdea2ccf 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -807,17 +807,13 @@ static const NWidgetPart _nested_station_view_widgets[] = { * @param y y coordinate * @param width the width of the view */ -static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int top, int bottom) +static void DrawCargoIcons(CargoID i, uint waiting, int left, int right, int top, int y) { int width = ScaleGUITrad(10); uint num = min((waiting + (width / 2)) / width, (right - left) / width); // maximum is width / 10 icons so it won't overflow if (num == 0) return; SpriteID sprite = CargoSpec::Get(i)->GetCargoIcon(); - Dimension d = GetSpriteSize(sprite); - - uint num = min((waiting + 5) / d.width, (right - left) / d.width); // maximum is width / 10 icons so it won't overflow - if (num == 0) return; int x = _current_text_dir == TD_RTL ? left : right - num * width; do { diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index d1f082873e..103d7163ac 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1418,9 +1418,11 @@ public: } _toolbar_width = nbuttons * this->smallest_x; if (type == NWID_HORIZONTAL) { - w->window_desc->default_width = nbuttons * this->smallest_x; + //w->window_desc->default_width_trad = nbuttons * this->smallest_x; + w->window_desc->pref_width = nbuttons * this->smallest_x; } else { - w->window_desc->default_height = nbuttons * this->smallest_y; + //w->window_desc->default_height_trad = nbuttons * this->smallest_y; + w->window_desc->pref_height = nbuttons * this->smallest_y; } } diff --git a/src/widget.cpp b/src/widget.cpp index 810476e104..980e639a4a 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2067,9 +2067,6 @@ void NWidgetScrollbar::Draw(const Window *w) horizontal_dimension.height = GetMinSizing(NWST_STEP, horizontal_dimension.height); } return horizontal_dimension; - SETTING_BUTTON_HEIGHT = max(GetMinSizing(NWST_STEP) - 10, 10); - SETTING_BUTTON_WIDTH = 2 * SETTING_BUTTON_HEIGHT; - } Dimension NWidgetScrollbar::vertical_dimension = {0, 0}; @@ -2135,7 +2132,6 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, case NWID_BUTTON_DROPDOWN: case WWT_DROPDOWN: case WWT_ARROWBTN: - case WWT_PUSHARROWBTN: this->sizing_type = NWST_STEP; break; default: diff --git a/src/widget_type.h b/src/widget_type.h index 49a75a955d..11799bf4f9 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -773,7 +773,7 @@ public: static void InvalidateDimensionCache(); static Dimension GetVerticalDimension(); static Dimension GetHorizontalDimension(); - static void ResetAllWidgetMinSizes(); ///< Called when screen size or font size or button size changes + friend void ResetAllWidgetMinSizes(); ///< Called when screen size or font size or button size changes private: static Dimension vertical_dimension; ///< Cached size of vertical scrollbar button. diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index a7c248d494..3b52653ce2 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -362,14 +362,6 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b /* Longest item in the list, if auto_width is enabled */ uint max_item_width = 0; - if (auto_width) { - /* Find the longest item in the list */ - for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) { - const DropDownListItem *item = *it; - max_item_width = max(max_item_width, item->Width() + 5); - } - } - /* Total length of list */ int height = 0; @@ -383,14 +375,11 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b int screen_bottom = GetMainViewBottom(); bool scroll = false; - enum { DISPLAY_BORDER = 20, TOP_BORDER = 4 }; - - /* Check if the dropdown will fully fit below the widget. */ - if (top + height + DISPLAY_BORDER >= screen_bottom) { - /* If not, check if it will fit above the widget. */ - int screen_top = GetMainViewTop(); - if (w->top + wi_rect.top - TOP_BORDER > screen_top + height) { - top = w->top + wi_rect.top - height - TOP_BORDER; + /* Check if the dropdown will fully fit below the widget */ + if (top + height + 4 >= screen_bottom) { + /* If not, check if it will fit above the widget */ + if (w->top + wi_rect.top - height > GetMainViewTop()) { + top = w->top + wi_rect.top - height - 4; } else { /* ... and lastly if it won't, enable the scroll bar and fit the * list in below the widget */ @@ -398,30 +387,9 @@ void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int b int rows = (screen_bottom - 4 - top) / avg_height; height = rows * avg_height; scroll = true; - - /* ... and choose whether to put the list above or below the widget. */ - bool put_above = false; - int available_height = screen_bottom - w->top - wi_rect.bottom; - if (w->top + wi_rect.top - screen_top > available_height) { - // Put it above. - available_height = w->top + wi_rect.top - screen_top - DISPLAY_BORDER - TOP_BORDER; - put_above = true; - } - - /* Check at least there is space for one item. */ - assert(available_height >= avg_height); - - /* And lastly, fit the list,... */ - int rows = available_height / avg_height; - height = rows * avg_height; - - /* ... add space for the scrollbar,... */ + /* Add space for the scroll bar if we automatically determined + * the width of the list. */ max_item_width += NWidgetScrollbar::GetVerticalDimension().width; - - /* ... and set the top position if needed. */ - if (put_above) { - top = w->top + wi_rect.top - height - TOP_BORDER; - } } } diff --git a/src/window.cpp b/src/window.cpp index 80cbae413d..30b0231432 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1874,7 +1874,7 @@ Window *FindWindowFromPt(int x, int y) * @todo Check if it can be moved to another file, so we do not need to include error, string and fontcache headers. * @todo Fix magic numbers 16/18/20/30/32 */ -void NWidgetScrollbar::ResetAllWidgetMinSizes() +void ResetAllWidgetMinSizes() { NWidgetScrollbar::vertical_dimension = {0, 0}; NWidgetScrollbar::horizontal_dimension = {0, 0}; @@ -3586,7 +3586,7 @@ void RelocateAllWindows(int neww, int newh) break; case WC_MAIN_TOOLBAR_RIGHT: - ResizeWindow(w, min(neww, w->window_desc->default_width) - w->width, 0, false); + ResizeWindow(w, min(neww, _toolbar_width) - w->width, 0, false); top = w->top; left = neww - w->width; diff --git a/src/window_func.h b/src/window_func.h index 8dff11baff..30e22847b5 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -29,6 +29,7 @@ int PositionNetworkChatWindow(Window *w); int GetMainViewTop(); int GetMainViewBottom(); +void ResetAllWidgetMinSizes(); void InitWindowSystem(); void UnInitWindowSystem(); void ResetWindowSystem();