MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ComputeMaxDateWidth

Method ComputeMaxDateWidth

src/openrct2-ui/windows/LoadSave.cpp:306–339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304 }
305
306 void ComputeMaxDateWidth()
307 {
308 // Generate a time object for a relatively wide time: 2000-02-20 00:00:00
309 std::tm tm;
310 tm.tm_sec = 0;
311 tm.tm_min = 0;
312 tm.tm_hour = 0;
313 tm.tm_mday = 20;
314 tm.tm_mon = 2;
315 tm.tm_year = 100;
316 tm.tm_wday = 5;
317 tm.tm_yday = 51;
318 tm.tm_isdst = -1;
319
320 std::time_t long_time = mktime(&tm);
321
322 // Check how this date is represented (e.g. 2000-02-20, or 00/02/20)
323 std::string date = Platform::FormatShortDate(long_time);
324 maxDateWidth = getStringWidth(date.c_str(), FontStyle::medium) + kDateTimeGap;
325
326 // Some locales do not use leading zeros for months and days, so let's try October, too.
327 tm.tm_mon = 10;
328 tm.tm_yday = 294;
329 long_time = mktime(&tm);
330
331 // Again, check how this date is represented (e.g. 2000-10-20, or 00/10/20)
332 date = Platform::FormatShortDate(long_time);
333 maxDateWidth = std::max(maxDateWidth, getStringWidth(date.c_str(), FontStyle::medium) + kDateTimeGap);
334
335 // Time appears to be universally represented with two digits for minutes, so 12:00 or 00:00 should be
336 // representable.
337 std::string time = Platform::FormatTime(long_time);
338 maxTimeWidth = getStringWidth(time.c_str(), FontStyle::medium) + kDateTimeGap;
339 }
340
341 void LoadPreview()
342 {

Callers

nothing calls this directly

Calls 3

getStringWidthFunction · 0.85
FormatShortDateFunction · 0.50
FormatTimeFunction · 0.50

Tested by

no test coverage detected