Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CEGUIListboxTextItem.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIListboxTextItem.cpp
00003         created:        12/6/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implementation of List box text items
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "elements/CEGUIListboxTextItem.h"
00027 #include "CEGUIFontManager.h"
00028 #include "CEGUIFont.h"
00029 #include "CEGUIWindow.h"
00030 #include "CEGUIImage.h"
00031 
00032 // Start of CEGUI namespace section
00033 namespace CEGUI
00034 {
00035 /*************************************************************************
00036         Constants
00037 *************************************************************************/
00038 const colour    ListboxTextItem::DefaultTextColour              = 0xFFFFFFFF;
00039 
00040 
00041 /*************************************************************************
00042         Constructor
00043 *************************************************************************/
00044 ListboxTextItem::ListboxTextItem(const String& text, uint item_id, void* item_data, bool disabled, bool auto_delete) :
00045         ListboxItem(text, item_id, item_data, disabled, auto_delete),
00046         d_textCols(DefaultTextColour, DefaultTextColour, DefaultTextColour, DefaultTextColour),
00047         d_font(NULL)
00048 {
00049 }
00050 
00051 
00052 /*************************************************************************
00053         Return a pointer to the font being used by this ListboxTextItem
00054 *************************************************************************/
00055 const Font* ListboxTextItem::getFont(void) const
00056 {
00057         // prefer out own font
00058         if (d_font != NULL)
00059         {
00060                 return d_font;
00061         }
00062         // try our owner window's font setting (may be null if owner uses no existant default font)
00063         else if (d_owner != NULL)
00064         {
00065                 return d_owner->getFont();
00066         }
00067         // no owner, just use the default (which may be NULL anyway)
00068         else
00069         {
00070                 return System::getSingleton().getDefaultFont();
00071         }
00072 
00073 }
00074 
00075 
00076 /*************************************************************************
00077         Set the font to be used by this ListboxTextItem
00078 *************************************************************************/
00079 void ListboxTextItem::setFont(const String& font_name)
00080 {
00081         setFont(FontManager::getSingleton().getFont(font_name));
00082 }
00083 
00084 /*************************************************************************
00085         Return the rendered pixel size of this list box item.
00086 *************************************************************************/
00087 Size ListboxTextItem::getPixelSize(void) const
00088 {
00089         Size tmp(0,0);
00090 
00091         const Font* fnt = getFont();
00092 
00093         if (fnt != NULL)
00094         {
00095                 tmp.d_height    = fnt->getLineSpacing();
00096                 tmp.d_width             = fnt->getTextExtent(d_itemText);
00097         }
00098 
00099         return tmp;
00100 }
00101 
00102 
00103 /*************************************************************************
00104         Draw the list box item in its current state.
00105 *************************************************************************/
00106 void ListboxTextItem::draw(const Vector3& position, float alpha, const Rect& clipper) const
00107 {
00108         if (d_selected && (d_selectBrush != NULL))
00109         {
00110                 d_selectBrush->draw(clipper, position.d_z, clipper, getModulateAlphaColourRect(d_selectCols, alpha));
00111         }
00112 
00113         const Font* fnt = getFont();
00114 
00115         if (fnt != NULL)
00116         {
00117         Vector3 finalPos(position);
00118         finalPos.d_y -= PixelAligned((fnt->getLineSpacing() - fnt->getBaseline()) * 0.5f);
00119                 fnt->drawText(d_itemText, finalPos, clipper, getModulateAlphaColourRect(d_textCols, alpha));
00120         }
00121 
00122 }
00123 
00124 
00125 /*************************************************************************
00126         Set the colours used for text rendering.        
00127 *************************************************************************/
00128 void ListboxTextItem::setTextColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour)
00129 {
00130         d_textCols.d_top_left           = top_left_colour;
00131         d_textCols.d_top_right          = top_right_colour;
00132         d_textCols.d_bottom_left        = bottom_left_colour;
00133         d_textCols.d_bottom_right       = bottom_right_colour;
00134 }
00135 
00136 
00137 } // End of  CEGUI namespace section

Generated on Wed Feb 16 12:41:06 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1