summaryrefslogtreecommitdiff
path: root/indra/newview/llchatitemscontainerctrl.cpp
diff options
context:
space:
mode:
authorYuri Chebotarev <ychebotarev@productengine.com>2009-11-25 13:48:13 +0200
committerYuri Chebotarev <ychebotarev@productengine.com>2009-11-25 13:48:13 +0200
commitc2c83f3535c5a0bc099528580375afc99ad3b020 (patch)
treef54a6fb13ca135ff54a897836281df517aeab2f3 /indra/newview/llchatitemscontainerctrl.cpp
parent7f7191c1735a2a823943119eec5c1ca160a7bf8d (diff)
EXT-2555 Change look and feel of nearby chat toasts
--HG-- branch : product-engine
Diffstat (limited to 'indra/newview/llchatitemscontainerctrl.cpp')
-rw-r--r--indra/newview/llchatitemscontainerctrl.cpp319
1 files changed, 128 insertions, 191 deletions
diff --git a/indra/newview/llchatitemscontainerctrl.cpp b/indra/newview/llchatitemscontainerctrl.cpp
index 8a6935b71b..90956d4aa0 100644
--- a/indra/newview/llchatitemscontainerctrl.cpp
+++ b/indra/newview/llchatitemscontainerctrl.cpp
@@ -44,27 +44,12 @@
#include "llviewercontrol.h"
#include "llagentdata.h"
-/*
-static const S32 BORDER_MARGIN = 2;
-static const S32 PARENT_BORDER_MARGIN = 0;
-
-static const S32 HORIZONTAL_MULTIPLE = 8;
-static const S32 VERTICAL_MULTIPLE = 16;
-static const F32 MIN_AUTO_SCROLL_RATE = 120.f;
-static const F32 MAX_AUTO_SCROLL_RATE = 500.f;
-static const F32 AUTO_SCROLL_RATE_ACCEL = 120.f;
-
-#define MAX_CHAT_HISTORY 100
-*/
-
-static const S32 msg_left_offset = 30;
+static const S32 msg_left_offset = 10;
static const S32 msg_right_offset = 10;
-static const S32 msg_height_pad = 2;
-
-//static LLDefaultChildRegistry::Register<LLChatItemsContainerCtrl> t2("chat_items_container");
+static const S32 msg_height_pad = 5;
//*******************************************************************************************************************
-//LLChatItemCtrl
+//LLNearbyChatToastPanel
//*******************************************************************************************************************
LLNearbyChatToastPanel* LLNearbyChatToastPanel::createInstance()
@@ -79,22 +64,22 @@ void LLNearbyChatToastPanel::reshape (S32 width, S32 height, BOOL called_from_p
{
LLPanel::reshape(width, height,called_from_parent);
- // *NOTE: we must check if child items exist because reshape is called from the
- // LLView::initFromParams BEFORE postBuild is called and child controls are not exist yet
- LLPanel* caption = findChild<LLPanel>("msg_caption", false);
- LLChatMsgBox* msg_text = findChild<LLChatMsgBox>("msg_text" ,false);
- if(caption && msg_text)
- {
- LLRect caption_rect = caption->getRect();
- caption_rect.setLeftTopAndSize( 2, height, width - 4, caption_rect.getHeight());
- caption->reshape( width - 4, caption_rect.getHeight(), 1);
- caption->setRect(caption_rect);
-
- LLRect msg_text_rect = msg_text->getRect();
- msg_text_rect.setLeftTopAndSize( msg_left_offset, height - caption_rect.getHeight() , width - msg_left_offset - msg_right_offset, height - caption_rect.getHeight());
- msg_text->reshape( width - msg_left_offset - msg_right_offset, height - caption_rect.getHeight(), 1);
- msg_text->setRect(msg_text_rect);
- }
+ LLUICtrl* msg_text = getChild<LLUICtrl>("msg_text", false);
+ LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false);
+
+ LLRect msg_text_rect = msg_text->getRect();
+ LLRect avatar_rect = icon->getRect();
+
+ avatar_rect.setLeftTopAndSize(2,height-2,avatar_rect.getWidth(),avatar_rect.getHeight());
+ icon->setRect(avatar_rect);
+
+
+ msg_text_rect.setLeftTopAndSize( avatar_rect.mRight + msg_left_offset,
+ height - msg_height_pad,
+ width - avatar_rect.mRight - msg_left_offset - msg_right_offset,
+ height - 2*msg_height_pad);
+ msg_text->reshape( msg_text_rect.getWidth(), msg_text_rect.getHeight(), 1);
+ msg_text->setRect(msg_text_rect);
}
BOOL LLNearbyChatToastPanel::postBuild()
@@ -102,37 +87,63 @@ BOOL LLNearbyChatToastPanel::postBuild()
return LLPanel::postBuild();
}
-
-std::string LLNearbyChatToastPanel::appendTime()
+void LLNearbyChatToastPanel::addMessage(LLSD& notification)
{
- time_t utc_time;
- utc_time = time_corrected();
- std::string timeStr ="["+ LLTrans::getString("TimeHour")+"]:["
- +LLTrans::getString("TimeMin")+"] ";
+ std::string messageText = notification["message"].asString(); // UTF-8 line of text
- LLSD substitution;
+ LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
- substitution["datetime"] = (S32) utc_time;
- LLStringUtil::format (timeStr, substitution);
+ std::string color_name = notification["text_color"].asString();
+
+ LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
+ textColor.mV[VALPHA] =notification["color_alpha"].asReal();
+
+ S32 font_size = notification["font_size"].asInteger();
- return timeStr;
-}
+ LLFontGL* messageFont;
+ switch(font_size)
+ {
+ case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break;
+ default:
+ case 1: messageFont = LLFontGL::getFontSansSerif(); break;
+ case 2: messageFont = LLFontGL::getFontSansSerifBig(); break;
+ }
+ //append text
+ {
+ LLStyle::Params style_params;
+ style_params.color(textColor);
+ std::string font_name = LLFontGL::nameFromFont(messageFont);
+ std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
+ style_params.font.name(font_name);
+ style_params.font.size(font_style_size);
+ int chat_type = notification["chat_type"].asInteger();
+
+ if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
+ {
+ messageText = messageText.substr(3);
+ style_params.font.style = "ITALIC";
+ }
+ else if( chat_type == CHAT_TYPE_SHOUT)
+ {
+ style_params.font.style = "BOLD";
+ }
+ else if( chat_type == CHAT_TYPE_WHISPER)
+ {
+ style_params.font.style = "ITALIC";
+ }
+ msg_text->appendText(messageText, TRUE, style_params);
+ }
+
+ snapToMessageHeight();
-void LLNearbyChatToastPanel::addText (const std::string& message , const LLStyle::Params& input_params)
-{
- LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
- msg_text->addText(message , input_params);
- mMessages.push_back(message);
}
void LLNearbyChatToastPanel::init(LLSD& notification)
{
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
-
- mText = notification["message"].asString(); // UTF-8 line of text
- mFromName = notification["from"].asString(); // agent or object name
+ std::string messageText = notification["message"].asString(); // UTF-8 line of text
+ std::string fromName = notification["from"].asString(); // agent or object name
mFromID = notification["from_id"].asUUID(); // agent id or object id
int sType = notification["source"].asInteger();
@@ -140,192 +151,121 @@ void LLNearbyChatToastPanel::init(LLSD& notification)
std::string color_name = notification["text_color"].asString();
- mTextColor = LLUIColorTable::instance().getColor(color_name);
- mTextColor.mV[VALPHA] =notification["color_alpha"].asReal();
+ LLColor4 textColor = LLUIColorTable::instance().getColor(color_name);
+ textColor.mV[VALPHA] =notification["color_alpha"].asReal();
S32 font_size = notification["font_size"].asInteger();
+
+ LLFontGL* messageFont;
switch(font_size)
{
- case 0:
- mFont = LLFontGL::getFontSansSerifSmall();
- break;
+ case 0: messageFont = LLFontGL::getFontSansSerifSmall(); break;
default:
- case 1:
- mFont = LLFontGL::getFontSansSerif();
- break;
- case 2:
- mFont = LLFontGL::getFontSansSerifBig();
- break;
+ case 1: messageFont = LLFontGL::getFontSansSerif(); break;
+ case 2: messageFont = LLFontGL::getFontSansSerifBig(); break;
}
- LLStyle::Params style_params;
- style_params.color(mTextColor);
-// style_params.font(mFont);
- std::string font_name = LLFontGL::nameFromFont(mFont);
- std::string font_style_size = LLFontGL::sizeFromFont(mFont);
- style_params.font.name(font_name);
- style_params.font.size(font_style_size);
+ LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
+
+ msg_text->setText(std::string(""));
std::string str_sender;
if(gAgentID != mFromID)
- str_sender = mFromName;
+ str_sender = fromName;
else
- str_sender = LLTrans::getString("You");;
+ str_sender = LLTrans::getString("You");
- caption->getChild<LLTextBox>("sender_name", false)->setText(str_sender , style_params);
-
- LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
+ str_sender+=" ";
+ //append user name
+ {
+ LLStyle::Params style_params_name;
+
+ LLColor4 userNameColor = LLUIColorTable::instance().getColor("ChatToastUserNameColor");
+
+ style_params_name.color(userNameColor);
+
+ std::string font_name = LLFontGL::nameFromFont(messageFont);
+ std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
+ style_params_name.font.name(font_name);
+ style_params_name.font.size(font_style_size);
+
+ msg_text->appendText(str_sender, FALSE, style_params_name);
+
+ }
- if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
+ //append text
{
- if (mFromName.size() > 0)
+ LLStyle::Params style_params;
+ style_params.color(textColor);
+ std::string font_name = LLFontGL::nameFromFont(messageFont);
+ std::string font_style_size = LLFontGL::sizeFromFont(messageFont);
+ style_params.font.name(font_name);
+ style_params.font.size(font_style_size);
+
+ int chat_type = notification["chat_type"].asInteger();
+
+ if(notification["chat_style"].asInteger()== CHAT_STYLE_IRC)
{
+ messageText = messageText.substr(3);
style_params.font.style = "ITALIC";
-
- msg_text->setText(mFromName, style_params);
}
- mText = mText.substr(3);
- style_params.font.style = "ITALIC";
-#define INFINITE_REFLOW_BUG 0
-#if INFINITE_REFLOW_BUG
- // This causes LLTextBase::reflow() to infinite loop until the viewer
- // runs out of memory, throws a bad_alloc exception from std::vector
- // in mLineInfoList, and the main loop catches it and continues.
- // It appears to be caused by addText() adding a line separator in the
- // middle of a line. See EXT-2579, EXT-1949
- msg_text->addText(mText,style_params);
-#else
- msg_text->appendText(mText, FALSE, style_params);
-#endif
- }
- else
- {
- msg_text->setText(mText, style_params);
+ else if( chat_type == CHAT_TYPE_SHOUT)
+ {
+ style_params.font.style = "BOLD";
+ }
+ else if( chat_type == CHAT_TYPE_WHISPER)
+ {
+ style_params.font.style = "ITALIC";
+ }
+ msg_text->appendText(messageText, FALSE, style_params);
}
-
- LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector");
- if(mSourceType != CHAT_SOURCE_AGENT)
- msg_inspector->setVisible(false);
-
- mMessages.clear();
-
- snapToMessageHeight ();
+ snapToMessageHeight();
mIsDirty = true;//will set Avatar Icon in draw
}
-void LLNearbyChatToastPanel::setMessage (const LLChat& chat_msg)
-{
- LLSD notification;
- notification["message"] = chat_msg.mText;
- notification["from"] = chat_msg.mFromName;
- notification["from_id"] = chat_msg.mFromID;
- notification["time"] = chat_msg.mTime;
- notification["source"] = (S32)chat_msg.mSourceType;
- notification["chat_type"] = (S32)chat_msg.mChatType;
- notification["chat_style"] = (S32)chat_msg.mChatStyle;
-
- std::string r_color_name="White";
- F32 r_color_alpha = 1.0f;
- LLViewerChat::getChatColor( chat_msg, r_color_name, r_color_alpha);
-
- notification["text_color"] = r_color_name;
- notification["color_alpha"] = r_color_alpha;
-
- notification["font_size"] = (S32)LLViewerChat::getChatFontSize() ;
- init(notification);
-
-}
-
void LLNearbyChatToastPanel::snapToMessageHeight ()
{
LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
- S32 new_height = text_box->getTextPixelHeight() + msg_height_pad;
+ S32 new_height = llmax (text_box->getTextPixelHeight() + 2*text_box->getVPad() + 2*msg_height_pad, 25);
+
LLRect panel_rect = getRect();
- S32 caption_height = 0;
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
- caption_height = caption->getRect().getHeight();
-
- panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), caption_height + new_height);
+ panel_rect.setLeftTopAndSize( panel_rect.mLeft, panel_rect.mTop, panel_rect.getWidth(), new_height);
- reshape( getRect().getWidth(), caption_height + new_height, 1);
+ reshape( getRect().getWidth(), getRect().getHeight(), 1);
setRect(panel_rect);
}
-
-void LLNearbyChatToastPanel::setWidth(S32 width)
-{
- LLChatMsgBox* text_box = getChild<LLChatMsgBox>("msg_text", false);
- text_box->reshape(width - msg_left_offset - msg_right_offset,100/*its not magic number, we just need any number*/);
-
- LLChatMsgBox* msg_text = getChild<LLChatMsgBox>("msg_text", false);
-
- LLStyle::Params style_params;
- style_params.color(mTextColor);
- style_params.font(mFont);
-
-
- if(mText.length())
- msg_text->setText(mText, style_params);
-
- for(size_t i=0;i<mMessages.size();++i)
- msg_text->addText(mMessages[i] , style_params);
-
- setRect(LLRect(getRect().mLeft, getRect().mTop, getRect().mLeft + width , getRect().mBottom));
- snapToMessageHeight ();
-}
-
void LLNearbyChatToastPanel::onMouseLeave (S32 x, S32 y, MASK mask)
{
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
- LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector");
- msg_inspector->setVisible(false);
}
void LLNearbyChatToastPanel::onMouseEnter (S32 x, S32 y, MASK mask)
{
if(mSourceType != CHAT_SOURCE_AGENT)
return;
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
- LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector");
- msg_inspector->setVisible(true);
}
BOOL LLNearbyChatToastPanel::handleMouseDown (S32 x, S32 y, MASK mask)
{
if(mSourceType != CHAT_SOURCE_AGENT)
return LLPanel::handleMouseDown(x,y,mask);
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
- LLUICtrl* msg_inspector = caption->getChild<LLUICtrl>("msg_inspector");
- S32 local_x = x - msg_inspector->getRect().mLeft - caption->getRect().mLeft;
- S32 local_y = y - msg_inspector->getRect().mBottom - caption->getRect().mBottom;
- if(msg_inspector->pointInView(local_x, local_y))
- {
- LLFloaterReg::showInstance("inspect_avatar", LLSD().insert("avatar_id", mFromID));
- }
- else
- {
- LLFloaterReg::showInstance("nearby_chat",LLSD());
- }
+ LLFloaterReg::showInstance("nearby_chat",LLSD());
return LLPanel::handleMouseDown(x,y,mask);
}
void LLNearbyChatToastPanel::setHeaderVisibility(EShowItemHeader e)
{
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
-
- LLUICtrl* icon = caption->getChild<LLUICtrl>("avatar_icon", false);
- LLUICtrl* name = caption->getChild<LLUICtrl>("sender_name", false);
-
- icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH);
- name->setVisible(e == CHATITEMHEADER_SHOW_ONLY_NAME || e==CHATITEMHEADER_SHOW_BOTH);
+ LLUICtrl* icon = getChild<LLUICtrl>("avatar_icon", false);
+ if(icon)
+ icon->setVisible(e == CHATITEMHEADER_SHOW_ONLY_ICON || e==CHATITEMHEADER_SHOW_BOTH);
}
@@ -339,11 +279,10 @@ bool LLNearbyChatToastPanel::canAddText ()
BOOL LLNearbyChatToastPanel::handleRightMouseDown(S32 x, S32 y, MASK mask)
{
- LLPanel* caption = getChild<LLPanel>("msg_caption", false);
- LLUICtrl* avatar_icon = caption->getChild<LLUICtrl>("avatar_icon", false);
+ LLUICtrl* avatar_icon = getChild<LLUICtrl>("avatar_icon", false);
- S32 local_x = x - avatar_icon->getRect().mLeft - caption->getRect().mLeft;
- S32 local_y = y - avatar_icon->getRect().mBottom - caption->getRect().mBottom;
+ S32 local_x = x - avatar_icon->getRect().mLeft;
+ S32 local_y = y - avatar_icon->getRect().mBottom;
//eat message for avatar icon if msg was from object
if(avatar_icon->pointInView(local_x, local_y) && mSourceType != CHAT_SOURCE_AGENT)
@@ -354,9 +293,7 @@ void LLNearbyChatToastPanel::draw()
{
if(mIsDirty)
{
- LLPanel* caption = findChild<LLPanel>("msg_caption", false);
- if(caption)
- caption->getChild<LLAvatarIconCtrl>("avatar_icon", false)->setValue(mFromID);
+ getChild<LLAvatarIconCtrl>("avatar_icon", false)->setValue(mFromID);
mIsDirty = false;
}
LLToastPanelBase::draw();