Receiving multi-color messages

Chat messages can now be formatted with colors in addition to varying
faces with "color_start," "color_length," and "color" slots in
IM_MESSAGE_RECEIVED.
This commit is contained in:
Jaidyn Ann 2021-08-16 21:50:43 -05:00
parent a697afbbd8
commit ab4881f2f0
3 changed files with 33 additions and 2 deletions

View File

@ -77,10 +77,13 @@ enum im_what_code {
buffer, rather than a specific conversation. buffer, rather than a specific conversation.
face_start and face_length specify the location of formatted text in face_start and face_length specify the location of formatted text in
the body, and "face" is the desired font face. Unsupported in bulk, the body, and "face" is the desired font face. Unsupported in bulk,
color_* works much the same, but with colors. Not much else to say.
i.e., IM_LOGS_RECEIVED. i.e., IM_LOGS_RECEIVED.
Requires: String "body" Requires: String "body"
Allows: String "chat_id", String "user_id", String "user_name", Allows: String "chat_id", String "user_id", String "user_name",
int32s "face_start", int32s "face_length", uint16s "face" */ int32s "face_start", int32s "face_length", uint16s "face"
int32s "color_start", int32s "color_length",
rgb_colors "color" */
IM_MESSAGE_RECEIVED = 22, IM_MESSAGE_RECEIVED = 22,
/*! Logs received →App /*! Logs received →App

View File

@ -413,7 +413,7 @@ ConversationView::_AppendMessage(BMessage* msg)
} }
// … else we're jamming a message into this view no matter what it takes! // … else we're jamming a message into this view no matter what it takes!
if (msg->HasInt32("face_start") == true) { if (msg->HasInt32("face_start") || msg->HasInt32("color_start")) {
_AppendFormattedMessage(msg); _AppendFormattedMessage(msg);
return; return;
} }
@ -504,10 +504,12 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
uint16 face = 0; uint16 face = 0;
UInt16IntMap face_indices; UInt16IntMap face_indices;
rgb_color color = ui_color(B_PANEL_TEXT_COLOR); rgb_color color = ui_color(B_PANEL_TEXT_COLOR);
int32 colorIndice = -1;
BFont font; BFont font;
for (int i = 0; i < body.CountChars(); i++) { for (int i = 0; i < body.CountChars(); i++) {
_EnableStartingFaces(msg, i, &face, &face_indices); _EnableStartingFaces(msg, i, &face, &face_indices);
_EnableStartingColor(msg, i, &color, &colorIndice);
if (face == B_REGULAR_FACE) { if (face == B_REGULAR_FACE) {
font = BFont(); font = BFont();
@ -517,6 +519,9 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
font.SetFace(face); font.SetFace(face);
} }
if (colorIndice <= 0)
color = ui_color(B_PANEL_TEXT_COLOR);
int32 bytes; int32 bytes;
const char* curChar = body.CharAt(i, &bytes); const char* curChar = body.CharAt(i, &bytes);
char append[bytes]; char append[bytes];
@ -527,6 +532,7 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
fReceiveView->Append(append, color, &font); fReceiveView->Append(append, color, &font);
_DisableEndingFaces(msg, &face, &face_indices); _DisableEndingFaces(msg, &face, &face_indices);
colorIndice--;
} }
fReceiveView->Append("\n"); fReceiveView->Append("\n");
} }
@ -576,6 +582,26 @@ ConversationView::_DisableEndingFaces(BMessage* msg, uint16* face,
} }
void
ConversationView::_EnableStartingColor(BMessage* msg, int32 index,
rgb_color* color, int32* indice)
{
rgb_color newColor;
int32 color_start, color_length, i = 0;
while (msg->FindInt32("color_start", i, &color_start) == B_OK) {
if (color_start == index
&& msg->FindInt32("color_length", i, &color_length) == B_OK
&& msg->FindColor("color", i, &newColor) == B_OK)
{
*indice = color_length;
*color = newColor;
break;
}
i++;
}
}
void void
ConversationView::_UserMessage(const char* format, const char* bodyFormat, ConversationView::_UserMessage(const char* format, const char* bodyFormat,
BMessage* msg) BMessage* msg)

View File

@ -64,6 +64,8 @@ private:
uint16* face, UInt16IntMap* indices); uint16* face, UInt16IntMap* indices);
void _DisableEndingFaces(BMessage* msg, uint16* face, void _DisableEndingFaces(BMessage* msg, uint16* face,
UInt16IntMap* indices); UInt16IntMap* indices);
void _EnableStartingColor(BMessage* msg, int32 index,
rgb_color* color, int32* indice);
void _UserMessage(const char* format, const char* bodyFormat, void _UserMessage(const char* format, const char* bodyFormat,
BMessage* msg); BMessage* msg);