00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "falagard/CEGUIFalTextComponent.h"
00025 #include "falagard/CEGUIFalXMLEnumHelper.h"
00026 #include "CEGUIFontManager.h"
00027 #include "CEGUIExceptions.h"
00028 #include "CEGUIPropertyHelper.h"
00029 #include <iostream>
00030
00031
00032 namespace CEGUI
00033 {
00034 TextComponent::TextComponent() :
00035 d_vertFormatting(VTF_TOP_ALIGNED),
00036 d_horzFormatting(HTF_LEFT_ALIGNED)
00037 {}
00038
00039 const String& TextComponent::getText() const
00040 {
00041 return d_text;
00042 }
00043
00044 void TextComponent::setText(const String& text)
00045 {
00046 d_text = text;
00047 }
00048
00049 const String& TextComponent::getFont() const
00050 {
00051 return d_font;
00052 }
00053
00054 void TextComponent::setFont(const String& font)
00055 {
00056 d_font = font;
00057 }
00058
00059 VerticalTextFormatting TextComponent::getVerticalFormatting() const
00060 {
00061 return d_vertFormatting;
00062 }
00063
00064 void TextComponent::setVerticalFormatting(VerticalTextFormatting fmt)
00065 {
00066 d_vertFormatting = fmt;
00067 }
00068
00069 HorizontalTextFormatting TextComponent::getHorizontalFormatting() const
00070 {
00071 return d_horzFormatting;
00072 }
00073
00074 void TextComponent::setHorizontalFormatting(HorizontalTextFormatting fmt)
00075 {
00076 d_horzFormatting = fmt;
00077 }
00078
00079 void TextComponent::render_impl(Window& srcWindow, Rect& destRect, float base_z, const CEGUI::ColourRect* modColours, const Rect* clipper, bool clipToDisplay) const
00080 {
00081
00082 const Font* font;
00083
00084 try
00085 {
00086 font = d_font.empty() ? srcWindow.getFont() : FontManager::getSingleton().getFont(d_font);
00087 }
00088 catch (UnknownObjectException)
00089 {
00090 font = 0;
00091 }
00092
00093
00094 if (!font)
00095 return;
00096
00097 HorizontalTextFormatting horzFormatting = d_horzFormatPropertyName.empty() ? d_horzFormatting :
00098 FalagardXMLHelper::stringToHorzTextFormat(srcWindow.getProperty(d_horzFormatPropertyName));
00099
00100 VerticalTextFormatting vertFormatting = d_vertFormatPropertyName.empty() ? d_vertFormatting :
00101 FalagardXMLHelper::stringToVertTextFormat(srcWindow.getProperty(d_vertFormatPropertyName));
00102
00103
00104 ColourRect finalColours;
00105 initColoursRect(srcWindow, modColours, finalColours);
00106
00107
00108 const String& renderString = d_text.empty() ? srcWindow.getText() : d_text;
00109
00110
00111 float textHeight = font->getFormattedLineCount(renderString, destRect, (TextFormatting)horzFormatting) * font->getLineSpacing();
00112
00113
00114 switch(vertFormatting)
00115 {
00116 case VTF_CENTRE_ALIGNED:
00117 destRect.d_top += (destRect.getHeight() - textHeight) * 0.5f;
00118 break;
00119
00120 case VTF_BOTTOM_ALIGNED:
00121 destRect.d_top = destRect.d_bottom - textHeight;
00122 break;
00123
00124 default:
00125
00126 break;
00127 }
00128
00129
00130 srcWindow.getRenderCache().cacheText(renderString, font, (TextFormatting)horzFormatting, destRect, base_z, finalColours, clipper, clipToDisplay);
00131 }
00132
00133 void TextComponent::writeXMLToStream(OutStream& out_stream) const
00134 {
00135
00136 out_stream << "<TextComponent>" << std::endl;
00137
00138 d_area.writeXMLToStream(out_stream);
00139
00140
00141 out_stream << "<Text font=\"" << d_font << "\" string=\"" << d_text << "\" />" << std::endl;
00142
00143
00144 writeColoursXML(out_stream);
00145
00146
00147 if (!writeVertFormatXML(out_stream))
00148 {
00149
00150 out_stream << "<VertFormat type=\"" << FalagardXMLHelper::vertTextFormatToString(d_vertFormatting) << "\" />" << std::endl;
00151 }
00152
00153
00154 if (!writeHorzFormatXML(out_stream))
00155 {
00156
00157 out_stream << "<HorzFormat type=\"" << FalagardXMLHelper::horzTextFormatToString(d_horzFormatting) << "\" />" << std::endl;
00158 }
00159
00160
00161 out_stream << "</TextComponent>" << std::endl;
00162 }
00163
00164 }