ElementTextDefault.h

00001 /*
00002  * This source file is part of libRocket, the HTML/CSS Interface Middleware
00003  *
00004  * For the latest information, see http://www.librocket.com
00005  *
00006  * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a copy
00009  * of this software and associated documentation files (the "Software"), to deal
00010  * in the Software without restriction, including without limitation the rights
00011  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012  * copies of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be included in
00016  * all copies or substantial portions of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024  * THE SOFTWARE.
00025  *
00026  */
00027 
00028 #ifndef ROCKETCOREELEMENTTEXTDEFAULT_H
00029 #define ROCKETCOREELEMENTTEXTDEFAULT_H
00030 
00031 #include <Rocket/Core/Header.h>
00032 #include <Rocket/Core/ElementText.h>
00033 #include <Rocket/Core/Geometry.h>
00034 
00035 namespace Rocket {
00036 namespace Core {
00037 
00042 class ROCKETCORE_API ElementTextDefault : public ElementText
00043 {
00044 public:
00045         ElementTextDefault(const String& tag);
00046         virtual ~ElementTextDefault();
00047 
00048         virtual void SetText(const WString& text);
00049         virtual const WString& GetText() const;
00050 
00051         virtual void OnRender();
00052 
00057         virtual bool GenerateToken(float& token_width, int token_begin);
00067         virtual bool GenerateLine(WString& line, int& line_length, float& line_width, int line_begin, float maximum_line_width, float right_spacing_width, bool trim_whitespace_prefix);
00068 
00070         virtual void ClearLines();
00074         virtual void AddLine(const Vector2f& line_position, const WString& line);
00075 
00077         virtual void SuppressAutoLayout();
00078 
00079 protected:
00080         virtual void OnPropertyChange(const PropertyNameList& properties);
00081 
00084         virtual void GetRML(String& content);
00085 
00087         virtual void DirtyFont();
00088 
00089 private:
00090         // Updates the configuration this element uses for its font, depending on which font effects
00091         // are active.
00092         bool UpdateFontConfiguration();
00093 
00094         // Used to store the position and length of each line we have geometry for.
00095         struct Line
00096         {
00097                 Line(const WString& text, const Vector2f& position) : text(text), position(position)
00098                 {
00099                         width = 0;
00100                 }
00101 
00102                 WString text;
00103                 Vector2f position;
00104                 int width;
00105         };
00106 
00107         // Clears and regenerates all of the text's geometry.
00108         void GenerateGeometry(FontFaceHandle* font_face_handle);
00109         // Generates the geometry for a single line of text.
00110         void GenerateGeometry(FontFaceHandle* font_face_handle, Line& line);
00111         // Generates any geometry necessary for rendering a line decoration (underline, strike-through, etc).
00112         void GenerateDecoration(FontFaceHandle* font_face_handle, const Line& line);
00113 
00114         WString text;
00115 
00116         typedef std::vector< Line > LineList;
00117         LineList lines;
00118 
00119         bool dirty_layout_on_change;
00120 
00121         GeometryList geometry;
00122         bool geometry_dirty;
00123 
00124         Colourb colour;
00125 
00126         // The decoration geometry we've generated for this string.
00127         Geometry decoration;
00128         // What the decoration type is that we have generated.
00129         int generated_decoration;
00130         // What the element's actual text-decoration property is; this may be different from the generated decoration
00131         // if it is set to none; this means we can keep generated decoration and simply toggle it on or off as long as
00132         // it isn't being changed.
00133         int decoration_property;
00134 
00135         int font_configuration;
00136         bool font_dirty;
00137 };
00138 
00139 }
00140 }
00141 
00142 #endif