MCPcopy Create free account
hub / github.com/ThirteenAG/WidescreenFixesPack / ParseWidescreenHudOffset

Function ParseWidescreenHudOffset

includes/stdafx.cpp:89–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89std::optional<float> ParseWidescreenHudOffset(std::string_view input)
90{
91 if (input.empty())
92 return std::nullopt;
93
94 std::string str(input);
95
96 // Trim whitespace
97 str.erase(0, str.find_first_not_of(" \t\r\n"));
98 str.erase(str.find_last_not_of(" \t\r\n") + 1);
99
100 if (str.empty())
101 return std::nullopt;
102
103 // Case-insensitive "Auto" check
104 std::string lower = str;
105 std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
106 if (lower == "auto")
107 return std::nullopt;
108
109 // Try direct float conversion
110 {
111 char* end = nullptr;
112 float value = std::strtof(str.c_str(), &end);
113 if (end != str.c_str() && *end == '\0')
114 return value;
115 }
116
117 // Try "1280x720" format
118 {
119 int width = 0, height = 0;
120 if (sscanf_s(str.c_str(), "%dx%d", &width, &height) == 2 && width > 0)
121 return static_cast<float>(width);
122 }
123
124 // Try "16:9" format
125 {
126 float aspect1 = 0.0f, aspect2 = 0.0f;
127 if (sscanf_s(str.c_str(), "%f:%f", &aspect1, &aspect2) == 2 && aspect2 > 0.0f && aspect1 > 0.0f)
128 {
129 return aspect1 / aspect2;
130 }
131 }
132
133 // Try "21/9" format
134 {
135 float aspect1 = 0.0f, aspect2 = 0.0f;
136 if (sscanf_s(str.c_str(), "%f/%f", &aspect1, &aspect2) == 2 && aspect2 > 0.0f && aspect1 > 0.0f)
137 {
138 return aspect1 / aspect2;
139 }
140 }
141
142 return std::nullopt;
143}
144
145float ClampHudAspectRatio(float value, float screenAspect, float minAspect, float maxAspect)
146{

Callers

nothing calls this directly

Calls 2

c_strMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected