1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 23:04:36 +01:00

Refactor uses of ShortenPath

This commit is contained in:
ζeh Matt
2023-08-10 14:39:47 +03:00
parent 39458a3df3
commit 3ff527fb78
3 changed files with 9 additions and 19 deletions

View File

@@ -106,7 +106,6 @@ static TrackDesign* _trackDesign;
static std::vector<LoadSaveListItem> _listItems;
static char _directory[MAX_PATH];
static char _shortenedDirectory[MAX_PATH];
static char _parentDirectory[MAX_PATH];
static u8string _extensionPattern;
static u8string _defaultPath;
@@ -527,7 +526,6 @@ public:
SafeStrCpy(_directory, absoluteDirectory.c_str(), std::size(_directory));
// Note: This compares the pointers, not values
_extensionPattern = extensionPattern;
_shortenedDirectory[0] = '\0';
_listItems.clear();
@@ -740,18 +738,15 @@ public:
{
DrawWidgets(dpi);
if (_shortenedDirectory[0] == '\0')
{
ShortenPath(_shortenedDirectory, sizeof(_shortenedDirectory), _directory, width - 8, FontStyle::Medium);
}
const auto shortPath = ShortenPath(_directory, width - 8, FontStyle::Medium);
// Format text
thread_local std::string _buffer;
_buffer.assign("{BLACK}");
_buffer += _shortenedDirectory;
std::string buffer;
buffer.assign("{BLACK}");
buffer += shortPath;
// Draw path text
const auto normalisedPath = Platform::StrDecompToPrecomp(_buffer.data());
const auto normalisedPath = Platform::StrDecompToPrecomp(buffer.data());
const auto* normalisedPathC = normalisedPath.c_str();
auto ft = Formatter();
ft.Add<const char*>(normalisedPathC);

View File

@@ -218,13 +218,10 @@ public:
// Scenario path
if (gConfigGeneral.DebuggingTools)
{
utf8 path[MAX_PATH];
const auto shortPath = ShortenPath(scenario->Path, width - 6 - TabWidth, FontStyle::Medium);
ShortenPath(path, sizeof(path), scenario->Path, width - 6 - TabWidth, FontStyle::Medium);
const utf8* pathPtr = path;
auto ft = Formatter();
ft.Add<const char*>(pathPtr);
ft.Add<utf8*>(shortPath.c_str());
DrawTextBasic(dpi, windowPos + ScreenCoordsXY{ TabWidth + 3, height - 3 - 11 }, STR_STRING, ft, { colours[1] });
}

View File

@@ -470,11 +470,9 @@ public:
// Show track file path (in debug mode)
if (gConfigGeneral.DebuggingTools)
{
utf8 pathBuffer[MAX_PATH];
const utf8* pathPtr = pathBuffer;
ShortenPath(pathBuffer, sizeof(pathBuffer), path.c_str(), width, FontStyle::Medium);
const auto shortPath = ShortenPath(path, width, FontStyle::Medium);
auto ft = Formatter();
ft.Add<utf8*>(pathPtr);
ft.Add<utf8*>(shortPath.c_str());
DrawTextBasic(
dpi, windowPos + ScreenCoordsXY{ 0, height - DEBUG_PATH_HEIGHT - 3 }, STR_STRING, ft,
{ colours[1] }); // TODO Check dpi