diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-11-04 16:44:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:44:42 +0100 |
commit | 5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch) | |
tree | c980d614fec4a5495798be3e79e033229062c3cd /src/irrlicht_changes/static_text.h | |
parent | 28f6a79706b088c37268a59d90878220dc4ef9c7 (diff) | |
parent | 3af10766fd2b58b068e970266724d7eb10e9316b (diff) | |
download | dragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz |
Merge branch 'master' into master
Diffstat (limited to 'src/irrlicht_changes/static_text.h')
-rw-r--r-- | src/irrlicht_changes/static_text.h | 315 |
1 files changed, 154 insertions, 161 deletions
diff --git a/src/irrlicht_changes/static_text.h b/src/irrlicht_changes/static_text.h index 1f111ea56..5c4db3e95 100644 --- a/src/irrlicht_changes/static_text.h +++ b/src/irrlicht_changes/static_text.h @@ -28,207 +28,202 @@ namespace irr namespace gui { - const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT = (EGUI_ELEMENT_TYPE)(0x1000); +const EGUI_ELEMENT_TYPE EGUIET_ENRICHED_STATIC_TEXT = (EGUI_ELEMENT_TYPE)(0x1000); - class StaticText : public IGUIStaticText - { - public: - - // StaticText is translated by EnrichedString. - // No need to use translate_string() - StaticText(const EnrichedString &text, bool border, IGUIEnvironment* environment, - IGUIElement* parent, s32 id, const core::rect<s32>& rectangle, +class StaticText : public IGUIStaticText +{ +public: + // StaticText is translated by EnrichedString. + // No need to use translate_string() + StaticText(const EnrichedString &text, bool border, IGUIEnvironment *environment, + IGUIElement *parent, s32 id, const core::rect<s32> &rectangle, bool background = false); - //! destructor - virtual ~StaticText(); - - static irr::gui::IGUIStaticText *add( - irr::gui::IGUIEnvironment *guienv, - const EnrichedString &text, - const core::rect< s32 > &rectangle, - bool border = false, - bool wordWrap = true, - irr::gui::IGUIElement *parent = NULL, - s32 id = -1, - bool fillBackground = false) - { - if (parent == NULL) { - // parent is NULL, so we must find one, or we need not to drop - // result, but then there will be a memory leak. - // - // What Irrlicht does is to use guienv as a parent, but the problem - // is that guienv is here only an IGUIEnvironment, while it is a - // CGUIEnvironment in Irrlicht, which inherits from both IGUIElement - // and IGUIEnvironment. - // - // A solution would be to dynamic_cast guienv to a - // IGUIElement*, but Irrlicht is shipped without rtti support - // in some distributions, causing the dymanic_cast to segfault. - // - // Thus, to find the parent, we create a dummy StaticText and ask - // for its parent, and then remove it. - irr::gui::IGUIStaticText *dummy_text = - guienv->addStaticText(L"", rectangle, border, wordWrap, - parent, id, fillBackground); - parent = dummy_text->getParent(); - dummy_text->remove(); - } - irr::gui::IGUIStaticText *result = new irr::gui::StaticText( - text, border, guienv, parent, - id, rectangle, fillBackground); - - result->setWordWrap(wordWrap); - result->drop(); - return result; - } + //! destructor + virtual ~StaticText(); - static irr::gui::IGUIStaticText *add( - irr::gui::IGUIEnvironment *guienv, - const wchar_t *text, - const core::rect< s32 > &rectangle, - bool border = false, - bool wordWrap = true, - irr::gui::IGUIElement *parent = NULL, - s32 id = -1, + static irr::gui::IGUIStaticText *add(irr::gui::IGUIEnvironment *guienv, + const EnrichedString &text, const core::rect<s32> &rectangle, + bool border = false, bool wordWrap = true, + irr::gui::IGUIElement *parent = NULL, s32 id = -1, bool fillBackground = false) - { - return add(guienv, EnrichedString(text), rectangle, border, wordWrap, parent, - id, fillBackground); + { + if (parent == NULL) { + // parent is NULL, so we must find one, or we need not to drop + // result, but then there will be a memory leak. + // + // What Irrlicht does is to use guienv as a parent, but the + // problem is that guienv is here only an IGUIEnvironment, while + // it is a CGUIEnvironment in Irrlicht, which inherits from both + // IGUIElement and IGUIEnvironment. + // + // A solution would be to dynamic_cast guienv to a + // IGUIElement*, but Irrlicht is shipped without rtti support + // in some distributions, causing the dymanic_cast to segfault. + // + // Thus, to find the parent, we create a dummy StaticText and ask + // for its parent, and then remove it. + irr::gui::IGUIStaticText *dummy_text = guienv->addStaticText(L"", + rectangle, border, wordWrap, parent, id, + fillBackground); + parent = dummy_text->getParent(); + dummy_text->remove(); } + irr::gui::IGUIStaticText *result = new irr::gui::StaticText(text, border, + guienv, parent, id, rectangle, fillBackground); - //! draws the element and its children - virtual void draw(); + result->setWordWrap(wordWrap); + result->drop(); + return result; + } - //! Sets another skin independent font. - virtual void setOverrideFont(IGUIFont* font=0); + static irr::gui::IGUIStaticText *add(irr::gui::IGUIEnvironment *guienv, + const wchar_t *text, const core::rect<s32> &rectangle, + bool border = false, bool wordWrap = true, + irr::gui::IGUIElement *parent = NULL, s32 id = -1, + bool fillBackground = false) + { + return add(guienv, EnrichedString(text), rectangle, border, wordWrap, + parent, id, fillBackground); + } - //! Gets the override font (if any) - virtual IGUIFont* getOverrideFont() const; + //! draws the element and its children + virtual void draw(); - //! Get the font which is used right now for drawing - virtual IGUIFont* getActiveFont() const; + //! Sets another skin independent font. + virtual void setOverrideFont(IGUIFont *font = 0); - //! Sets another color for the text. - virtual void setOverrideColor(video::SColor color); + //! Gets the override font (if any) + virtual IGUIFont *getOverrideFont() const; - //! Sets another color for the background. - virtual void setBackgroundColor(video::SColor color); + //! Get the font which is used right now for drawing + virtual IGUIFont *getActiveFont() const; - //! Sets whether to draw the background - virtual void setDrawBackground(bool draw); + //! Sets another color for the text. + virtual void setOverrideColor(video::SColor color); - //! Gets the background color - virtual video::SColor getBackgroundColor() const; + //! Sets another color for the background. + virtual void setBackgroundColor(video::SColor color); - //! Checks if background drawing is enabled - virtual bool isDrawBackgroundEnabled() const; + //! Sets whether to draw the background + virtual void setDrawBackground(bool draw); - //! Sets whether to draw the border - virtual void setDrawBorder(bool draw); + //! Gets the background color + virtual video::SColor getBackgroundColor() const; - //! Checks if border drawing is enabled - virtual bool isDrawBorderEnabled() const; + //! Checks if background drawing is enabled + virtual bool isDrawBackgroundEnabled() const; - //! Sets alignment mode for text - virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); + //! Sets whether to draw the border + virtual void setDrawBorder(bool draw); - //! Gets the override color - #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 7 - virtual const video::SColor& getOverrideColor() const; - #else - virtual video::SColor getOverrideColor() const; - #endif + //! Checks if border drawing is enabled + virtual bool isDrawBorderEnabled() const; - //! Sets if the static text should use the overide color or the - //! color in the gui skin. - virtual void enableOverrideColor(bool enable); + //! Sets alignment mode for text + virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical); - //! Checks if an override color is enabled - virtual bool isOverrideColorEnabled() const; +//! Gets the override color +#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 7 + virtual const video::SColor &getOverrideColor() const; +#else + virtual video::SColor getOverrideColor() const; +#endif - //! Set whether the text in this label should be clipped if it goes outside bounds - virtual void setTextRestrainedInside(bool restrainedInside); + //! Sets if the static text should use the overide color or the + //! color in the gui skin. + virtual void enableOverrideColor(bool enable); - //! Checks if the text in this label should be clipped if it goes outside bounds - virtual bool isTextRestrainedInside() const; + //! Checks if an override color is enabled + virtual bool isOverrideColorEnabled() const; - //! Enables or disables word wrap for using the static text as - //! multiline text control. - virtual void setWordWrap(bool enable); + //! Set whether the text in this label should be clipped if it goes outside bounds + virtual void setTextRestrainedInside(bool restrainedInside); - //! Checks if word wrap is enabled - virtual bool isWordWrapEnabled() const; + //! Checks if the text in this label should be clipped if it goes outside bounds + virtual bool isTextRestrainedInside() const; - //! Sets the new caption of this element. - virtual void setText(const wchar_t* text); + //! Enables or disables word wrap for using the static text as + //! multiline text control. + virtual void setWordWrap(bool enable); - //! Returns the height of the text in pixels when it is drawn. - virtual s32 getTextHeight() const; + //! Checks if word wrap is enabled + virtual bool isWordWrapEnabled() const; - //! Returns the width of the current text, in the current font - virtual s32 getTextWidth() const; + //! Sets the new caption of this element. + virtual void setText(const wchar_t *text); - //! Updates the absolute position, splits text if word wrap is enabled - virtual void updateAbsolutePosition(); + //! Returns the height of the text in pixels when it is drawn. + virtual s32 getTextHeight() const; - //! Set whether the string should be interpreted as right-to-left (RTL) text - /** \note This component does not implement the Unicode bidi standard, the - text of the component should be already RTL if you call this. The - main difference when RTL is enabled is that the linebreaks for multiline - elements are performed starting from the end. - */ - virtual void setRightToLeft(bool rtl); + //! Returns the width of the current text, in the current font + virtual s32 getTextWidth() const; - //! Checks if the text should be interpreted as right-to-left text - virtual bool isRightToLeft() const; + //! Updates the absolute position, splits text if word wrap is enabled + virtual void updateAbsolutePosition(); - //! Writes attributes of the element. - virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; + //! Set whether the string should be interpreted as right-to-left (RTL) text + /** \note This component does not implement the Unicode bidi standard, the + text of the component should be already RTL if you call this. The + main difference when RTL is enabled is that the linebreaks for multiline + elements are performed starting from the end. + */ + virtual void setRightToLeft(bool rtl); - //! Reads attributes of the element - virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); + //! Checks if the text should be interpreted as right-to-left text + virtual bool isRightToLeft() const; - virtual bool hasType(EGUI_ELEMENT_TYPE t) const { - return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); - }; + //! Writes attributes of the element. + virtual void serializeAttributes(io::IAttributes *out, + io::SAttributeReadWriteOptions *options) const; - virtual bool hasType(EGUI_ELEMENT_TYPE t) { - return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); - }; + //! Reads attributes of the element + virtual void deserializeAttributes( + io::IAttributes *in, io::SAttributeReadWriteOptions *options); - void setText(const EnrichedString &text); + virtual bool hasType(EGUI_ELEMENT_TYPE t) const + { + return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); + }; - private: + virtual bool hasType(EGUI_ELEMENT_TYPE t) + { + return (t == EGUIET_ENRICHED_STATIC_TEXT) || (t == EGUIET_STATIC_TEXT); + }; - //! Breaks the single text line. - void updateText(); + void setText(const EnrichedString &text); - EGUI_ALIGNMENT HAlign, VAlign; - bool Border; - bool WordWrap; - bool Background; - bool RestrainTextInside; - bool RightToLeft; +private: + //! Breaks the single text line. + void updateText(); - gui::IGUIFont* OverrideFont; - gui::IGUIFont* LastBreakFont; // stored because: if skin changes, line break must be recalculated. + EGUI_ALIGNMENT HAlign, VAlign; + bool Border; + bool WordWrap; + bool Background; + bool RestrainTextInside; + bool RightToLeft; - EnrichedString ColoredText; - std::vector<EnrichedString> BrokenText; - }; + gui::IGUIFont *OverrideFont; + gui::IGUIFont *LastBreakFont; // stored because: if skin changes, line break must + // be recalculated. + EnrichedString ColoredText; + std::vector<EnrichedString> BrokenText; +}; } // end namespace gui } // end namespace irr -inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedString &text) +inline void setStaticText( + irr::gui::IGUIStaticText *static_text, const EnrichedString &text) { // dynamic_cast not possible due to some distributions shipped // without rtti support in irrlicht if (static_text->hasType(irr::gui::EGUIET_ENRICHED_STATIC_TEXT)) { - irr::gui::StaticText* stext = static_cast<irr::gui::StaticText*>(static_text); + irr::gui::StaticText *stext = + static_cast<irr::gui::StaticText *>(static_text); stext->setText(text); } else { static_text->setText(text.c_str()); @@ -245,17 +240,14 @@ namespace gui class StaticText { public: - static irr::gui::IGUIStaticText *add( - irr::gui::IGUIEnvironment *guienv, - const EnrichedString &text, - const core::rect< s32 > &rectangle, - bool border = false, - bool wordWrap = true, - irr::gui::IGUIElement *parent = NULL, - s32 id = -1, - bool fillBackground = false) + static irr::gui::IGUIStaticText *add(irr::gui::IGUIEnvironment *guienv, + const EnrichedString &text, const core::rect<s32> &rectangle, + bool border = false, bool wordWrap = true, + irr::gui::IGUIElement *parent = NULL, s32 id = -1, + bool fillBackground = false) { - return guienv->addStaticText(text.c_str(), rectangle, border, wordWrap, parent, id, fillBackground); + return guienv->addStaticText(text.c_str(), rectangle, border, wordWrap, + parent, id, fillBackground); } }; @@ -263,7 +255,8 @@ public: } // end namespace irr -inline void setStaticText(irr::gui::IGUIStaticText *static_text, const EnrichedString &text) +inline void setStaticText( + irr::gui::IGUIStaticText *static_text, const EnrichedString &text) { static_text->setText(text.c_str()); } |