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:
parent
a697afbbd8
commit
ab4881f2f0
|
@ -77,10 +77,13 @@ enum im_what_code {
|
|||
buffer, rather than a specific conversation.
|
||||
face_start and face_length specify the location of formatted text in
|
||||
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.
|
||||
Requires: String "body"
|
||||
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,
|
||||
|
||||
/*! Logs received →App
|
||||
|
|
|
@ -413,7 +413,7 @@ ConversationView::_AppendMessage(BMessage* msg)
|
|||
}
|
||||
|
||||
// … 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);
|
||||
return;
|
||||
}
|
||||
|
@ -504,10 +504,12 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
|
|||
uint16 face = 0;
|
||||
UInt16IntMap face_indices;
|
||||
rgb_color color = ui_color(B_PANEL_TEXT_COLOR);
|
||||
int32 colorIndice = -1;
|
||||
|
||||
BFont font;
|
||||
for (int i = 0; i < body.CountChars(); i++) {
|
||||
_EnableStartingFaces(msg, i, &face, &face_indices);
|
||||
_EnableStartingColor(msg, i, &color, &colorIndice);
|
||||
|
||||
if (face == B_REGULAR_FACE) {
|
||||
font = BFont();
|
||||
|
@ -517,6 +519,9 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
|
|||
font.SetFace(face);
|
||||
}
|
||||
|
||||
if (colorIndice <= 0)
|
||||
color = ui_color(B_PANEL_TEXT_COLOR);
|
||||
|
||||
int32 bytes;
|
||||
const char* curChar = body.CharAt(i, &bytes);
|
||||
char append[bytes];
|
||||
|
@ -527,6 +532,7 @@ ConversationView::_AppendFormattedMessage(BMessage* msg)
|
|||
fReceiveView->Append(append, color, &font);
|
||||
|
||||
_DisableEndingFaces(msg, &face, &face_indices);
|
||||
colorIndice--;
|
||||
}
|
||||
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
|
||||
ConversationView::_UserMessage(const char* format, const char* bodyFormat,
|
||||
BMessage* msg)
|
||||
|
|
|
@ -64,6 +64,8 @@ private:
|
|||
uint16* face, UInt16IntMap* indices);
|
||||
void _DisableEndingFaces(BMessage* msg, uint16* face,
|
||||
UInt16IntMap* indices);
|
||||
void _EnableStartingColor(BMessage* msg, int32 index,
|
||||
rgb_color* color, int32* indice);
|
||||
|
||||
void _UserMessage(const char* format, const char* bodyFormat,
|
||||
BMessage* msg);
|
||||
|
|
Ŝarĝante…
Reference in New Issue