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

Method DrawInfo

src/industry_gui.cpp:878–989  ·  view source on GitHub ↗

* Draw the text in the #WID_IV_INFO panel. * @param r Rectangle of the panel. * @return Expected position of the bottom edge of the panel. */

Source from the content-addressed store, hash-verified

876 * @return Expected position of the bottom edge of the panel.
877 */
878 int DrawInfo(const Rect &r)
879 {
880 bool rtl = _current_text_dir == TD_RTL;
881 Industry *i = Industry::Get(this->window_number);
882 const IndustrySpec *ind = GetIndustrySpec(i->type);
883 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
884 bool first = true;
885 bool has_accept = false;
886
887 /* Use all the available space past the rect, so that we can enlarge the window if needed. */
888 ir.bottom = INT_MAX;
889
890 if (i->prod_level == PRODLEVEL_CLOSURE) {
891 DrawString(ir, STR_INDUSTRY_VIEW_INDUSTRY_ANNOUNCED_CLOSURE);
892 ir.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_wide;
893 }
894
895 const int label_indent = WidgetDimensions::scaled.hsep_normal + this->cargo_icon_size.width;
896 bool stockpiling = ind->callback_mask.Any({IndustryCallbackMask::ProductionCargoArrival, IndustryCallbackMask::Production256Ticks});
897
898 for (const auto &a : i->accepted) {
899 if (!IsValidCargoType(a.cargo)) continue;
900 has_accept = true;
901 if (first) {
902 DrawString(ir, STR_INDUSTRY_VIEW_REQUIRES);
903 ir.top += GetCharacterHeight(FS_NORMAL);
904 first = false;
905 }
906
907 DrawCargoIcon(ir, a.cargo);
908
909 CargoSuffix suffix;
910 GetCargoSuffix(CARGOSUFFIX_IN, CST_VIEW, i, i->type, ind, a.cargo, &a - i->accepted.data(), suffix);
911 /* if the industry is not stockpiling then don't show amount in the acceptance display. */
912 if (!stockpiling && suffix.display == CSD_CARGO_AMOUNT_TEXT) suffix.display = CSD_CARGO_TEXT;
913 if (!stockpiling && suffix.display == CSD_CARGO_AMOUNT) suffix.display = CSD_CARGO;
914
915 DrawString(ir.Indent(label_indent, rtl), this->GetAcceptedCargoString(a, suffix));
916 ir.top += GetCharacterHeight(FS_NORMAL);
917 }
918
919 int line_height = this->editable == EA_RATE ? this->cheat_line_height : GetCharacterHeight(FS_NORMAL);
920 int text_y_offset = (line_height - GetCharacterHeight(FS_NORMAL)) / 2;
921 int button_y_offset = (line_height - SETTING_BUTTON_HEIGHT) / 2;
922 first = true;
923 for (const auto &p : i->produced) {
924 if (!IsValidCargoType(p.cargo)) continue;
925 if (first) {
926 if (has_accept) ir.top += WidgetDimensions::scaled.vsep_wide;
927 DrawString(ir, TimerGameEconomy::UsingWallclockUnits() ? STR_INDUSTRY_VIEW_PRODUCTION_LAST_MINUTE_TITLE : STR_INDUSTRY_VIEW_PRODUCTION_LAST_MONTH_TITLE);
928 ir.top += GetCharacterHeight(FS_NORMAL);
929 if (this->editable == EA_RATE) this->production_offset_y = ir.top;
930 first = false;
931 }
932
933 DrawCargoIcon(ir, p.cargo);
934
935 CargoSuffix suffix;

Callers 1

OnPaintMethod · 0.95

Calls 15

GetIndustrySpecFunction · 0.85
GetCharacterHeightFunction · 0.85
IsValidCargoTypeFunction · 0.85
GetCargoSuffixFunction · 0.85
ToPercent8Function · 0.85
DrawArrowButtonsFunction · 0.85
RoundDivSUFunction · 0.85
GetIndustryCallbackFunction · 0.85
ShrinkMethod · 0.80

Tested by

no test coverage detected