| 146 | } |
| 147 | |
| 148 | void OverlayController::processMessage() |
| 149 | { |
| 150 | auto now = std::chrono::steady_clock::now(); |
| 151 | auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(now - *_messageStartTimepoint); |
| 152 | if (duration.count() > ShowDuration + FadeoutTextDuration) { |
| 153 | _messageStartTimepoint.reset(); |
| 154 | } |
| 155 | if (_counter == 2) { |
| 156 | _ticksLaterTimepoint = std::chrono::steady_clock::now(); |
| 157 | } |
| 158 | |
| 159 | float textAlpha = 1.0f; |
| 160 | if (duration.count() > ShowDuration) { |
| 161 | textAlpha = std::max(0.0f, 1.0f - static_cast<float>(duration.count() - ShowDuration) / FadeoutTextDuration); |
| 162 | } |
| 163 | ImDrawList* drawList = ImGui::GetForegroundDrawList(); |
| 164 | |
| 165 | auto& styleRep = StyleRepository::get(); |
| 166 | auto center = ImGui::GetMainViewport()->Size; |
| 167 | center.x /= 2; |
| 168 | auto textColorFront = ImColor::HSV(0.5f, 0.0f, 1.0f, textAlpha); |
| 169 | auto textColorBack = ImColor::HSV(0.5f, 0.0f, 0.0f, textAlpha); |
| 170 | |
| 171 | ImGui::PushFont(styleRep.getMonospaceLargeFont()); |
| 172 | auto fontScaling = MessageFontSize / styleRep.getMonospaceLargeFont()->FontSize; |
| 173 | auto fontSize = ImGui::CalcTextSize(_message.c_str()); |
| 174 | fontSize.x *= fontScaling; |
| 175 | fontSize.y *= fontScaling; |
| 176 | ImGui::PopFont(); |
| 177 | |
| 178 | if (_withLightning && ++_counter > 2) { |
| 179 | auto durationAfterSomeTicks = std::chrono::duration_cast<std::chrono::milliseconds>(now - *_ticksLaterTimepoint); |
| 180 | float lightningAlpha = std::max(0.0f, 0.7f - static_cast<float>(durationAfterSomeTicks.count()) / FadeoutLightningDuration); |
| 181 | auto viewSize = toRealVector2D(Viewport::get().getViewSize()); |
| 182 | drawList->AddRectFilled({0, 0}, {viewSize.x, viewSize.y}, ImColor::HSV(0.0f, 0.0f, 1.0f, lightningAlpha)); |
| 183 | } |
| 184 | drawList->AddText( |
| 185 | styleRep.getMonospaceLargeFont(), |
| 186 | styleRep.scale(MessageFontSize), |
| 187 | {center.x - fontSize.x / 2 - 2, center.y - styleRep.scale(100.0f) - fontSize.y - 2}, |
| 188 | textColorBack, |
| 189 | _message.c_str()); |
| 190 | |
| 191 | drawList->AddText( |
| 192 | styleRep.getMonospaceLargeFont(), |
| 193 | styleRep.scale(MessageFontSize), |
| 194 | {center.x - fontSize.x / 2, center.y - styleRep.scale(100.0f) - fontSize.y}, |
| 195 | textColorFront, |
| 196 | _message.c_str()); |
| 197 | } |
nothing calls this directly
no test coverage detected