//----------------------------------------------------------------------------// Size FormattedListboxTextItem::getPixelSize(void) const { if (!d_owner) return Size(0, 0); // reparse text if we need to. if (!d_renderedStringValid) parseTextString(); // create formatter if needed if (!d_formattedRenderedString) setupStringFormatter(); // get size of render area from target window, to see if we need to reformat const Size area_sz(static_cast<const Listbox*>(d_owner)-> getListRenderArea().getSize()); if (area_sz != d_formattingAreaSize) { d_formattedRenderedString->format(area_sz); d_formattingAreaSize = area_sz; } return Size(d_formattedRenderedString->getHorizontalExtent(), d_formattedRenderedString->getVerticalExtent()); }
//----------------------------------------------------------------------------// void FormattedListboxTextItem::draw(GeometryBuffer& buffer, const Rect& targetRect, float alpha, const Rect* clipper) const { // reparse text if we need to. if (!d_renderedStringValid) parseTextString(); // create formatter if needed if (!d_formattedRenderedString) setupStringFormatter(); // get size of render area from target window, to see if we need to reformat // NB: We do not use targetRect, since it may not represent the same area. const Size area_sz(static_cast<const Listbox*>(d_owner)-> getListRenderArea().getSize()); if (area_sz != d_formattingAreaSize) { d_formattedRenderedString->format(area_sz); d_formattingAreaSize = area_sz; } // draw selection imagery if (d_selected && d_selectBrush != 0) d_selectBrush->draw(buffer, targetRect, clipper, getModulateAlphaColourRect(d_selectCols, alpha)); // factor the window alpha into our colours. const ColourRect final_colours( getModulateAlphaColourRect(ColourRect(0xFFFFFFFF), alpha)); // draw the formatted text d_formattedRenderedString->draw(buffer, targetRect.getPosition(), &final_colours, clipper); }
//----------------------------------------------------------------------------// void FormattedListboxTextItem::updateString() const { bool StringChanged = !d_renderedStringValid; if (StringChanged) parseTextString(); if (!d_formattedRenderedString) setupStringFormatter(); else if (StringChanged) d_formattedRenderedString->setRenderedString(d_renderedString); // get size of render area from target window, to see if we need to reformat // NB: We do not use targetRect, since it may not represent the same area. const Size area_sz(static_cast<const Listbox*>(d_owner)->getListRenderArea().getSize()); if (StringChanged || area_sz != d_formattingAreaSize) { d_formattedRenderedString->format(area_sz); d_formattingAreaSize = area_sz; } }
//------------------------------------------------------------------------// void TextComponent::updateFormatting( const Window& srcWindow, const Sizef& size) const { const Font* font = getFontObject(srcWindow); // exit if we have no font to use. if (!font) throw InvalidRequestException("Window doesn't have a font."); const RenderedString* rs = &d_renderedString; // do we fetch text from a property if (!d_textPropertyName.empty()) { // fetch text & do bi-directional reordering as needed String vis; #ifdef CEGUI_BIDI_SUPPORT BidiVisualMapping::StrIndexList l2v, v2l; d_bidiVisualMapping->reorderFromLogicalToVisual( srcWindow.getProperty(d_textPropertyName), vis, l2v, v2l); #else vis = srcWindow.getProperty(d_textPropertyName); #endif // parse string using parser from Window. d_renderedString = srcWindow.getRenderedStringParser().parse(vis, font, 0); } // do we use a static text string from the looknfeel else if (!getTextVisual().empty()) // parse string using parser from Window. d_renderedString = srcWindow.getRenderedStringParser(). parse(getTextVisual(), font, 0); // do we have to override the font? else if (font != srcWindow.getFont()) d_renderedString = srcWindow.getRenderedStringParser(). parse(srcWindow.getTextVisual(), font, 0); // use ready-made RenderedString from the Window itself else rs = &srcWindow.getRenderedString(); setupStringFormatter(srcWindow, *rs); d_formattedRenderedString->format(&srcWindow, size); }