MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawEngineList

Function DrawEngineList

src/build_vehicle_gui.cpp:966–1090  ·  view source on GitHub ↗

* Engine drawing loop * @param type Type of vehicle (VEH_*) * @param r The Rect of the list * @param eng_list What engines to draw * @param sb Scrollbar of list. * @param selected_id what engine to highlight as selected, if any * @param show_count Whether to show the amount of engines or not * @param selected_group the group to list the engines of */

Source from the content-addressed store, hash-verified

964 * @param selected_group the group to list the engines of
965 */
966void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group, const GUIBadgeClasses &badge_classes)
967{
968 static const std::array<int8_t, VehicleType::VEH_COMPANY_END> sprite_y_offsets = { 0, 0, -1, -1 };
969
970 auto [first, last] = sb.GetVisibleRangeIterators(eng_list);
971
972 bool rtl = _current_text_dir == TD_RTL;
973 int step_size = GetEngineListHeight(type);
974 int sprite_left = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_left;
975 int sprite_right = GetVehicleImageCellSize(type, EIT_PURCHASE).extend_right;
976 int sprite_width = sprite_left + sprite_right;
977 int circle_width = std::max(GetScaledSpriteSize(SPR_CIRCLE_FOLDED).width, GetScaledSpriteSize(SPR_CIRCLE_UNFOLDED).width);
978 PixelColour linecolour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
979
980 auto badge_column_widths = badge_classes.GetColumnWidths();
981
982 Rect ir = r.WithHeight(step_size).Shrink(WidgetDimensions::scaled.matrix, RectPadding::zero);
983 int sprite_y_offset = ScaleSpriteTrad(sprite_y_offsets[type]) + ir.Height() / 2;
984
985 Dimension replace_icon = {0, 0};
986 int count_width = 0;
987 if (show_count) {
988 replace_icon = GetSpriteSize(SPR_GROUP_REPLACE_ACTIVE);
989
990 uint biggest_num_engines = 0;
991 for (auto it = first; it != last; ++it) {
992 const uint num_engines = GetGroupNumEngines(_local_company, selected_group, it->engine_id);
993 biggest_num_engines = std::max(biggest_num_engines, num_engines);
994 }
995
996 count_width = GetStringBoundingBox(GetString(STR_JUST_COMMA, biggest_num_engines), FS_SMALL).width;
997 }
998
999 const int text_row_height = ir.Shrink(WidgetDimensions::scaled.matrix).Height();
1000 const int normal_text_y_offset = (text_row_height - GetCharacterHeight(FS_NORMAL)) / 2;
1001 const int small_text_y_offset = text_row_height - GetCharacterHeight(FS_SMALL);
1002
1003 const int offset = (rtl ? -circle_width : circle_width) / 2;
1004 const int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
1005
1006 for (auto it = first; it != last; ++it) {
1007 const auto &item = *it;
1008 const Engine *e = Engine::Get(item.engine_id);
1009
1010 uint indent = item.indent * WidgetDimensions::scaled.hsep_indent;
1011 bool has_variants = item.flags.Test(EngineDisplayFlag::HasVariants);
1012 bool is_folded = item.flags.Test(EngineDisplayFlag::IsFolded);
1013 bool shaded = item.flags.Test(EngineDisplayFlag::Shaded);
1014
1015 Rect textr = ir.Shrink(WidgetDimensions::scaled.matrix);
1016 Rect tr = ir.Indent(indent, rtl);
1017
1018 if (item.indent > 0) {
1019 /* Draw tree continuation lines. */
1020 int tx = (rtl ? ir.right : ir.left) + offset;
1021 for (uint lvl = 1; lvl <= item.indent; ++lvl) {
1022 if (HasBit(item.level_mask, lvl)) GfxDrawLine(tx, ir.top, tx, ir.bottom, linecolour, WidgetDimensions::scaled.fullbevel.top);
1023 if (lvl < item.indent) tx += level_width;

Callers 2

DrawWidgetMethod · 0.85
DrawWidgetMethod · 0.85

Calls 15

GetEngineListHeightFunction · 0.85
GetVehicleImageCellSizeFunction · 0.85
GetScaledSpriteSizeFunction · 0.85
GetColourGradientFunction · 0.85
ScaleSpriteTradFunction · 0.85
GetSpriteSizeFunction · 0.85
GetGroupNumEnginesFunction · 0.85
GetStringBoundingBoxFunction · 0.85
GetCharacterHeightFunction · 0.85
HasBitFunction · 0.85
GfxDrawLineFunction · 0.85
CentreBoundsFunction · 0.85

Tested by

no test coverage detected