diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUICheckBox.h Irrlicht_starsonata/include/IGUICheckBox.h --- irrlicht-svn-ss/trunk/include/IGUICheckBox.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUICheckBox.h 2008-04-25 22:50:44.000000000 +0200 @@ -11,7 +11,6 @@ namespace irr { namespace gui { - //! GUI Check box interface. class IGUICheckBox : public IGUIElement { @@ -29,6 +28,19 @@ namespace gui //! Returns true if box is checked. virtual bool isChecked() = 0; + + // starsonata, micha - adding spritesupport to have more layout possibilities + //! Set the spritebank which will be used to draw custom icons. + virtual void setSpriteBank(const c8 *bankName) = 0; + + // starsonata, micha - adding spritesupport to have more layout possibilities + //! Set a sprite which will be used for drawing in "checked" state + //! Set the spritebank for this in setSpriteBank, otherwise the spritebank of the default skin is used + virtual void setIconChecked(s32 spriteIdx) = 0; + + //! set a sprite which will be used for drawing in "unchecked" state + //! Set the spritebank for this in setSpriteBank, otherwise the spritebank of the default skin is used + virtual void setIconUnChecked(s32 spriteIdx) = 0; }; } // end namespace gui diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUICheckBox.cpp Irrlicht_starsonata/source/Irrlicht/CGUICheckBox.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUICheckBox.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUICheckBox.cpp 2008-05-29 03:31:18.000000000 +0200 @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in irrlicht.h #include "CGUICheckBox.h" +#include "IGUISpriteBank.h" #include "IGUISkin.h" #include "IGUIEnvironment.h" #include "IVideoDriver.h" @@ -16,7 +17,10 @@ namespace gui //! constructor CGUICheckBox::CGUICheckBox(bool checked, IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle) -: IGUICheckBox(environment, parent, id, rectangle), Pressed(false), Checked(checked), checkTime(0) +: IGUICheckBox(environment, parent, id, rectangle), Pressed(false), Checked(checked), CheckTime(0) +, IconChecked(-1) +, IconUnchecked(-1) +, IconBank(NULL) { #ifdef _DEBUG setDebugName("CGUICheckBox"); @@ -32,6 +36,8 @@ CGUICheckBox::CGUICheckBox(bool checked, //! destructor CGUICheckBox::~CGUICheckBox() { + if (IconBank) + IconBank->drop(); } @@ -39,6 +45,9 @@ CGUICheckBox::~CGUICheckBox() //! called if an event happened. bool CGUICheckBox::OnEvent(SEvent event) { + if ( !IsEnabled ) + return IGUIElement::OnEvent(event); + switch(event.EventType) { case EET_KEY_INPUT_EVENT: @@ -85,7 +94,7 @@ bool CGUICheckBox::OnEvent(SEvent event) if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) { Pressed = true; - checkTime = os::Timer::getTime(); + CheckTime = os::Timer::getTime(); Environment->setFocus(this); return true; } @@ -118,7 +127,7 @@ bool CGUICheckBox::OnEvent(SEvent event) break; } - return Parent ? Parent->OnEvent(event) : false; + return IGUIElement::OnEvent(event); } @@ -130,6 +139,7 @@ void CGUICheckBox::draw() return; IGUISkin* skin = Environment->getSkin(); + IGUISpriteBank* currentIconBank = IconBank ? IconBank : skin->getSpriteBank(); core::rect rect = AbsoluteRect; @@ -142,12 +152,31 @@ void CGUICheckBox::draw() checkRect.LowerRightCorner.X = checkRect.UpperLeftCorner.X + height; checkRect.LowerRightCorner.Y = checkRect.UpperLeftCorner.Y + height; + bool customDrawing = false; + if ( Checked && IconChecked >= 0 ) + { + customDrawing = true; + currentIconBank->draw2DSprite( (u32)IconChecked, checkRect.getCenter(), &AbsoluteClippingRect, + Pressed || !IsEnabled ? skin->getColor(EGDC_ICON_HIGH_LIGHT) : skin->getColor(EGDC_ICON), + CheckTime, os::Timer::getTime(), false, true); + } + else if ( !Checked && IconUnchecked >= 0 ) + { + customDrawing = true; + currentIconBank->draw2DSprite( (u32)IconUnchecked, checkRect.getCenter(), &AbsoluteClippingRect, + Pressed || !IsEnabled ? skin->getColor(EGDC_ICON_HIGH_LIGHT) : skin->getColor(EGDC_ICON), + CheckTime, os::Timer::getTime(), false, true); + } + + if ( ! customDrawing ) + { skin->draw3DSunkenPane(this, skin->getColor(Pressed ? EGDC_3D_FACE : EGDC_ACTIVE_CAPTION), false, true, checkRect, &AbsoluteClippingRect); if (Checked && Environment->getSkin()) Environment->getSkin()->drawIcon(this, EGDI_CHECK_BOX_CHECKED, checkRect.getCenter(), - checkTime, os::Timer::getTime(), false, &AbsoluteClippingRect); + CheckTime, os::Timer::getTime(), false, &AbsoluteClippingRect); + } if (Text.size()) { @@ -157,7 +186,7 @@ void CGUICheckBox::draw() IGUIFont* font = skin->getFont(); if (font) font->draw(Text.c_str(), checkRect, - skin->getColor(EGDC_BUTTON_TEXT), false, true, &AbsoluteClippingRect); + skin->getColor( !IsEnabled ? EGDC_GRAY_TEXT : EGDC_BUTTON_TEXT), false, true, &AbsoluteClippingRect); } IGUIElement::draw(); @@ -178,17 +207,56 @@ bool CGUICheckBox::isChecked() return Checked; } +void CGUICheckBox::setSpriteBank(const c8 *bankName) +{ + IconBankName = core::stringc(bankName); + IGUISpriteBank* bank = IconBankName.size() ? Environment->getSpriteBank(IconBankName.c_str()) : NULL; + if ( bank != IconBank ) + { + if (IconBank) + IconBank->drop(); + IconBank = bank; + if (IconBank) + IconBank->grab(); + } +} + +void CGUICheckBox::setIconChecked(s32 spriteIdx) +{ + IconChecked = spriteIdx; +} + +void CGUICheckBox::setIconUnChecked(s32 spriteIdx) +{ + IconUnchecked = spriteIdx; +} + //! Writes attributes of the element. void CGUICheckBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) { IGUICheckBox::serializeAttributes(out,options); out->addBool ("Checked", Checked ); + out->addInt ("IconChecked", IconChecked ); + out->addInt ("IconUnchecked", IconUnchecked ); + out->addString ("IconBankName", IconBankName.c_str() ); } //! Reads attributes of the element void CGUICheckBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) { + Pressed = false; Checked = in->getAttributeAsBool ("Checked"); + CheckTime = 0; + IconChecked = in->getAttributeAsInt("IconChecked"); + IconUnchecked = in->getAttributeAsInt("IconUnchecked"); + + IconBankName = in->getAttributeAsString("IconBankName"); + setSpriteBank(IconBankName.c_str()); + + if ( IconBankName.size() && !IconBank ) + { + os::Printer::log("CGUICheckBox::deserializeAttributes Got no sprite bank for", IconBankName.c_str(), ELL_ERROR); + } IGUICheckBox::deserializeAttributes(in,options); } diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUICheckBox.h Irrlicht_starsonata/source/Irrlicht/CGUICheckBox.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUICheckBox.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUICheckBox.h 2008-04-25 22:48:38.000000000 +0200 @@ -11,6 +11,7 @@ namespace irr { namespace gui { + class IGUISpriteBank; class CGUICheckBox : public IGUICheckBox { @@ -28,6 +29,20 @@ namespace gui //! returns if box is checked virtual bool isChecked(); + // starsonata, micha - adding spritesupport to have more layout possibilities + //! Set the spritebank which will be used to draw custom icons. + virtual void setSpriteBank(const c8 *bankName); + + // starsonata, micha + //! Set a sprite which will be used for drawing in "checked" state + //! Set the spritebank for this in setSpriteBank, otherwise the spritebank of the default skin is used + virtual void setIconChecked(s32 spriteIdx); + + // starsonata, micha + //! set a sprite which will be used for drawing in "unchecked" state + //! Set the spritebank for this in setSpriteBank, otherwise the spritebank of the default skin is used + virtual void setIconUnChecked(s32 spriteIdx); + //! called if an event happened. virtual bool OnEvent(SEvent event); @@ -44,7 +59,11 @@ namespace gui bool Pressed; bool Checked; - u32 checkTime; + u32 CheckTime; + s32 IconChecked; + s32 IconUnchecked; + core::stringc IconBankName; + IGUISpriteBank* IconBank; }; } // end namespace gui