|
| 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 | + |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +namespace irr |
| 17 | +{ |
| 18 | +namespace gui |
| 19 | +{ |
| 20 | + class StaticText : public IGUIStaticText |
| 21 | + { |
| 22 | + public: |
| 23 | + |
| 24 | + //! constructor |
| 25 | + StaticText(const wchar_t* text, bool border, IGUIEnvironment* environment, |
| 26 | + IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, |
| 27 | + bool background = false); |
| 28 | + |
| 29 | + //! destructor |
| 30 | + virtual ~StaticText(); |
| 31 | + |
| 32 | + //! draws the element and its children |
| 33 | + virtual void draw(); |
| 34 | + |
| 35 | + //! Sets another skin independent font. |
| 36 | + virtual void setOverrideFont(IGUIFont* font=0); |
| 37 | + |
| 38 | + //! Gets the override font (if any) |
| 39 | + virtual IGUIFont* getOverrideFont() const; |
| 40 | + |
| 41 | + //! Get the font which is used right now for drawing |
| 42 | + virtual IGUIFont* getActiveFont() const; |
| 43 | + |
| 44 | + //! Sets another color for the text. |
| 45 | + virtual void setOverrideColor(video::SColor color); |
| 46 | + |
| 47 | + //! Sets another color for the background. |
| 48 | + virtual void setBackgroundColor(video::SColor color); |
| 49 | + |
| 50 | + //! Sets whether to draw the background |
| 51 | + virtual void setDrawBackground(bool draw); |
| 52 | + |
| 53 | + //! Gets the background color |
| 54 | + virtual video::SColor getBackgroundColor() const; |
| 55 | + |
| 56 | + //! Checks if background drawing is enabled |
| 57 | + virtual bool isDrawBackgroundEnabled() const; |
| 58 | + |
| 59 | + //! Sets whether to draw the border |
| 60 | + virtual void setDrawBorder(bool draw); |
| 61 | + |
| 62 | + //! Checks if border drawing is enabled |
| 63 | + virtual bool isDrawBorderEnabled() const; |
| 64 | + |
| 65 | + //! Sets alignment mode for text |
| 66 | + virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); |
| 67 | + |
| 68 | + //! Gets the override color |
| 69 | + #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 7 |
| 70 | + virtual const video::SColor& getOverrideColor() const; |
| 71 | + #else |
| 72 | + virtual video::SColor getOverrideColor() const; |
| 73 | + #endif |
| 74 | + |
| 75 | + //! Sets if the static text should use the overide color or the |
| 76 | + //! color in the gui skin. |
| 77 | + virtual void enableOverrideColor(bool enable); |
| 78 | + |
| 79 | + //! Checks if an override color is enabled |
| 80 | + virtual bool isOverrideColorEnabled() const; |
| 81 | + |
| 82 | + //! Set whether the text in this label should be clipped if it goes outside bounds |
| 83 | + virtual void setTextRestrainedInside(bool restrainedInside); |
| 84 | + |
| 85 | + //! Checks if the text in this label should be clipped if it goes outside bounds |
| 86 | + virtual bool isTextRestrainedInside() const; |
| 87 | + |
| 88 | + //! Enables or disables word wrap for using the static text as |
| 89 | + //! multiline text control. |
| 90 | + virtual void setWordWrap(bool enable); |
| 91 | + |
| 92 | + //! Checks if word wrap is enabled |
| 93 | + virtual bool isWordWrapEnabled() const; |
| 94 | + |
| 95 | + //! Sets the new caption of this element. |
| 96 | + virtual void setText(const wchar_t* text); |
| 97 | + |
| 98 | + //! Returns the height of the text in pixels when it is drawn. |
| 99 | + virtual s32 getTextHeight() const; |
| 100 | + |
| 101 | + //! Returns the width of the current text, in the current font |
| 102 | + virtual s32 getTextWidth() const; |
| 103 | + |
| 104 | + //! Updates the absolute position, splits text if word wrap is enabled |
| 105 | + virtual void updateAbsolutePosition(); |
| 106 | + |
| 107 | + //! Set whether the string should be interpreted as right-to-left (RTL) text |
| 108 | + /** \note This component does not implement the Unicode bidi standard, the |
| 109 | + text of the component should be already RTL if you call this. The |
| 110 | + main difference when RTL is enabled is that the linebreaks for multiline |
| 111 | + elements are performed starting from the end. |
| 112 | + */ |
| 113 | + virtual void setRightToLeft(bool rtl); |
| 114 | + |
| 115 | + //! Checks if the text should be interpreted as right-to-left text |
| 116 | + virtual bool isRightToLeft() const; |
| 117 | + |
| 118 | + //! Writes attributes of the element. |
| 119 | + virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; |
| 120 | + |
| 121 | + //! Reads attributes of the element |
| 122 | + virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); |
| 123 | + |
| 124 | + private: |
| 125 | + |
| 126 | + //! Breaks the single text line. |
| 127 | + void breakText(); |
| 128 | + |
| 129 | + EGUI_ALIGNMENT HAlign, VAlign; |
| 130 | + bool Border; |
| 131 | + bool OverrideColorEnabled; |
| 132 | + bool OverrideBGColorEnabled; |
| 133 | + bool WordWrap; |
| 134 | + bool Background; |
| 135 | + bool RestrainTextInside; |
| 136 | + bool RightToLeft; |
| 137 | + |
| 138 | + video::SColor OverrideColor, BGColor; |
| 139 | + gui::IGUIFont* OverrideFont; |
| 140 | + gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated. |
| 141 | + |
| 142 | + core::array< core::stringw > BrokenText; |
| 143 | + }; |
| 144 | + |
| 145 | +} // end namespace gui |
| 146 | +} // end namespace irr |
| 147 | + |
| 148 | +#endif // _IRR_COMPILE_WITH_GUI_ |
| 149 | + |
| 150 | +#endif // C_GUI_STATIC_TEXT_H_INCLUDED |
0 commit comments