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 LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLUUID &image_id)
00046 :       LLUICtrl(name, 
00047                          rect, 
00048                          FALSE, // mouse opaque
00049                          NULL, NULL, 
00050                          FOLLOWS_LEFT | FOLLOWS_TOP),
00051         mColor( LLColor4::white ),
00052         mImageName("")
00053 {
00054         setImage( image_id );
00055         setTabStop(FALSE);
00056 }
00057 
00058 LLIconCtrl::LLIconCtrl(const LLString& name, const LLRect &rect, const LLString &image_name)
00059 :       LLUICtrl(name, 
00060                          rect, 
00061                          FALSE, // mouse opaque
00062                          NULL, NULL, 
00063                          FOLLOWS_LEFT | FOLLOWS_TOP),
00064         mColor( LLColor4::white ),
00065         mImageName(image_name)
00066 {
00067         LLUUID image_id;
00068         image_id.set(LLUI::sAssetsGroup->getString( image_name ));
00069         setImage( image_id );
00070         setTabStop(FALSE);
00071 }
00072 
00073 
00074 LLIconCtrl::~LLIconCtrl()
00075 {
00076         mImagep = NULL;
00077 }
00078 
00079 
00080 void LLIconCtrl::setImage(const LLUUID &image_id)
00081 {
00082         mImageID = image_id;
00083         mImagep = LLUI::sImageProvider->getUIImageByID(image_id);
00084 }
00085 
00086 
00087 void LLIconCtrl::draw()
00088 {
00089         if( getVisible() ) 
00090         {
00091                 // Border
00092                 BOOL has_image = !mImageID.isNull();
00093 
00094                 if( has_image )
00095                 {
00096                         if( mImagep.notNull() )
00097                         {
00098                                 gl_draw_scaled_image(0, 0, 
00099                                                                          mRect.getWidth(), mRect.getHeight(), 
00100                                                                          mImagep,
00101                                                                          mColor );
00102                         }
00103                 }
00104 
00105                 LLUICtrl::draw();
00106         }
00107 }
00108 
00109 // virtual
00110 void LLIconCtrl::setValue(const LLSD& value )
00111 {
00112         setImage(value.asUUID());
00113 }
00114 
00115 // virtual
00116 LLSD LLIconCtrl::getValue() const
00117 {
00118         LLSD ret = getImage();
00119         return ret;
00120 }
00121 
00122 // virtual
00123 LLXMLNodePtr LLIconCtrl::getXML(bool save_children) const
00124 {
00125         LLXMLNodePtr node = LLUICtrl::getXML();
00126 
00127         if (mImageName != "")
00128         {
00129                 node->createChild("image_name", TRUE)->setStringValue(mImageName);
00130         }
00131 
00132         node->createChild("color", TRUE)->setFloatValue(4, mColor.mV);
00133 
00134         return node;
00135 }
00136 
00137 LLView* LLIconCtrl::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory)
00138 {
00139         LLString name("icon");
00140         node->getAttributeString("name", name);
00141 
00142         LLRect rect;
00143         createRect(node, rect, parent, LLRect());
00144 
00145         LLUUID image_id;
00146         if (node->hasAttribute("image_name"))
00147         {
00148                 LLString image_name;
00149                 node->getAttributeString("image_name", image_name);
00150                 image_id.set(LLUI::sAssetsGroup->getString( image_name ));
00151         }
00152 
00153         LLColor4 color(LLColor4::white);
00154         LLUICtrlFactory::getAttributeColor(node,"color", color);
00155 
00156         LLIconCtrl* icon = new LLIconCtrl(name, rect, image_id);
00157         icon->setColor(color);
00158 
00159         icon->initFromXML(node, parent);
00160 
00161         return icon;
00162 }

Generated on Thu Jul 1 06:08:43 2010 for Second Life Viewer by  doxygen 1.4.7