lliconctrl.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "lliconctrl.h"
00035 
00036 // Linden library includes 
00037 
00038 // Project includes
00039 #include "llcontrol.h"
00040 #include "llui.h"
00041 #include "lluictrlfactory.h"
00042 
00043 const F32 RESOLUTION_BUMP = 1.f;
00044 
00045 static LLRegisterWidget<LLIconCtrl> r("icon");
00046 
00047 LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLUUID &image_id)
00048 :       LLUICtrl(name, 
00049                          rect, 
00050                          FALSE, // mouse opaque
00051                          NULL, NULL, 
00052                          FOLLOWS_LEFT | FOLLOWS_TOP),
00053         mColor( LLColor4::white )
00054 {
00055         setImage( image_id );
00056         setTabStop(FALSE);
00057 }
00058 
00059 LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLString &image_name)
00060 :       LLUICtrl(name, 
00061                          rect, 
00062                          FALSE, // mouse opaque
00063                          NULL, NULL, 
00064                          FOLLOWS_LEFT | FOLLOWS_TOP),
00065         mColor( LLColor4::white ),
00066         mImageName(image_name)
00067 {
00068         setImage( image_name );
00069         setTabStop(FALSE);
00070 }
00071 
00072 
00073 LLIconCtrl::~LLIconCtrl()
00074 {
00075         mImagep = NULL;
00076 }
00077 
00078 
00079 void LLIconCtrl::setImage(const LLString& image_name)
00080 {
00081         //RN: support UUIDs masquerading as strings
00082         if (LLUUID::validate(image_name))
00083         {
00084                 mImageID = LLUUID(image_name);
00085 
00086                 setImage(mImageID);
00087         }
00088         else
00089         {
00090                 mImageName = image_name;
00091                 mImagep = LLUI::sImageProvider->getUIImage(image_name);
00092                 mImageID.setNull();
00093         }
00094 }
00095 
00096 void LLIconCtrl::setImage(const LLUUID& image_id)
00097 {
00098         mImageName.clear();
00099         mImagep = LLUI::sImageProvider->getUIImageByID(image_id);
00100         mImageID = image_id;
00101 }
00102 
00103 
00104 void LLIconCtrl::draw()
00105 {
00106         if( mImagep.notNull() )
00107         {
00108                 mImagep->draw(getLocalRect(), mColor );
00109         }
00110 
00111         LLUICtrl::draw();
00112 }
00113 
00114 // virtual
00115 void LLIconCtrl::setValue(const LLSD& value )
00116 {
00117         if (value.isUUID())
00118         {
00119                 setImage(value.asUUID());
00120         }
00121         else
00122         {
00123                 setImage(value.asString());
00124         }
00125 }
00126 
00127 // virtual
00128 LLSD LLIconCtrl::getValue() const
00129 {
00130         LLSD ret = getImage();
00131         return ret;
00132 }
00133 
00134 // virtual
00135 LLXMLNodePtr LLIconCtrl::getXML(bool save_children) const
00136 {
00137         LLXMLNodePtr node = LLUICtrl::getXML();
00138 
00139         if (mImageName != "")
00140         {
00141                 node->createChild("image_name", TRUE)->setStringValue(mImageName);
00142         }
00143 
00144         node->createChild("color", TRUE)->setFloatValue(4, mColor.mV);
00145 
00146         return node;
00147 }
00148 
00149 LLView* LLIconCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00150 {
00151         LLString name("icon");
00152         node->getAttributeString("name", name);
00153 
00154         LLRect rect;
00155         createRect(node, rect, parent, LLRect());
00156 
00157         LLString image_name;
00158         if (node->hasAttribute("image_name"))
00159         {
00160                 node->getAttributeString("image_name", image_name);
00161         }
00162 
00163         LLColor4 color(LLColor4::white);
00164         LLUICtrlFactory::getAttributeColor(node,"color", color);
00165 
00166         LLIconCtrl* icon = new LLIconCtrl(name, rect, image_name);
00167 
00168         icon->setColor(color);
00169 
00170         icon->initFromXML(node, parent);
00171 
00172         return icon;
00173 }

Generated on Fri May 16 08:32:52 2008 for SecondLife by  doxygen 1.5.5