1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __C_GUI_STATIC_TEXT_H_INCLUDED__
6 #define __C_GUI_STATIC_TEXT_H_INCLUDED__
7 
8 #include "IrrCompileConfig.h"
9 #ifdef _IRR_COMPILE_WITH_GUI_
10 
11 #include "IGUIStaticText.h"
12 #include "irrArray.h"
13 #include "GlyphLayout.h"
14 
15 namespace irr
16 {
17 namespace gui
18 {
19 	class CGUIStaticText : public IGUIStaticText
20 	{
21 	public:
22 
23 		//! constructor
24 		CGUIStaticText(const core::stringw& text, bool border, IGUIEnvironment* environment,
25 			IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
26 			bool background = false);
27 
28 		//! destructor
29 		virtual ~CGUIStaticText();
30 
31 		//! draws the element and its children
32 		virtual void draw();
33 
34 		//! Sets another skin independent font.
35 		virtual void setOverrideFont(IGUIFont* font=0);
36 
37 		//! Gets the override font (if any)
38 		virtual IGUIFont* getOverrideFont() const;
39 
40 		//! Get the font which is used right now for drawing
41 		virtual IGUIFont* getActiveFont() const;
42 
43 		//! Sets another color for the text.
44 		virtual void setOverrideColor(video::SColor color);
45 
46 		//! Sets another color for the background.
47 		virtual void setBackgroundColor(video::SColor color);
48 
49 		//! Sets whether to draw the background
50 		virtual void setDrawBackground(bool draw);
51 
52 		//! Gets the background color
53 		virtual video::SColor getBackgroundColor() const;
54 
55 		//! Checks if background drawing is enabled
56 		virtual bool isDrawBackgroundEnabled() const;
57 
58 		//! Sets whether to draw the border
59 		virtual void setDrawBorder(bool draw);
60 
61 		//! Checks if border drawing is enabled
62 		virtual bool isDrawBorderEnabled() const;
63 
64 		//! Sets alignment mode for text
65 		virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
66 
67 		//! Gets the override color
68 		virtual video::SColor getOverrideColor() const;
69 
70 		//! Sets if the static text should use the overide color or the
71 		//! color in the gui skin.
72 		virtual void enableOverrideColor(bool enable);
73 
74 		//! Checks if an override color is enabled
75 		virtual bool isOverrideColorEnabled() const;
76 
77 		//! Set whether the text in this label should be clipped if it goes outside bounds
78 		virtual void setTextRestrainedInside(bool restrainedInside);
79 
80 		//! Checks if the text in this label should be clipped if it goes outside bounds
81 		virtual bool isTextRestrainedInside() const;
82 
83 		//! Enables or disables word wrap for using the static text as
84 		//! multiline text control.
85 		virtual void setWordWrap(bool enable);
86 
87 		//! Checks if word wrap is enabled
88 		virtual bool isWordWrapEnabled() const;
89 
90 		//! Sets the new caption of this element.
91 		virtual void setText(const core::stringw& text);
92 
93 		//! Returns the height of the text in pixels when it is drawn.
94 		virtual s32 getTextHeight() const;
95 
96 		//! Returns the width of the current text, in the current font
97 		virtual s32 getTextWidth() const;
98 
99 		//! Updates the absolute position, splits text if word wrap is enabled
100 		virtual void updateAbsolutePosition();
101 
102 		//! Writes attributes of the element.
103 		virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
104 
105 		//! Reads attributes of the element
106 		virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
107 
getGlyphLayouts()108 		virtual const std::vector<GlyphLayout>& getGlyphLayouts() const { return m_glyph_layouts; }
setGlyphLayouts(std::vector<GlyphLayout> & gls)109 		virtual void setGlyphLayouts(std::vector<GlyphLayout>& gls) { m_glyph_layouts = gls; }
clearGlyphLayouts()110 		virtual void clearGlyphLayouts() { m_glyph_layouts.clear(); }
setUseGlyphLayoutsOnly(bool gls_only)111 		virtual void setUseGlyphLayoutsOnly(bool gls_only) { m_use_glyph_layouts_only = gls_only; }
useGlyphLayoutsOnly()112 		virtual bool useGlyphLayoutsOnly() const { return m_use_glyph_layouts_only; }
113 
114 	private:
115 
116 		//! Breaks the single text line.
117 		void breakText();
118 
119 		EGUI_ALIGNMENT HAlign, VAlign;
120 		bool Border;
121 		bool OverrideColorEnabled;
122 		bool OverrideBGColorEnabled;
123 		bool WordWrap;
124 		bool Background;
125 		bool RestrainTextInside;
126 
127 		video::SColor OverrideColor, BGColor;
128 		gui::IGUIFont* OverrideFont;
129 		gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated.
130 
131 		//! If true, setText / updating this element will not reshape with Text object
132 		bool m_use_glyph_layouts_only;
133 		std::vector<GlyphLayout> m_glyph_layouts;
134 	};
135 
136 } // end namespace gui
137 } // end namespace irr
138 
139 #endif // _IRR_COMPILE_WITH_GUI_
140 
141 #endif
142 
143