Commit 9736e456 authored by cutealien's avatar cutealien

- In IGUICheckBox add: setDrawBackground, isDrawBackgroundEnabled,...

- In IGUICheckBox add: setDrawBackground, isDrawBackgroundEnabled, setDrawBorder, isDrawBorderEnabled
- Some minor function re-ordering in IGUIStaticText


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4433 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 187c56cc
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Add in IGUICheckBox: setDrawBackground, isDrawBackgroundEnabled, setDrawBorder, isDrawBorderEnabled
- IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and EGET_EDITBOX_ENTER events from it's sub-elements. - IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and EGET_EDITBOX_ENTER events from it's sub-elements.
- IGUISpinBox no longer validates values after each character type but only on KEY_ENTER and when losing focus. New behavior can be set with IGUISpinBox::setValidateOn - IGUISpinBox no longer validates values after each character type but only on KEY_ENTER and when losing focus. New behavior can be set with IGUISpinBox::setValidateOn
- IAttributes::getAttributeAs functions now can have a customizable default-parameter to return when attributeName is not found - IAttributes::getAttributeAs functions now can have a customizable default-parameter to return when attributeName is not found
......
...@@ -29,6 +29,21 @@ namespace gui ...@@ -29,6 +29,21 @@ namespace gui
//! Returns true if box is checked. //! Returns true if box is checked.
virtual bool isChecked() const = 0; virtual bool isChecked() const = 0;
//! Sets whether to draw the background
virtual void setDrawBackground(bool draw) = 0;
//! Checks if background drawing is enabled
/** \return true if background drawing is enabled, false otherwise */
virtual bool isDrawBackgroundEnabled() const = 0;
//! Sets whether to draw the border
virtual void setDrawBorder(bool draw) = 0;
//! Checks if border drawing is enabled
/** \return true if border drawing is enabled, false otherwise */
virtual bool isDrawBorderEnabled() const = 0;
}; };
} // end namespace gui } // end namespace gui
......
...@@ -67,14 +67,14 @@ namespace gui ...@@ -67,14 +67,14 @@ namespace gui
//! Sets whether to draw the background //! Sets whether to draw the background
virtual void setDrawBackground(bool draw) = 0; virtual void setDrawBackground(bool draw) = 0;
//! Gets the background color
/** \return: The background color */
virtual video::SColor getBackgroundColor() const = 0;
//! Checks if background drawing is enabled //! Checks if background drawing is enabled
/** \return true if background drawing is enabled, false otherwise */ /** \return true if background drawing is enabled, false otherwise */
virtual bool isDrawBackgroundEnabled() const = 0; virtual bool isDrawBackgroundEnabled() const = 0;
//! Gets the background color
/** \return: The background color */
virtual video::SColor getBackgroundColor() const = 0;
//! Sets whether to draw the border //! Sets whether to draw the border
virtual void setDrawBorder(bool draw) = 0; virtual void setDrawBorder(bool draw) = 0;
......
...@@ -19,7 +19,8 @@ namespace gui ...@@ -19,7 +19,8 @@ namespace gui
//! constructor //! constructor
CGUICheckBox::CGUICheckBox(bool checked, IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) CGUICheckBox::CGUICheckBox(bool checked, IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUICheckBox(environment, parent, id, rectangle), checkTime(0), Pressed(false), Checked(checked) : IGUICheckBox(environment, parent, id, rectangle), CheckTime(0), Pressed(false), Checked(checked)
, Border(false), Background(false)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUICheckBox"); setDebugName("CGUICheckBox");
...@@ -80,7 +81,7 @@ bool CGUICheckBox::OnEvent(const SEvent& event) ...@@ -80,7 +81,7 @@ bool CGUICheckBox::OnEvent(const SEvent& event)
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{ {
Pressed = true; Pressed = true;
checkTime = os::Timer::getTime(); CheckTime = os::Timer::getTime();
Environment->setFocus(this); Environment->setFocus(this);
return true; return true;
} }
...@@ -129,10 +130,29 @@ void CGUICheckBox::draw() ...@@ -129,10 +130,29 @@ void CGUICheckBox::draw()
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
if (skin) if (skin)
{ {
video::IVideoDriver* driver = Environment->getVideoDriver();
core::rect<s32> frameRect(AbsoluteRect);
// draw background
if (Background)
{
video::SColor bgColor = skin->getColor(gui::EGDC_3D_FACE);
driver->draw2DRectangle(bgColor, frameRect, &AbsoluteClippingRect);
}
// draw the border
if (Border)
{
skin->draw3DSunkenPane(this, 0, true, false, frameRect, &AbsoluteClippingRect);
frameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
frameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X);
}
const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH); const s32 height = skin->getSize(EGDS_CHECK_BOX_WIDTH);
core::rect<s32> checkRect(AbsoluteRect.UpperLeftCorner.X, // the rectangle around the "checked" area.
((AbsoluteRect.getHeight() - height) / 2) + AbsoluteRect.UpperLeftCorner.Y, core::rect<s32> checkRect(frameRect.UpperLeftCorner.X,
((frameRect.getHeight() - height) / 2) + frameRect.UpperLeftCorner.Y,
0, 0); 0, 0);
checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height;
...@@ -144,14 +164,17 @@ void CGUICheckBox::draw() ...@@ -144,14 +164,17 @@ void CGUICheckBox::draw()
skin->draw3DSunkenPane(this, skin->getColor(col), skin->draw3DSunkenPane(this, skin->getColor(col),
false, true, checkRect, &AbsoluteClippingRect); false, true, checkRect, &AbsoluteClippingRect);
// the checked icon
if (Checked) if (Checked)
{ {
skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), skin->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(),
checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); CheckTime, os::Timer::getTime(), false, &AbsoluteClippingRect);
} }
// associated text
if (Text.size()) if (Text.size())
{ {
checkRect = AbsoluteRect; checkRect = frameRect;
checkRect.UpperLeftCorner.X += height + 5; checkRect.UpperLeftCorner.X += height + 5;
IGUIFont* font = skin->getFont(); IGUIFont* font = skin->getFont();
...@@ -180,12 +203,39 @@ bool CGUICheckBox::isChecked() const ...@@ -180,12 +203,39 @@ bool CGUICheckBox::isChecked() const
return Checked; return Checked;
} }
//! Sets whether to draw the background
void CGUICheckBox::setDrawBackground(bool draw)
{
Background = draw;
}
//! Checks if background drawing is enabled
bool CGUICheckBox::isDrawBackgroundEnabled() const
{
return Background;
}
//! Sets whether to draw the border
void CGUICheckBox::setDrawBorder(bool draw)
{
Border = draw;
}
//! Checks if border drawing is enabled
bool CGUICheckBox::isDrawBorderEnabled() const
{
return Border;
}
//! Writes attributes of the element. //! Writes attributes of the element.
void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
{ {
IGUICheckBox::serializeAttributes(out,options); IGUICheckBox::serializeAttributes(out,options);
out->addBool("Checked", Checked); out->addBool("Checked", Checked);
out->addBool("Border", Border);
out->addBool("Background", Background);
} }
...@@ -193,6 +243,8 @@ void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadW ...@@ -193,6 +243,8 @@ void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadW
void CGUICheckBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) void CGUICheckBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
{ {
Checked = in->getAttributeAsBool ("Checked"); Checked = in->getAttributeAsBool ("Checked");
Border = in->getAttributeAsBool ("Border", Border);
Background = in->getAttributeAsBool ("Background", Background);
IGUICheckBox::deserializeAttributes(in,options); IGUICheckBox::deserializeAttributes(in,options);
} }
......
...@@ -28,6 +28,20 @@ namespace gui ...@@ -28,6 +28,20 @@ namespace gui
//! returns if box is checked //! returns if box is checked
virtual bool isChecked() const; virtual bool isChecked() const;
//! Sets whether to draw the background
virtual void setDrawBackground(bool draw);
//! Checks if background drawing is enabled
/** \return true if background drawing is enabled, false otherwise */
virtual bool isDrawBackgroundEnabled() const;
//! Sets whether to draw the border
virtual void setDrawBorder(bool draw);
//! Checks if border drawing is enabled
/** \return true if border drawing is enabled, false otherwise */
virtual bool isDrawBorderEnabled() const;
//! called if an event happened. //! called if an event happened.
virtual bool OnEvent(const SEvent& event); virtual bool OnEvent(const SEvent& event);
...@@ -42,9 +56,11 @@ namespace gui ...@@ -42,9 +56,11 @@ namespace gui
private: private:
u32 checkTime; u32 CheckTime;
bool Pressed; bool Pressed;
bool Checked; bool Checked;
bool Border;
bool Background;
}; };
} // end namespace gui } // end namespace gui
......
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