From: <ice...@us...> - 2009-06-29 17:44:27
|
Revision: 2070 http://crayzedsgui.svn.sourceforge.net/crayzedsgui/?rev=2070&view=rev Author: ice-drezday Date: 2009-06-29 17:44:26 +0000 (Mon, 29 Jun 2009) Log Message: ----------- Transition CEGUI::TreeItem to use RenderedString rather than the basic String. Modified Paths: -------------- cegui_mk2/trunk/cegui/include/elements/CEGUITreeItem.h cegui_mk2/trunk/cegui/src/elements/CEGUITreeItem.cpp Modified: cegui_mk2/trunk/cegui/include/elements/CEGUITreeItem.h =================================================================== --- cegui_mk2/trunk/cegui/include/elements/CEGUITreeItem.h 2009-06-29 13:17:18 UTC (rev 2069) +++ cegui_mk2/trunk/cegui/include/elements/CEGUITreeItem.h 2009-06-29 17:44:26 UTC (rev 2070) @@ -31,6 +31,7 @@ #include "CEGUIBase.h" #include "CEGUIString.h" #include "CEGUIColourRect.h" +#include "CEGUIBasicRenderedStringParser.h" #if defined(_MSC_VER) # pragma warning(push) @@ -121,8 +122,7 @@ \return Nothing */ - void setFont(Font* font) - { d_font = font; } + void setFont(Font* font); /*! \brief @@ -634,6 +634,9 @@ */ colour calculateModulatedAlphaColour(colour col, float alpha) const; + //! parse the text visual string into a RenderString representation. + void parseTextString() const; + /************************************************************************* Implementation Data *************************************************************************/ @@ -674,6 +677,12 @@ LBItemList d_listItems; //! true if the this item's tree branch is opened. bool d_isOpen; + //! Parser used to produce a final RenderedString from the standard String. + static BasicRenderedStringParser d_stringParser; + //! RenderedString drawn by this item. + mutable RenderedString d_renderedString; + //! boolean used to track when item state changes (and needs re-parse) + mutable bool d_renderedStringValid; }; } // End of CEGUI namespace section Modified: cegui_mk2/trunk/cegui/src/elements/CEGUITreeItem.cpp =================================================================== --- cegui_mk2/trunk/cegui/src/elements/CEGUITreeItem.cpp 2009-06-29 13:17:18 UTC (rev 2069) +++ cegui_mk2/trunk/cegui/src/elements/CEGUITreeItem.cpp 2009-06-29 17:44:26 UTC (rev 2070) @@ -40,6 +40,9 @@ // Start of CEGUI namespace section namespace CEGUI { +//----------------------------------------------------------------------------// +BasicRenderedStringParser TreeItem::d_stringParser; + /************************************************************************* Constants *************************************************************************/ @@ -65,7 +68,8 @@ DefaultTextColour, DefaultTextColour), d_font(0), d_iconImage(0), - d_isOpen(false) + d_isOpen(false), + d_renderedStringValid(false) { setText(text); } @@ -132,23 +136,30 @@ setFont(FontManager::getSingleton().getFont(font_name)); } +//----------------------------------------------------------------------------// +void TreeItem::setFont(Font* font) +{ + d_font = font; + d_renderedStringValid = false; +} + +//----------------------------------------------------------------------------// + /************************************************************************* Return the rendered pixel size of this tree item. *************************************************************************/ Size TreeItem::getPixelSize(void) const { - Size tmp(0,0); - Font* fnt = getFont(); - - if (fnt != 0) - { - tmp.d_height = PixelAligned(fnt->getLineSpacing()); - tmp.d_width = PixelAligned(fnt->getTextExtent(getText())); - } - - return tmp; + + if (!fnt) + return Size(0, 0); + + if (!d_renderedStringValid) + parseTextString(); + + return d_renderedString.getPixelSize(); } /************************************************************************* @@ -226,7 +237,7 @@ float alpha, const Rect *clipper) const { Rect finalRect(targetRect); - + if (d_iconImage != 0) { // Size iconSize = d_iconImage->getSize(); @@ -248,8 +259,13 @@ { Rect finalPos(finalRect); finalPos.d_top -= (font->getLineSpacing() - font->getBaseline()) * 0.5f; - font->drawText(buffer, getTextVisual(), finalPos, clipper, LeftAligned, - getModulateAlphaColourRect(d_textCols, alpha)); + + if (!d_renderedStringValid) + parseTextString(); + + d_renderedString.draw(buffer, finalPos.getPosition(), + &getModulateAlphaColourRect(ColourRect(0xFFFFFFFF), + alpha), clipper); } } @@ -279,8 +295,11 @@ d_textCols.d_top_right = top_right_colour; d_textCols.d_bottom_left = bottom_left_colour; d_textCols.d_bottom_right = bottom_right_colour; + + d_renderedStringValid = false; } +//----------------------------------------------------------------------------// void TreeItem::setText( const String& text ) { d_textLogical = text; @@ -289,4 +308,16 @@ #endif } + +//----------------------------------------------------------------------------// +void TreeItem::parseTextString() const +{ + d_stringParser.setInitialFontName(getFont()->getProperty("Name")); + d_stringParser.setInitialColours(d_textCols); + d_renderedString = d_stringParser.parse(getTextVisual()); + d_renderedStringValid = true; +} + +//----------------------------------------------------------------------------// + } // End of CEGUI namespace section This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |