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)
- 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: remove bug that added spaces to the end of each line
......
......@@ -65,6 +65,15 @@ namespace gui
\param font: New font to set. */
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.
/** \param image: Image to be displayed */
virtual void setImage(video::ITexture* image=0) = 0;
......
......@@ -28,6 +28,15 @@ namespace gui
\param font: New font to set. */
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.
/** 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
......
......@@ -32,6 +32,11 @@ namespace gui
/** \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 another color for the text.
/** 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
......@@ -91,10 +96,10 @@ namespace gui
/** If the text is broken, this returns the width of the widest line
\return The width of the text, or the widest broken line. */
virtual s32 getTextWidth(void) const = 0;
//! Set whether the text in this label should be clipped if it goes outside bounds
virtual void setTextRestrainedInside(bool restrainedInside) = 0;
//! Checks if the text in this label should be clipped if it goes outside bounds
virtual bool isTextRestrainedInside() const = 0;
......
......@@ -287,9 +287,7 @@ void CGUIButton::draw()
if (Text.size())
{
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont(EGDF_BUTTON);
IGUIFont* font = getActiveFont();
core::rect<s32> rect = AbsoluteRect;
if (Pressed)
......@@ -320,6 +318,22 @@ void CGUIButton::setOverrideFont(IGUIFont* font)
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.
void CGUIButton::setImage(video::ITexture* image)
......
......@@ -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.
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.
virtual void setImage(video::ITexture* image=0);
......
......@@ -100,6 +100,22 @@ void CGUIEditBox::setOverrideFont(IGUIFont* font)
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.
void CGUIEditBox::setOverrideColor(video::SColor color)
......@@ -733,9 +749,7 @@ void CGUIEditBox::draw()
// draw the text
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
s32 cursorLine = 0;
s32 charcursorpos = 0;
......@@ -1033,10 +1047,7 @@ bool CGUIEditBox::processMouse(const SEvent& event)
s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
{
IGUIFont* font = OverrideFont;
IGUISkin* skin = Environment->getSkin();
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
const u32 lineCount = (WordWrap || MultiLine) ? BrokenText.size() : 1;
......@@ -1082,18 +1093,13 @@ s32 CGUIEditBox::getCursorPos(s32 x, s32 y)
//! Breaks the single text line.
void CGUIEditBox::breakText()
{
IGUISkin* skin = Environment->getSkin();
if ((!WordWrap && !MultiLine) || !skin)
if ((!WordWrap && !MultiLine))
return;
BrokenText.clear(); // need to reallocate :/
BrokenTextPositions.set_used(0);
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
......@@ -1198,12 +1204,7 @@ void CGUIEditBox::setTextRect(s32 line)
if ( line < 0 )
return;
IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
......@@ -1344,10 +1345,7 @@ void CGUIEditBox::calculateScrollPos()
if (!WordWrap)
{
// get cursor position
IGUISkin* skin = Environment->getSkin();
if (!skin)
return;
IGUIFont* font = OverrideFont ? OverrideFont : skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
......
......@@ -30,6 +30,15 @@ namespace gui
//! Sets another skin independent font.
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.
virtual void setOverrideColor(video::SColor color);
......
......@@ -82,9 +82,7 @@ void CGUIStaticText::draw()
// draw the text
if (Text.size())
{
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
if (font)
{
......@@ -162,12 +160,22 @@ void CGUIStaticText::setOverrideFont(IGUIFont* font)
breakText();
}
//! Gets the override font (if any)
IGUIFont * CGUIStaticText::getOverrideFont() const
{
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.
void CGUIStaticText::setOverrideColor(video::SColor color)
......@@ -275,17 +283,12 @@ bool CGUIStaticText::isRightToLeft() const
//! Breaks the single text line.
void CGUIStaticText::breakText()
{
IGUISkin* skin = Environment->getSkin();
if (!WordWrap || !skin)
if (!WordWrap)
return;
BrokenText.clear();
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return;
......@@ -512,15 +515,7 @@ void CGUIStaticText::updateAbsolutePosition()
//! Returns the height of the text in pixels when it is drawn.
s32 CGUIStaticText::getTextHeight() const
{
IGUISkin* skin = Environment->getSkin();
if (!skin)
return 0;
IGUIFont* font = OverrideFont;
if (!OverrideFont)
font = skin->getFont();
IGUIFont* font = getActiveFont();
if (!font)
return 0;
......@@ -535,15 +530,7 @@ s32 CGUIStaticText::getTextHeight() const
s32 CGUIStaticText::getTextWidth() const
{
IGUIFont * font = OverrideFont;
if(!OverrideFont)
{
IGUISkin * skin = Environment->getSkin();
if(skin)
font = skin->getFont();
}
IGUIFont * font = getActiveFont();
if(!font)
return 0;
......
......@@ -34,7 +34,10 @@ namespace gui
virtual void setOverrideFont(IGUIFont* font=0);
//! 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.
virtual void setOverrideColor(video::SColor color);
......@@ -63,7 +66,7 @@ namespace gui
//! Set whether the text in this label should be clipped if it goes outside bounds
virtual void setTextRestrainedInside(bool restrainedInside);
//! Checks if the text in this label should be clipped if it goes outside bounds
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