CGUIStaticText.h 4.4 KB

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