MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / updateLabel

Method updateLabel

src/OpenLoco/src/World/Station.cpp:952–993  ·  view source on GitHub ↗

0x0048DCA5

Source from the content-addressed store, hash-verified

950
951 // 0x0048DCA5
952 void Station::updateLabel()
953 {
954 // duplicate of drawStationName in Viewport.cpp
955 char buffer[256]{};
956 FormatArguments args{};
957 args.push(town);
958 auto* strEnd = StringManager::formatString(buffer, 256, name, args);
959
960 *strEnd++ = ' ';
961 *strEnd = '\0';
962
963 const auto remainingLength = strEnd - buffer;
964 StringManager::formatString(strEnd, remainingLength, getTransportIconsFromStationFlags(flags));
965
966 for (auto zoom = 0U; zoom < 4; ++zoom)
967 {
968 Ui::Viewport virtualVp{};
969 virtualVp.zoom = zoom;
970
971 const auto labelCenter = World::Pos3{ x, y, z };
972 const auto vpPos = World::gameToScreen(labelCenter, WindowManager::getCurrentRotation());
973
974 const auto font = kZoomToStationFonts[zoom];
975 const auto width = Gfx::TextRenderer::getStringWidth(font, buffer) + kZoomToStationBorder[zoom].width * 2;
976 const auto height = kZoomToStationBorder[zoom].height;
977
978 const auto [zoomWidth, zoomHeight] = ScreenToViewport::scaleTransform(Ui::Point(width, height), virtualVp);
979
980 const auto left = vpPos.x - zoomWidth / 2;
981 const auto right = left + zoomWidth;
982 const auto top = vpPos.y - zoomHeight / 2 - 32;
983 const auto bottom = top + zoomHeight;
984
985 const auto [uiLeft, uiTop] = ViewportToScreen::scaleTransform(Ui::Point(left, top), virtualVp);
986 const auto [uiRight, uiBottom] = ViewportToScreen::scaleTransform(Ui::Point(right, bottom), virtualVp);
987
988 labelFrame.left[zoom] = uiLeft;
989 labelFrame.right[zoom] = uiRight;
990 labelFrame.top[zoom] = uiTop;
991 labelFrame.bottom[zoom] = uiBottom;
992 }
993 }
994
995 // 0x004CBA2D
996 void Station::invalidate()

Callers 1

recalculateStationCenterFunction · 0.45

Calls 7

formatStringFunction · 0.85
gameToScreenFunction · 0.85
getCurrentRotationFunction · 0.85
getStringWidthFunction · 0.85
scaleTransformFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected