Commit caac1b45 authored by cutealien's avatar cutealien

- Add getActiveFont to all elements which have setOverrideFont for cleaner code

- Add getOverrideFont to all elements which have setOverrideFont to have a consistent interface


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3861 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f5a2be6e
Changes in 1.8 (??.??.2011) Changes in 1.8 (??.??.2011)
- Add getActiveFont to all elements which have setOverrideFont for cleaner code
- Add getOverrideFont to all elements which have setOverrideFont to have a consistent interface
- IGUIEditBox: added missing serialization for Border - IGUIEditBox: added missing serialization for Border
- IGUIEditBox: remove bug that added spaces to the end of each line - IGUIEditBox: remove bug that added spaces to the end of each line
......
...@@ -65,6 +65,15 @@ namespace gui ...@@ -65,6 +65,15 @@ namespace gui
\param font: New font to set. */ \param font: New font to set. */
virtual void setOverrideFont(IGUIFont* font=0) = 0; virtual void setOverrideFont(IGUIFont* font=0) = 0;
//! Gets the override font (if any)
/** \return The override font (may be 0) */
virtual IGUIFont* getOverrideFont(void) const = 0;
//! Get the font which is used right now for drawing
/** Currently this is the override font when one is set and the
font of the active skin otherwise */
virtual IGUIFont* getActiveFont() const = 0;
//! Sets an image which should be displayed on the button when it is in normal state. //! Sets an image which should be displayed on the button when it is in normal state.
/** \param image: Image to be displayed */ /** \param image: Image to be displayed */
virtual void setImage(video::ITexture* image=0) = 0; virtual void setImage(video::ITexture* image=0) = 0;
......
...@@ -28,6 +28,15 @@ namespace gui ...@@ -28,6 +28,15 @@ namespace gui
\param font: New font to set. */ \param font: New font to set. */
virtual void setOverrideFont(IGUIFont* font=0) = 0; virtual void setOverrideFont(IGUIFont* font=0) = 0;
//! Gets the override font (if any)
/** \return The override font (may be 0) */
virtual IGUIFont* getOverrideFont() const = 0;
//! Get the font which is used right now for drawing
/** Currently this is the override font when one is set and the
font of the active skin otherwise */
virtual IGUIFont* getActiveFont() const = 0;
//! Sets another color for the text. //! Sets another color for the text.
/** If set, the edit box does not use the EGDC_BUTTON_TEXT color defined /** If set, the edit box does not use the EGDC_BUTTON_TEXT color defined
in the skin, but the set color instead. You don't need to call in the skin, but the set color instead. You don't need to call
......
...@@ -32,6 +32,11 @@ namespace gui ...@@ -32,6 +32,11 @@ namespace gui
/** \return The override font (may be 0) */ /** \return The override font (may be 0) */
virtual IGUIFont* getOverrideFont(void) const = 0; virtual IGUIFont* getOverrideFont(void) const = 0;
//! Get the font which is used right now for drawing
/** Currently this is the override font when one is set and the
font of the active skin otherwise */
virtual IGUIFont* getActiveFont() const = 0;
//! Sets another color for the text. //! Sets another color for the text.
/** If set, the static text does not use the EGDC_BUTTON_TEXT color defined /** If set, the static text does not use the EGDC_BUTTON_TEXT color defined
in the skin, but the set color instead. You don't need to call in the skin, but the set color instead. You don't need to call
...@@ -91,10 +96,10 @@ namespace gui ...@@ -91,10 +96,10 @@ namespace gui
/** If the text is broken, this returns the width of the widest line /** If the text is broken, this returns the width of the widest line
\return The width of the text, or the widest broken line. */ \return The width of the text, or the widest broken line. */
virtual s32 getTextWidth(void) const = 0; virtual s32 getTextWidth(void) const = 0;
//! Set whether the text in this label should be clipped if it goes outside bounds //! Set whether the text in this label should be clipped if it goes outside bounds
virtual void setTextRestrainedInside(bool restrainedInside) = 0; virtual void setTextRestrainedInside(bool restrainedInside) = 0;
//! Checks if the text in this label should be clipped if it goes outside bounds //! Checks if the text in this label should be clipped if it goes outside bounds
virtual bool isTextRestrainedInside() const = 0; virtual bool isTextRestrainedInside() const = 0;
......
...@@ -287,9 +287,7 @@ void CGUIButton::draw() ...@@ -287,9 +287,7 @@ void CGUIButton::draw()
if (Text.size()) if (Text.size())
{ {
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
if (!OverrideFont)
font = skin->getFont(EGDF_BUTTON);
core::rect<s32> rect = AbsoluteRect; core::rect<s32> rect = AbsoluteRect;
if (Pressed) if (Pressed)
...@@ -320,6 +318,22 @@ void CGUIButton::setOverrideFont(IGUIFont* font) ...@@ -320,6 +318,22 @@ void CGUIButton::setOverrideFont(IGUIFont* font)
OverrideFont->grab(); OverrideFont->grab();
} }
//! Gets the override font (if any)
IGUIFont * CGUIButton::getOverrideFont() const
{
return OverrideFont;
}
//! Get the font which is used right now for drawing
IGUIFont* CGUIButton::getActiveFont() const
{
if ( OverrideFont )
return OverrideFont;
IGUISkin* skin = Environment->getSkin();
if (skin)
return skin->getFont();
return 0;
}
//! Sets an image which should be displayed on the button when it is in normal state. //! Sets an image which should be displayed on the button when it is in normal state.
void CGUIButton::setImage(video::ITexture* image) void CGUIButton::setImage(video::ITexture* image)
......
...@@ -37,6 +37,12 @@ namespace gui ...@@ -37,6 +37,12 @@ namespace gui
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin. //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0); virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state. //! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0); virtual void setImage(video::ITexture* image=0);
......
...@@ -100,6 +100,22 @@ void CGUIEditBox::setOverrideFont(IGUIFont* font) ...@@ -100,6 +100,22 @@ void CGUIEditBox::setOverrideFont(IGUIFont* font)
breakText(); breakText();
} }
//! Gets the override font (if any)
IGUIFont * CGUIEditBox::getOverrideFont() const
{
return OverrideFont;
}
//! Get the font which is used right now for drawing
IGUIFont* CGUIEditBox::getActiveFont() const
{
if ( OverrideFont )
return OverrideFont;
IGUISkin* skin = Environment->getSkin();
if (skin)
return skin->getFont();
return 0;
}
//! Sets another color for the text. //! Sets another color for the text.
void CGUIEditBox::setOverrideColor(video::SColor color) void CGUIEditBox::setOverrideColor(video::SColor color)
...@@ -733,9 +749,7 @@ void CGUIEditBox::draw() ...@@ -733,9 +749,7 @@ void CGUIEditBox::draw()
// draw the text // draw the text
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
if (!OverrideFont)
font = skin->getFont();
s32 cursorLine = 0; s32 cursorLine = 0;
s32 charcursorpos = 0; s32 charcursorpos = 0;
...@@ -1033,10 +1047,7 @@ bool CGUIEditBox::processMouse(const SEvent& event) ...@@ -1033,10 +1047,7 @@ bool CGUIEditBox::processMouse(const SEvent& event)
s32 CGUIEditBox::getCursorPos(s32 x, s32 y) s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
{ {
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
IGUISkin* skin = Environment->getSkin();
if (!OverrideFont)
font = skin->getFont();
const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1; const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
...@@ -1082,18 +1093,13 @@ s32 CGUIEditBox::getCursorPos(s32 x, s32 y) ...@@ -1082,18 +1093,13 @@ s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
//! Breaks the single text line. //! Breaks the single text line.
void CGUIEditBox::breakText() void CGUIEditBox::breakText()
{ {
IGUISkin* skin = Environment->getSkin(); if ((!WordWrap && !MultiLine))
if ((!WordWrap && !MultiLine) || !skin)
return; return;
BrokenText.clear(); // need to reallocate :/ BrokenText.clear(); // need to reallocate :/
BrokenTextPositions.set_used(0); BrokenTextPositions.set_used(0);
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
if (!OverrideFont)
font = skin->getFont();
if (!font) if (!font)
return; return;
...@@ -1198,12 +1204,7 @@ void CGUIEditBox::setTextRect(s32 line) ...@@ -1198,12 +1204,7 @@ void CGUIEditBox::setTextRect(s32 line)
if ( line < 0 ) if ( line < 0 )
return; return;
IGUISkin* skin = Environment->getSkin(); IGUIFont* font = getActiveFont();
if (!skin)
return;
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
if (!font) if (!font)
return; return;
...@@ -1344,10 +1345,7 @@ void CGUIEditBox::calculateScrollPos() ...@@ -1344,10 +1345,7 @@ void CGUIEditBox::calculateScrollPos()
if (!WordWrap) if (!WordWrap)
{ {
// get cursor position // get cursor position
IGUISkin* skin = Environment->getSkin(); IGUIFont* font = getActiveFont();
if (!skin)
return;
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
if (!font) if (!font)
return; return;
......
...@@ -30,6 +30,15 @@ namespace gui ...@@ -30,6 +30,15 @@ namespace gui
//! Sets another skin independent font. //! Sets another skin independent font.
virtual void setOverrideFont(IGUIFont* font=0); virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
/** \return The override font (may be 0) */
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
/** Currently this is the override font when one is set and the
font of the active skin otherwise */
virtual IGUIFont* getActiveFont() const;
//! Sets another color for the text. //! Sets another color for the text.
virtual void setOverrideColor(video::SColor color); virtual void setOverrideColor(video::SColor color);
......
...@@ -82,9 +82,7 @@ void CGUIStaticText::draw() ...@@ -82,9 +82,7 @@ void CGUIStaticText::draw()
// draw the text // draw the text
if (Text.size()) if (Text.size())
{ {
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
if (!OverrideFont)
font = skin->getFont();
if (font) if (font)
{ {
...@@ -162,12 +160,22 @@ void CGUIStaticText::setOverrideFont(IGUIFont* font) ...@@ -162,12 +160,22 @@ void CGUIStaticText::setOverrideFont(IGUIFont* font)
breakText(); breakText();
} }
//! Gets the override font (if any)
IGUIFont * CGUIStaticText::getOverrideFont() const IGUIFont * CGUIStaticText::getOverrideFont() const
{ {
return OverrideFont; return OverrideFont;
} }
//! Get the font which is used right now for drawing
IGUIFont* CGUIStaticText::getActiveFont() const
{
if ( OverrideFont )
return OverrideFont;
IGUISkin* skin = Environment->getSkin();
if (skin)
return skin->getFont();
return 0;
}
//! Sets another color for the text. //! Sets another color for the text.
void CGUIStaticText::setOverrideColor(video::SColor color) void CGUIStaticText::setOverrideColor(video::SColor color)
...@@ -275,17 +283,12 @@ bool CGUIStaticText::isRightToLeft() const ...@@ -275,17 +283,12 @@ bool CGUIStaticText::isRightToLeft() const
//! Breaks the single text line. //! Breaks the single text line.
void CGUIStaticText::breakText() void CGUIStaticText::breakText()
{ {
IGUISkin* skin = Environment->getSkin(); if (!WordWrap)
if (!WordWrap || !skin)
return; return;
BrokenText.clear(); BrokenText.clear();
IGUIFont* font = OverrideFont; IGUIFont* font = getActiveFont();
if (!OverrideFont)
font = skin->getFont();
if (!font) if (!font)
return; return;
...@@ -512,15 +515,7 @@ void CGUIStaticText::updateAbsolutePosition() ...@@ -512,15 +515,7 @@ void CGUIStaticText::updateAbsolutePosition()
//! Returns the height of the text in pixels when it is drawn. //! Returns the height of the text in pixels when it is drawn.
s32 CGUIStaticText::getTextHeight() const s32 CGUIStaticText::getTextHeight() const
{ {
IGUISkin* skin = Environment->getSkin(); IGUIFont* font = getActiveFont();
if (!skin)
return 0;
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
if (!font) if (!font)
return 0; return 0;
...@@ -535,15 +530,7 @@ s32 CGUIStaticText::getTextHeight() const ...@@ -535,15 +530,7 @@ s32 CGUIStaticText::getTextHeight() const
s32 CGUIStaticText::getTextWidth() const s32 CGUIStaticText::getTextWidth() const
{ {
IGUIFont * font = OverrideFont; IGUIFont * font = getActiveFont();
if(!OverrideFont)
{
IGUISkin * skin = Environment->getSkin();
if(skin)
font = skin->getFont();
}
if(!font) if(!font)
return 0; return 0;
......
...@@ -34,7 +34,10 @@ namespace gui ...@@ -34,7 +34,10 @@ namespace gui
virtual void setOverrideFont(IGUIFont* font=0); virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any) //! Gets the override font (if any)
virtual IGUIFont * getOverrideFont() const; virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets another color for the text. //! Sets another color for the text.
virtual void setOverrideColor(video::SColor color); virtual void setOverrideColor(video::SColor color);
...@@ -63,7 +66,7 @@ namespace gui ...@@ -63,7 +66,7 @@ namespace gui
//! Set whether the text in this label should be clipped if it goes outside bounds //! Set whether the text in this label should be clipped if it goes outside bounds
virtual void setTextRestrainedInside(bool restrainedInside); virtual void setTextRestrainedInside(bool restrainedInside);
//! Checks if the text in this label should be clipped if it goes outside bounds //! Checks if the text in this label should be clipped if it goes outside bounds
virtual bool isTextRestrainedInside() const; virtual bool isTextRestrainedInside() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment