| 90 | } |
| 91 | |
| 92 | void ChatDraw(RenderTarget& rt, ColourWithFlags chatBackgroundColor) |
| 93 | { |
| 94 | thread_local std::string lineBuffer; |
| 95 | |
| 96 | if (!ChatAvailable()) |
| 97 | { |
| 98 | gChatOpen = false; |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | _chatLeft = 10; |
| 103 | _chatRight = std::min<int16_t>((ContextGetWidth() - 10), kChatMaxWindowWidth); |
| 104 | _chatWidth = _chatRight - _chatLeft; |
| 105 | _chatBottom = ContextGetHeight() - 45; |
| 106 | _chatTop = _chatBottom - 10; |
| 107 | |
| 108 | const char* inputLine = _chatCurrentLine.c_str(); |
| 109 | int32_t inputLineHeight = 10; |
| 110 | |
| 111 | // Draw chat window |
| 112 | if (gChatOpen) |
| 113 | { |
| 114 | inputLineHeight = ChatStringWrappedGetHeight(inputLine, _chatWidth - 10); |
| 115 | _chatTop -= inputLineHeight; |
| 116 | |
| 117 | for (const auto& entry : _chatHistory) |
| 118 | { |
| 119 | if (entry.empty()) |
| 120 | { |
| 121 | continue; |
| 122 | } |
| 123 | lineBuffer = entry; |
| 124 | int32_t lineHeight = ChatStringWrappedGetHeight(lineBuffer, _chatWidth - 10); |
| 125 | _chatTop -= (lineHeight + 5); |
| 126 | } |
| 127 | |
| 128 | _chatHeight = _chatBottom - _chatTop; |
| 129 | |
| 130 | if (_chatTop < 50) |
| 131 | { |
| 132 | _chatTop = 50; |
| 133 | } |
| 134 | else if (_chatHeight < 150) |
| 135 | { // Min height |
| 136 | _chatTop = _chatBottom - 150; |
| 137 | _chatHeight = 150; |
| 138 | } |
| 139 | |
| 140 | ScreenCoordsXY topLeft{ _chatLeft, _chatTop }; |
| 141 | ScreenCoordsXY bottomRight{ _chatRight, _chatBottom }; |
| 142 | ScreenCoordsXY bottomLeft{ _chatLeft, _chatBottom }; |
| 143 | GfxSetDirtyBlocks( |
| 144 | { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }); // Background area + Textbox |
| 145 | Rectangle::filter( |
| 146 | rt, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }, |
| 147 | FilterPaletteID::palette51); // Opaque grey background |
| 148 | Rectangle::fillInset( |
| 149 | rt, { topLeft - ScreenCoordsXY{ 0, 5 }, bottomRight + ScreenCoordsXY{ 0, 5 } }, chatBackgroundColor, |
no test coverage detected