Modernize LLIconCtrl
Adds min_height and min_width attributes Adds mPriority for controlling priority with which to call LLUI::getUIImage* Moves specialized setImage()s into setValue Removes mImageName and mImageID, value is stored in base as LLSD now
This commit is contained in:
@@ -40,68 +40,32 @@
|
||||
#include "llcontrol.h"
|
||||
#include "llui.h"
|
||||
#include "lluictrlfactory.h"
|
||||
|
||||
const F32 RESOLUTION_BUMP = 1.f;
|
||||
#include "lluiimage.h"
|
||||
|
||||
static LLRegisterWidget<LLIconCtrl> r("icon");
|
||||
|
||||
LLIconCtrl::LLIconCtrl(const std::string& name, const LLRect &rect, const LLUUID &image_id)
|
||||
: LLUICtrl(name,
|
||||
rect,
|
||||
FALSE, // mouse opaque
|
||||
NULL,
|
||||
FOLLOWS_LEFT | FOLLOWS_TOP),
|
||||
mColor( LLColor4::white )
|
||||
{
|
||||
setImage( image_id );
|
||||
setTabStop(FALSE);
|
||||
}
|
||||
|
||||
LLIconCtrl::LLIconCtrl(const std::string& name, const LLRect &rect, const std::string &image_name)
|
||||
LLIconCtrl::LLIconCtrl(const std::string& name, const LLRect &rect, const std::string &image_name, const S32& min_width, const S32& min_height)
|
||||
: LLUICtrl(name,
|
||||
rect,
|
||||
FALSE, // mouse opaque
|
||||
NULL,
|
||||
FOLLOWS_LEFT | FOLLOWS_TOP),
|
||||
mColor( LLColor4::white ),
|
||||
mImageName(image_name)
|
||||
mPriority(0),
|
||||
mMinWidth(min_width),
|
||||
mMinHeight(min_height)
|
||||
{
|
||||
setImage( image_name );
|
||||
setValue( image_name );
|
||||
setTabStop(FALSE);
|
||||
}
|
||||
|
||||
|
||||
LLIconCtrl::~LLIconCtrl()
|
||||
{
|
||||
mImagep = NULL;
|
||||
}
|
||||
|
||||
|
||||
void LLIconCtrl::setImage(const std::string& image_name)
|
||||
{
|
||||
//RN: support UUIDs masquerading as strings
|
||||
if (LLUUID::validate(image_name))
|
||||
{
|
||||
mImageID = LLUUID(image_name);
|
||||
|
||||
setImage(mImageID);
|
||||
}
|
||||
else
|
||||
{
|
||||
mImageName = image_name;
|
||||
mImagep = LLUI::getUIImage(image_name);
|
||||
mImageID.setNull();
|
||||
}
|
||||
}
|
||||
|
||||
void LLIconCtrl::setImage(const LLUUID& image_id)
|
||||
{
|
||||
mImageName.clear();
|
||||
mImagep = LLUI::getUIImageByID(image_id);
|
||||
mImageID = image_id;
|
||||
}
|
||||
|
||||
|
||||
void LLIconCtrl::draw()
|
||||
{
|
||||
if( mImagep.notNull() )
|
||||
@@ -120,23 +84,40 @@ void LLIconCtrl::setAlpha(F32 alpha)
|
||||
}
|
||||
|
||||
// virtual
|
||||
// value might be a string or a UUID
|
||||
void LLIconCtrl::setValue(const LLSD& value )
|
||||
{
|
||||
if (value.isUUID())
|
||||
LLSD tvalue(value);
|
||||
if (value.isString() && LLUUID::validate(value.asString()))
|
||||
{
|
||||
setImage(value.asUUID());
|
||||
//RN: support UUIDs masquerading as strings
|
||||
tvalue = LLSD(LLUUID(value.asString()));
|
||||
}
|
||||
LLUICtrl::setValue(tvalue);
|
||||
if (tvalue.isUUID())
|
||||
{
|
||||
mImagep = LLUI::getUIImageByID(tvalue.asUUID(), mPriority);
|
||||
}
|
||||
else
|
||||
{
|
||||
setImage(value.asString());
|
||||
mImagep = LLUI::getUIImage(tvalue.asString(), mPriority);
|
||||
}
|
||||
|
||||
if (mImagep.notNull()
|
||||
&& mImagep->getImage().notNull()
|
||||
&& mMinWidth
|
||||
&& mMinHeight)
|
||||
{
|
||||
mImagep->getImage()->setKnownDrawSize(llmax(mMinWidth, mImagep->getWidth()), llmax(mMinHeight, mImagep->getHeight()));
|
||||
}
|
||||
}
|
||||
|
||||
// virtual
|
||||
LLSD LLIconCtrl::getValue() const
|
||||
std::string LLIconCtrl::getImageName() const
|
||||
{
|
||||
LLSD ret = getImage();
|
||||
return ret;
|
||||
if (getValue().isString())
|
||||
return getValue().asString();
|
||||
else
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// virtual
|
||||
@@ -146,11 +127,14 @@ LLXMLNodePtr LLIconCtrl::getXML(bool save_children) const
|
||||
|
||||
node->setName(LL_ICON_CTRL_TAG);
|
||||
|
||||
if (mImageName != "")
|
||||
if (!getImageName().empty())
|
||||
{
|
||||
node->createChild("image_name", TRUE)->setStringValue(mImageName);
|
||||
node->createChild("image_name", TRUE)->setStringValue(getImageName());
|
||||
}
|
||||
|
||||
if (mMinWidth) node->createChild("min_width", true)->setIntValue(mMinWidth);
|
||||
if (mMinHeight) node->createChild("min_height", true)->setIntValue(mMinHeight);
|
||||
|
||||
node->createChild("color", TRUE)->setFloatValue(4, mColor.mV);
|
||||
|
||||
return node;
|
||||
@@ -170,7 +154,18 @@ LLView* LLIconCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *
|
||||
LLColor4 color(LLColor4::white);
|
||||
LLUICtrlFactory::getAttributeColor(node,"color", color);
|
||||
|
||||
LLIconCtrl* icon = new LLIconCtrl("icon", rect, image_name);
|
||||
S32 min_width = 0, min_height = 0;
|
||||
if (node->hasAttribute("min_width"))
|
||||
{
|
||||
node->getAttributeS32("min_width", min_width);
|
||||
}
|
||||
|
||||
if (node->hasAttribute("min_height"))
|
||||
{
|
||||
node->getAttributeS32("min_height", min_height);
|
||||
}
|
||||
|
||||
LLIconCtrl* icon = new LLIconCtrl("icon", rect, image_name, min_width, min_height);
|
||||
|
||||
icon->setColor(color);
|
||||
|
||||
|
||||
@@ -49,33 +49,35 @@ class LLIconCtrl
|
||||
: public LLUICtrl
|
||||
{
|
||||
public:
|
||||
LLIconCtrl(const std::string& name, const LLRect &rect, const LLUUID &image_id);
|
||||
LLIconCtrl(const std::string& name, const LLRect &rect, const std::string &image_name);
|
||||
LLIconCtrl(const std::string& name, const LLRect &rect, const std::string &image_name, const S32& min_width = 0, const S32& min_height = 0);
|
||||
virtual ~LLIconCtrl();
|
||||
|
||||
// llview overrides
|
||||
virtual void draw();
|
||||
|
||||
void setImage(const std::string& image_name);
|
||||
void setImage(const LLUUID& image_name);
|
||||
const LLUUID &getImage() const { return mImageID; }
|
||||
std::string getImageName() const { return mImageName; }
|
||||
|
||||
// Takes a UUID, wraps get/setImage
|
||||
// lluictrl overrides
|
||||
virtual void setValue(const LLSD& value );
|
||||
virtual LLSD getValue() const;
|
||||
|
||||
/*virtual*/ void setAlpha(F32 alpha);
|
||||
|
||||
std::string getImageName() const;
|
||||
|
||||
void setColor(const LLColor4& color) { mColor = color; }
|
||||
void setImage(LLPointer<LLUIImage> image) { mImagep = image; }
|
||||
const LLPointer<LLUIImage> getImage() { return mImagep; }
|
||||
|
||||
virtual LLXMLNodePtr getXML(bool save_children = true) const;
|
||||
static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
|
||||
|
||||
protected:
|
||||
S32 mPriority;
|
||||
|
||||
//the output size of the icon image if set.
|
||||
S32 mMinWidth,
|
||||
mMinHeight;
|
||||
|
||||
private:
|
||||
LLColor4 mColor;
|
||||
std::string mImageName;
|
||||
LLUUID mImageID;
|
||||
LLPointer<LLUIImage> mImagep;
|
||||
};
|
||||
|
||||
|
||||
@@ -4275,7 +4275,7 @@ void LLModelPreview::updateStatusMessages()
|
||||
std::string img = lod_status_image[upload_status[lod]];
|
||||
LLIconCtrl* icon = mFMP->getChild<LLIconCtrl>(lod_icon_name[lod]);
|
||||
icon->setVisible(true);
|
||||
icon->setImage(img);
|
||||
icon->setValue(img);
|
||||
|
||||
if (upload_status[lod] >= 2)
|
||||
{
|
||||
@@ -4286,7 +4286,7 @@ void LLModelPreview::updateStatusMessages()
|
||||
{
|
||||
mFMP->childSetText("lod_status_message_text", mFMP->getString(message));
|
||||
icon = mFMP->getChild<LLIconCtrl>("lod_status_message_icon");
|
||||
icon->setImage(img);
|
||||
icon->setValue(img);
|
||||
}
|
||||
|
||||
updateLodControls(lod);
|
||||
|
||||
@@ -163,7 +163,7 @@ LLGroupNotifyBox::LLGroupNotifyBox(const std::string& subject,
|
||||
{
|
||||
icon = new LLIconCtrl(std::string("icon"),
|
||||
LLRect(x, y, x+ICON_WIDTH, y-ICON_WIDTH),
|
||||
group_insignia);
|
||||
group_insignia.asString());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -293,7 +293,7 @@ void LLMediaRemoteCtrl::enableMediaButtons()
|
||||
mMusicIcon->setColor(music_icon_color);
|
||||
if(!media_icon_name.empty())
|
||||
{
|
||||
media_icon->setImage(media_icon_name);
|
||||
media_icon->setValue(media_icon_name);
|
||||
}
|
||||
|
||||
media_play_btn->setEnabled(play_media_enabled);
|
||||
|
||||
@@ -310,7 +310,7 @@ void LLPanelGroupNotices::setItem(LLPointer<LLInventoryItem> inv_item)
|
||||
inv_item->getFlags(),
|
||||
item_is_multi );
|
||||
|
||||
mCreateInventoryIcon->setImage(icon_name);
|
||||
mCreateInventoryIcon->setValue(icon_name);
|
||||
mCreateInventoryIcon->setVisible(TRUE);
|
||||
|
||||
std::stringstream ss;
|
||||
@@ -541,7 +541,7 @@ void LLPanelGroupNotices::showNotice(const std::string& subject,
|
||||
std::string icon_name = LLInventoryIcon::getIconName(mInventoryOffer->mType,
|
||||
LLInventoryType::IT_TEXTURE);
|
||||
|
||||
mViewInventoryIcon->setImage(icon_name);
|
||||
mViewInventoryIcon->setValue(icon_name);
|
||||
mViewInventoryIcon->setVisible(TRUE);
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -94,10 +94,10 @@ void LLViewChildren::setBadge(const std::string& id, Badge badge, bool visible)
|
||||
switch (badge)
|
||||
{
|
||||
default:
|
||||
case BADGE_OK: child->setImage(std::string("badge_ok.j2c")); break;
|
||||
case BADGE_NOTE: child->setImage(std::string("badge_note.j2c")); break;
|
||||
case BADGE_WARN: child->setImage(std::string("badge_warn.j2c")); break;
|
||||
case BADGE_ERROR: child->setImage(std::string("badge_error.j2c")); break;
|
||||
case BADGE_OK: child->setValue(std::string("badge_ok.j2c")); break;
|
||||
case BADGE_NOTE: child->setValue(std::string("badge_note.j2c")); break;
|
||||
case BADGE_WARN: child->setValue(std::string("badge_warn.j2c")); break;
|
||||
case BADGE_ERROR: child->setValue(std::string("badge_error.j2c")); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void LLVoiceRemoteCtrl::draw()
|
||||
LLIconCtrl* icon = mVoiceVolIcon;
|
||||
if (icon)
|
||||
{
|
||||
icon->setImage(talk_blip_image);
|
||||
icon->setValue(talk_blip_image);
|
||||
}
|
||||
|
||||
LLFloater* voice_floater = LLFloaterChatterBox::getInstance()->getCurrentVoiceFloater();
|
||||
@@ -185,7 +185,7 @@ void LLVoiceRemoteCtrl::draw()
|
||||
LLIconCtrl* voice_channel_icon = findChild<LLIconCtrl>("voice_channel_icon");
|
||||
if (voice_channel_icon && voice_floater)
|
||||
{
|
||||
voice_channel_icon->setImage(voice_floater->getString("voice_icon"));
|
||||
voice_channel_icon->setValue(voice_floater->getString("voice_icon"));
|
||||
}
|
||||
|
||||
if (voice_channel_bg)
|
||||
|
||||
Reference in New Issue
Block a user