From e92f6be91988665591b2b99c698552d295e98fef Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Wed, 23 Mar 2011 22:00:03 -0700 Subject: Comboboxes can now use the font= xui setting --- linden/indra/llui/llcombobox.cpp | 25 ++++++++++++++++++++----- linden/indra/llui/llcombobox.h | 4 +++- linden/indra/llui/llscrolllistctrl.cpp | 28 +++++++++++++++++++++------- linden/indra/llui/llscrolllistctrl.h | 3 +++ 4 files changed, 47 insertions(+), 13 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/llcombobox.cpp b/linden/indra/llui/llcombobox.cpp index be34325..a93dc9b 100644 --- a/linden/indra/llui/llcombobox.cpp +++ b/linden/indra/llui/llcombobox.cpp @@ -43,6 +43,7 @@ // newview includes #include "llbutton.h" +#include "llfont.h" #include "llkeyboard.h" #include "llscrolllistctrl.h" #include "llwindow.h" @@ -60,7 +61,7 @@ S32 MAX_COMBO_WIDTH = 500; static LLRegisterWidget r1("combo_box"); -LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::string& label, +LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std::string& label, const LLFontGL* font, void (*commit_callback)(LLUICtrl*,void*), void *callback_userdata ) @@ -76,6 +77,15 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std:: mTextEntryCallback( NULL ), mLabel(label) { + if (font) + { + mGLFont = font; + } + else + { + mGLFont = LLFontGL::getFontSansSerifSmall(); + } + // Always use text box // Text label button mButton = new LLButton(mLabel, @@ -89,14 +99,14 @@ LLComboBox::LLComboBox( const std::string& name, const LLRect &rect, const std:: mButton->setScaleImage(TRUE); mButton->setMouseDownCallback(onButtonDown); - mButton->setFont(LLFontGL::getFontSansSerifSmall()); + mButton->setFont(mGLFont); mButton->setFollows(FOLLOWS_LEFT | FOLLOWS_BOTTOM | FOLLOWS_RIGHT); mButton->setHAlign( LLFontGL::LEFT ); mButton->setRightHPad(2); addChild(mButton); // disallow multiple selection - mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(), + mList = new LLScrollListCtrl(std::string("ComboBox"), LLRect(), mGLFont, &LLComboBox::onItemSelected, this, FALSE); mList->setVisible(FALSE); mList->setBgWriteableColor( LLColor4(1,1,1,1) ); @@ -167,11 +177,14 @@ LLView* LLComboBox::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory * S32 max_chars = 20; node->getAttributeS32("max_chars", max_chars); + LLFontGL* font = LLView::selectFont(node); + LLUICtrlCallback callback = NULL; LLComboBox* combo_box = new LLComboBox(name, rect, label, + font, callback, NULL); combo_box->setAllowTextEntry(allow_text_entry, max_chars); @@ -540,7 +553,7 @@ void LLComboBox::updateLayout() mTextEntry = new LLLineEditor(std::string("combo_text_entry"), text_entry_rect, LLStringUtil::null, - LLFontGL::getFontSansSerifSmall(), + mGLFont, mMaxChars, onTextCommit, onTextEntry, @@ -1153,7 +1166,7 @@ LLFlyoutButton::LLFlyoutButton( const std::string& label, void (*commit_callback)(LLUICtrl*, void*) , void *callback_userdata) -: LLComboBox(name, rect, LLStringUtil::null, commit_callback, callback_userdata), +: LLComboBox(name, rect, LLStringUtil::null, NULL, commit_callback, callback_userdata), mToggleState(FALSE), mActionButton(NULL) { @@ -1214,6 +1227,8 @@ LLXMLNodePtr LLFlyoutButton::getXML(bool save_children) const } } + node->createChild("font", TRUE)->setStringValue(LLFontGL::nameFromFont(mGLFont)); + return node; } diff --git a/linden/indra/llui/llcombobox.h b/linden/indra/llui/llcombobox.h index 95ad17a..596f659 100644 --- a/linden/indra/llui/llcombobox.h +++ b/linden/indra/llui/llcombobox.h @@ -67,7 +67,8 @@ public: LLComboBox( const std::string& name, const LLRect &rect, - const std::string& label, + const std::string& label, + const LLFontGL* font = NULL, void (*commit_callback)(LLUICtrl*, void*) = NULL, void *callback_userdata = NULL ); @@ -190,6 +191,7 @@ protected: EPreferredPosition mListPosition; LLPointer mArrowImage; std::string mLabel; + const LLFontGL* mGLFont; private: S32 mButtonPadding; diff --git a/linden/indra/llui/llscrolllistctrl.cpp b/linden/indra/llui/llscrolllistctrl.cpp index 1248a9a..1b93abf 100644 --- a/linden/indra/llui/llscrolllistctrl.cpp +++ b/linden/indra/llui/llscrolllistctrl.cpp @@ -570,7 +570,7 @@ void LLScrollListItemSeparator::draw(const LLRect& rect, const LLColor4& fg_colo // LLScrollListCtrl //--------------------------------------------------------------------------- -LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, +LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, const LLFontGL* font, void (*commit_callback)(LLUICtrl* ctrl, void* userdata), void* callback_user_data, BOOL allow_multiple_selection, @@ -619,6 +619,15 @@ LLScrollListCtrl::LLScrollListCtrl(const std::string& name, const LLRect& rect, mOriginalSelection(-1), mDrewSelected(FALSE) { + if (font) + { + mGLFont = font; + } + else + { + mGLFont = LLFontGL::getFontSansSerifSmall(); + } + mItemListRect.setOriginAndSize( mBorderThickness, mBorderThickness, @@ -987,14 +996,14 @@ void LLScrollListCtrl::calcColumnWidths() column->setWidth(new_width); // update max content width for this column, by looking at all items - column->mMaxContentWidth = column->mHeader ? LLFontGL::getFontSansSerifSmall()->getWidth(column->mLabel) + mColumnPadding + HEADING_TEXT_PADDING : 0; + column->mMaxContentWidth = column->mHeader ? mGLFont->getWidth(column->mLabel) + mColumnPadding + HEADING_TEXT_PADDING : 0; item_list::iterator iter; for (iter = mItemList.begin(); iter != mItemList.end(); iter++) { LLScrollListCell* cellp = (*iter)->getColumn(column->mIndex); if (!cellp) continue; - column->mMaxContentWidth = llmax(LLFontGL::getFontSansSerifSmall()->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth); + column->mMaxContentWidth = llmax(mGLFont->getWidth(cellp->getValue().asString()) + mColumnPadding + COLUMN_TEXT_PADDING, column->mMaxContentWidth); } max_item_width += column->mMaxContentWidth; @@ -1642,7 +1651,7 @@ LLScrollListItem* LLScrollListCtrl::addStringUUIDItem(const std::string& item_te if (getItemCount() < mMaxItemCount) { item = new LLScrollListItem( enabled, NULL, id ); - item->addColumn(item_text, LLResMgr::getInstance()->getRes(LLFONT_SANSSERIF_SMALL), column_width); + item->addColumn(item_text, mGLFont, column_width); addItem( item, pos ); } return item; @@ -2900,6 +2909,7 @@ LLView* LLScrollListCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFac LLScrollListCtrl* scroll_list = new LLScrollListCtrl( name, rect, + NULL, callback, NULL, multi_select, @@ -3374,7 +3384,11 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p const LLFontGL *font = LLResMgr::getInstance()->getRes(fontname); if (!font) { - font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + font = mGLFont; + if (!font) + { + font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + } } U8 font_style = LLFontGL::getStyleFromString(fontstyle); @@ -3446,7 +3460,7 @@ LLScrollListItem* LLScrollListCtrl::addElement(const LLSD& value, EAddPosition p if (new_item->getColumn(column_idx) == NULL) { LLScrollListColumn* column_ptr = &column_it->second; - new_item->setColumn(column_idx, new LLScrollListText(LLStringUtil::null, LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ), column_ptr->getWidth(), LLFontGL::NORMAL)); + new_item->setColumn(column_idx, new LLScrollListText(LLStringUtil::null, mGLFont, column_ptr->getWidth(), LLFontGL::NORMAL)); } } @@ -3466,7 +3480,7 @@ LLScrollListItem* LLScrollListCtrl::addSimpleElement(const std::string& value, E LLScrollListItem *new_item = new LLScrollListItem(entry_id); - const LLFontGL *font = LLResMgr::getInstance()->getRes( LLFONT_SANSSERIF_SMALL ); + const LLFontGL *font = mGLFont; new_item->addColumn(value, font, getRect().getWidth()); diff --git a/linden/indra/llui/llscrolllistctrl.h b/linden/indra/llui/llscrolllistctrl.h index 4be7ff7..1b7105f 100644 --- a/linden/indra/llui/llscrolllistctrl.h +++ b/linden/indra/llui/llscrolllistctrl.h @@ -353,6 +353,7 @@ public: LLScrollListCtrl( const std::string& name, const LLRect& rect, + const LLFontGL* font, void (*commit_callback)(LLUICtrl*, void*), void* callback_userdata, BOOL allow_multiple_selection, @@ -694,6 +695,8 @@ private: // HACK: Did we draw one selected item this frame? BOOL mDrewSelected; + + const LLFontGL* mGLFont; }; // end class LLScrollListCtrl -- cgit v1.1