@@ -79,12 +79,14 @@ void TUI::setCommandCallback(std::function<void(const std::string&)> callback)
7979 m_commandCallback = callback;
8080}
8181
82- void TUI::addConsoleMessage (int channelId, const std::string& message)
83- {
82+ void TUI::addConsoleMessage (int channelId, const std::string& message, uint32_t msgColor) // no background color required, this is only for PRNT as of now, which doesn't deliver background colors anyways
83+ {
8484 std::lock_guard<std::mutex> lock (m_consoleMutex);
8585 ConsoleMessage cMessage;
8686 cMessage.channelId = channelId;
87+ cMessage.color = _byteswap_ulong (msgColor); // byteswapping because apparently message colors have their bytes swapped relative to channel colors...Valve...
8788 cMessage.message = message;
89+
8890 cMessage.timestamp = std::chrono::system_clock::now ();
8991
9092 m_consoleMessages.push_back (cMessage);
@@ -95,7 +97,7 @@ void TUI::addConsoleMessage(int channelId, const std::string& message)
9597 m_consoleDirty = true ;
9698}
9799
98- void TUI::registerChannel (int id, const std::string& name, uint32_t color)
100+ void TUI::registerChannel (int id, const std::string& name, uint32_t color, uint32_t backgroundColor )
99101{
100102 std::lock_guard<std::mutex> lock (m_channelsMutex);
101103
@@ -110,10 +112,7 @@ void TUI::registerChannel(int id, const std::string& name, uint32_t color)
110112 {
111113 if (m_nextColorPairId < COLOR_PAIRS)
112114 {
113- short colorPairId = m_nextColorPairId++;
114- initializeColor (color, colorPairId);
115- m_colorCache[color] = colorPairId;
116- channel.colorPairId = colorPairId;
115+ channel.colorPairId = initializeColor (color, backgroundColor);
117116 }
118117 else
119118 {
@@ -173,21 +172,25 @@ void TUI::drawConsoleWindow()
173172
174173 std::string prefix;
175174 short colorPairId = 0 ;
175+
176+ if (channelIt != m_channels.end ())
177+ {
178+ colorPairId = channelIt->second .colorPairId ;
179+ prefix = " [" + channelIt->second .name + " ] " ;
180+ }
181+ else
182+ {
183+ prefix = " [Unknown] " ;
184+ }
185+
176186
177187 if (currentMessage.channelId == APPLICATION_SPECIAL_CHANNEL_ID)
178188 {
179189 prefix = " " ;
180- colorPairId = m_colorCache[4285057279 ];
181190 }
182- else if (channelIt != m_channels. end () )
191+ if (currentMessage. color )
183192 {
184- const auto & channel = channelIt->second ;
185- prefix = " [" + channel.name + " ] " ;
186- colorPairId = channel.colorPairId ;
187- }
188- else
189- {
190- prefix = " [Unknown] " ;
193+ colorPairId = initializeColor (currentMessage.color );
191194 }
192195
193196 if (colorPairId != 0 )
@@ -353,21 +356,49 @@ short TUI::mapTo256Color(uint32_t color)
353356 round (b / 255.0 * 5 ));
354357}
355358
356- void TUI::initializeColor (uint32_t color, short & colorPairId )
359+ short TUI::initializeColor (uint32_t color, uint32_t backgroundColor )
357360{
361+ long long combinedColor = (((long long )color) << 32 ) | (backgroundColor & 0xffffffffL );
362+
363+ short colorPairId = 0 ;
364+
358365 int r = (color >> 24 ) & 0xFF ;
359366 int g = (color >> 16 ) & 0xFF ;
360367 int b = (color >> 8 ) & 0xFF ;
361368
362- if (m_useExtendedColors)
369+ int br = (backgroundColor >> 24 ) & 0xFF ;
370+ int bg = (backgroundColor >> 16 ) & 0xFF ;
371+ int bb = (backgroundColor >> 8 ) & 0xFF ;
372+
373+ if (m_colorCache.find (combinedColor) == m_colorCache.end ())
363374 {
364- int colorNumber = EXTENDED_COLOR_BASE + colorPairId;
365- init_color (colorNumber, r * 1000 / 255 , g * 1000 / 255 , b * 1000 / 255 );
366- init_pair (colorPairId, colorNumber, -1 );
375+ colorPairId = m_nextColorPairId++;
376+ if (m_useExtendedColors)
377+ {
378+ int colorNumber = EXTENDED_COLOR_BASE + m_nextColorId++;
379+ int bColorNumber = -1 ;
380+ if (backgroundColor)
381+ bColorNumber = EXTENDED_COLOR_BASE + m_nextColorId++;
382+ init_color (colorNumber, r * 1000 / 255 , g * 1000 / 255 , b * 1000 / 255 );
383+ init_color (bColorNumber, br * 1000 / 255 , bg * 1000 / 255 , bb * 1000 / 255 );
384+ color_content (colorNumber, (short *)&r, (short *)&g, (short *)&b);
385+ init_pair (colorPairId, colorNumber, bColorNumber);
386+ }
387+ else
388+ {
389+ short nearestColor = mapTo256Color (color);
390+ short bNearestColor = -1 ;
391+ if (backgroundColor)
392+ bNearestColor = mapTo256Color (backgroundColor);
393+ init_pair (colorPairId, nearestColor, bNearestColor);
394+ }
395+ m_colorCache[combinedColor] = colorPairId;
367396 }
368397 else
369398 {
370- short nearestColor = mapTo256Color (color);
371- init_pair ( colorPairId, nearestColor, - 1 ) ;
399+
400+ colorPairId = m_colorCache. find (combinedColor)-> second ;
372401 }
402+
403+ return colorPairId;
373404}
0 commit comments