diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIButton.h Irrlicht_starsonata/include/IGUIButton.h --- irrlicht-svn-ss/trunk/include/IGUIButton.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIButton.h 2008-03-20 04:50:48.000000000 +0100 @@ -68,6 +68,10 @@ namespace gui \param font: New font to set. */ virtual void setOverrideFont(IGUIFont* font=0) = 0; + // Starsonata, Micha + //! Return the font which is used for this button + virtual IGUIFont* getCurrentFont() = 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; @@ -88,6 +92,15 @@ namespace gui \param pos: Position in the texture, where the image is located */ virtual void setPressedImage(video::ITexture* image, const core::rect& pos) = 0; + //! Sets the background image which should be displayed on the button when it is in disabled state. + /** \param image: Image to be displayed */ + virtual void setDisabledImage(video::ITexture* image) = 0; + + //! Sets the background image which should be displayed on the button when it is in disabled state. + /** \param image: Texture containing the image to be displayed + \param pos: Position in the texture, where the image is located */ + virtual void setDisabledImage(video::ITexture* image, const core::rect& pos) = 0; + //! Sets the sprite bank used by the button virtual void setSpriteBank(IGUISpriteBank* bank) = 0; @@ -107,6 +120,7 @@ namespace gui virtual void setIsPushButton(bool isPushButton) = 0; //! Sets the pressed state of the button if this is a pushbutton + //! This will not cause EGET_PUSHBUTTON_STATE_CHANGED events virtual void setPressed(bool pressed) = 0; //! Returns if the button is currently pressed @@ -126,6 +140,31 @@ namespace gui //! Returns if the border and button face are being drawn using the skin virtual bool isDrawingBorder() = 0; + + // starsonata, micha: flashing background + //! enabled/disable flashing of the button background + virtual void setFlashing(bool flash_) = 0; + + // starsonata, micha: flashing background + //! is the button background flashing + virtual bool isFlashing() const = 0; + + // starsonata, micha: flashing background + //! get the state of the shift key when the last click event was created + virtual bool getClickShiftState() const = 0; + + // starsonata, micha: flashing background + //! get the state of the control key when the last click event was created + virtual bool getClickControlState() const = 0; + + // starsonata, micha: override the usual text color + //! set a new textcolor which can override the default from the skin + //! the override color will only be used if enableOverrideTextColor is set to true + virtual void setOverrideTextColor( video::SColor color=video::SColor(255,255,255,255) ) = 0; + + // starsonata, micha: override the usual text color + //! use the color from setOverrideTextColor instead of the skin color + virtual void enableOverrideTextColor(bool enable) = 0; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIButton.cpp Irrlicht_starsonata/source/Irrlicht/CGUIButton.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIButton.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIButton.cpp 2008-06-04 02:58:04.000000000 +0200 @@ -18,9 +18,11 @@ namespace gui CGUIButton::CGUIButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle, bool noclip) : IGUIButton(environment, parent, id, rectangle), Pressed(false), - IsPushButton(false), UseAlphaChannel(false), Border(true), - MouseOverTime(0), FocusTime(0), ClickTime(0), SpriteBank(0), - OverrideFont(0), Image(0), PressedImage(0) + IsPushButton(false), UseAlphaChannel(false), + IsFlashing(false), Border(true), ClickTime(0), + ClickShiftState(false), ClickControlState(false), + SpriteBank(0), OverrideFont(0), EnabledOverrideTextColor(false), + Image(0), PressedImage(0), DisabledImage(0) { #ifdef _DEBUG setDebugName("CGUIButton"); @@ -47,6 +49,9 @@ CGUIButton::~CGUIButton() if (Image) Image->drop(); + if ( DisabledImage ) + DisabledImage->drop(); + if (PressedImage) PressedImage->drop(); @@ -89,7 +94,7 @@ void CGUIButton::setSprite(EGUI_BUTTON_S bool CGUIButton::OnEvent(SEvent event) { if (!IsEnabled) - return Parent ? Parent->OnEvent(event) : false; + return IGUIElement::OnEvent(event); switch(event.EventType) { @@ -101,7 +106,18 @@ bool CGUIButton::OnEvent(SEvent event) if (!IsPushButton) setPressed(true); else + { setPressed(!Pressed); + if ( Parent ) + { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_PUSHBUTTON_STATE_CHANGED; + Parent->OnEvent(newEvent); + } + } return true; } @@ -122,6 +138,9 @@ bool CGUIButton::OnEvent(SEvent event) if (Parent) { + ClickShiftState = false; + ClickControlState = false; + SEvent newEvent; newEvent.EventType = EET_GUI_EVENT; newEvent.GUIEvent.Caller = this; @@ -173,11 +192,23 @@ bool CGUIButton::OnEvent(SEvent event) else { setPressed(!Pressed); + if ( Parent ) + { + SEvent newEvent; + newEvent.EventType = EET_GUI_EVENT; + newEvent.GUIEvent.Caller = this; + newEvent.GUIEvent.Element = 0; + newEvent.GUIEvent.EventType = EGET_PUSHBUTTON_STATE_CHANGED; + Parent->OnEvent(newEvent); + } } if ((!IsPushButton && wasPressed && Parent) || (IsPushButton && wasPressed != Pressed)) { + ClickShiftState = event.MouseInput.Shift; + ClickControlState = event.MouseInput.Control; + SEvent newEvent; newEvent.EventType = EET_GUI_EVENT; newEvent.GUIEvent.Caller = this; @@ -191,7 +222,7 @@ bool CGUIButton::OnEvent(SEvent event) break; } - return Parent ? Parent->OnEvent(event) : false; + return IGUIElement::OnEvent(event); } @@ -205,12 +236,11 @@ void CGUIButton::draw() IGUISkin* skin = Environment->getSkin(); irr::video::IVideoDriver* driver = Environment->getVideoDriver(); - IGUIFont* font = OverrideFont; - if (!OverrideFont) - font = skin->getFont(EGDF_BUTTON); + IGUIFont* font = getCurrentFont(); core::rect rect = AbsoluteRect; + // todo (MICHA): lot of duplicated code here. One call to draw2DImage and one to draw2DSprite would be cleaner imho. // todo: move sprite up and text down if the pressed state has a sprite // draw sprites for focused and mouse-over core::position2di spritePos = AbsoluteRect.getCenter(); @@ -218,9 +248,26 @@ void CGUIButton::draw() if (!Pressed) { if (Border) - skin->draw3DButtonPaneStandard(this, rect, &AbsoluteClippingRect); + { + u32 flashFrequency=0; + u32 flashTime=os::Timer::getTime(); + if ( IsFlashing ) + { + flashFrequency = 1000; + } + skin->draw3DButtonPaneStandard(this, rect, &AbsoluteClippingRect, flashFrequency, flashTime); + } - if (Image) + if ( !isEnabled() && DisabledImage ) + { + core::position2d pos = AbsoluteRect.getCenter(); + pos.X -= DisabledImageRect.getWidth() / 2; + pos.Y -= DisabledImageRect.getHeight() / 2; + + driver->draw2DImage(DisabledImage, pos, DisabledImageRect, &AbsoluteClippingRect, + video::SColor(255,255,255,255), UseAlphaChannel); + } + else if (Image) { core::position2d pos = AbsoluteRect.getCenter(); pos.X -= ImageRect.getWidth() / 2; @@ -231,7 +278,7 @@ void CGUIButton::draw() } if (SpriteBank && ButtonSprites[EGBS_BUTTON_UP].Index != -1) { - // draw pressed sprite + // draw sprite SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_UP].Index, spritePos, &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_UP].Color, ClickTime, os::Timer::getTime(), ButtonSprites[EGBS_BUTTON_UP].Loop, true); @@ -240,9 +287,26 @@ void CGUIButton::draw() else { if (Border) - skin->draw3DButtonPanePressed(this, rect, &AbsoluteClippingRect); + { + u32 flashFrequency=0; + u32 flashTime=os::Timer::getTime(); + if ( IsFlashing ) + { + flashFrequency = 1000; + } + skin->draw3DButtonPanePressed(this, rect, &AbsoluteClippingRect, flashFrequency, flashTime); + } - if (PressedImage) + if ( !isEnabled() && DisabledImage ) + { + core::position2d pos = AbsoluteRect.getCenter(); + pos.X -= DisabledImageRect.getWidth() / 2; + pos.Y -= DisabledImageRect.getHeight() / 2; + + driver->draw2DImage(DisabledImage, pos, DisabledImageRect, &AbsoluteClippingRect, + video::SColor(255,255,255,255), UseAlphaChannel); + } + else if (PressedImage) { core::position2d pos = AbsoluteRect.getCenter(); pos.X -= PressedImageRect.getWidth() / 2; @@ -259,7 +323,7 @@ void CGUIButton::draw() if (SpriteBank && ButtonSprites[EGBS_BUTTON_DOWN].Index != -1) { - // draw sprite + // draw pressed sprite SpriteBank->draw2DSprite(ButtonSprites[EGBS_BUTTON_DOWN].Index, spritePos, &AbsoluteClippingRect, ButtonSprites[EGBS_BUTTON_DOWN].Color, ClickTime, os::Timer::getTime(), ButtonSprites[EGBS_BUTTON_DOWN].Loop, true); @@ -274,10 +338,21 @@ void CGUIButton::draw() rect.UpperLeftCorner.Y += 2; if (font) + { + video::SColor textColor; + if ( EnabledOverrideTextColor ) + textColor = OverrideTextColor; + else if ( IsEnabled ) + textColor = skin->getColor(EGDC_BUTTON_TEXT); + else + textColor = skin->getColor(EGDC_GRAY_TEXT); + + font->draw(Text.c_str(), rect, - skin->getColor(IsEnabled ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT), true, true, + textColor, true, true, &AbsoluteClippingRect); } + } IGUIElement::draw(); } @@ -287,6 +362,9 @@ void CGUIButton::draw() //! sets another skin independent font. if this is set to zero, the button uses the font of the skin. void CGUIButton::setOverrideFont(IGUIFont* font) { + if ( OverrideFont == font ) + return; + if (OverrideFont) OverrideFont->drop(); @@ -296,19 +374,30 @@ void CGUIButton::setOverrideFont(IGUIFon OverrideFont->grab(); } +IGUIFont* CGUIButton::getCurrentFont() +{ + if ( OverrideFont ) + return OverrideFont; + + return Environment->getSkin()->getFont(EGDF_BUTTON); +} + //! Sets an image which should be displayed on the button when it is in normal state. void CGUIButton::setImage(video::ITexture* image) { + if ( image != Image ) + { if (Image) Image->drop(); Image = image; - if (image) - ImageRect = core::rect(core::position2d(0,0), image->getOriginalSize()); if (Image) Image->grab(); + } + if (image) + ImageRect = core::rect(core::position2d(0,0), image->getOriginalSize()); if (!PressedImage) setPressedImage(Image); @@ -317,14 +406,17 @@ void CGUIButton::setImage(video::ITextur //! Sets an image which should be displayed on the button when it is in normal state. void CGUIButton::setImage(video::ITexture* image, const core::rect& pos) { + ImageRect = pos; + if ( Image != image ) + { if (Image) Image->drop(); Image = image; - ImageRect = pos; if (Image) Image->grab(); + } if (!PressedImage) setPressedImage(Image, pos); @@ -357,6 +449,36 @@ void CGUIButton::setPressedImage(video:: PressedImage->grab(); } +//! Sets the background image which should be displayed on the button when it is in disabled state. +/** \param image: Image to be displayed */ +void CGUIButton::setDisabledImage(video::ITexture* image) +{ + if (DisabledImage) + DisabledImage->drop(); + + DisabledImage = image; + if (image) + DisabledImageRect = core::rect(core::position2d(0,0), image->getOriginalSize()); + + if (DisabledImage) + DisabledImage->grab(); +} + +//! Sets the background image which should be displayed on the button when it is in disabled state. +/** \param image: Texture containing the image to be displayed + \param pos: Position in the texture, where the image is located */ +void CGUIButton::setDisabledImage(video::ITexture* image, const core::rect& pos) +{ + if (DisabledImage) + DisabledImage->drop(); + + DisabledImage = image; + DisabledImageRect = pos; + + if (DisabledImage) + DisabledImage->grab(); +} + //! Sets if the button should behave like a push button. Which means it //! can be in two states: Normal or Pressed. With a click on the button, @@ -410,6 +532,26 @@ bool CGUIButton::isDrawingBorder() return Border; } +void CGUIButton::setFlashing(bool flash_) +{ + IsFlashing = flash_; +} + +bool CGUIButton::isFlashing() const +{ + return IsFlashing; +} + +void CGUIButton::setOverrideTextColor( video::SColor color ) +{ + OverrideTextColor = color; +} + +void CGUIButton::enableOverrideTextColor(bool enable) +{ + EnabledOverrideTextColor = enable; +} + //! Writes attributes of the element. void CGUIButton::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) { @@ -424,11 +566,18 @@ void CGUIButton::serializeAttributes(io: out->addRect ("ImageRect", ImageRect); out->addTexture ("PressedImage", PressedImage); out->addRect ("PressedImageRect",PressedImageRect); + out->addTexture ("DisabledImage", DisabledImage); + out->addRect ("DisabledImageRect",DisabledImageRect); out->addBool ("Border", Border); out->addBool ("UseAlphaChannel", UseAlphaChannel); + out->addBool ("IsFlashing", IsFlashing); + out->addBool ("EnabledOverrideTextColor", EnabledOverrideTextColor); + out->addColor ("OverrideTextColor", OverrideTextColor); + + if ( OverrideFont && OverrideFont->getName().size() ) + out->addString("OverrideFont", OverrideFont->getName().c_str() ); - // out->addString ("OverrideFont", OverrideFont); } //! Reads attributes of the element @@ -451,10 +600,23 @@ void CGUIButton::deserializeAttributes(i else setPressedImage( in->getAttributeAsTexture("PressedImage") ); + rec = in->getAttributeAsRect("DisabledImageRect"); + if (rec.isValid()) + setDisabledImage( in->getAttributeAsTexture("DisabledImage"), rec); + else + setDisabledImage( in->getAttributeAsTexture("DisabledImage") ); + setDrawBorder(in->getAttributeAsBool("Border")); UseAlphaChannel = in->getAttributeAsBool("UseAlphaChannel"); + setFlashing(in->getAttributeAsBool("IsFlashing")); + EnabledOverrideTextColor = in->getAttributeAsBool("EnabledOverrideTextColor"); + OverrideTextColor = in->getAttributeAsColor("OverrideTextColor"); - // setOverrideFont(in->getAttributeAsString("OverrideFont")); + core::stringc fontName = in->getAttributeAsString("OverrideFont"); + if ( fontName.size() ) + { + setOverrideFont( Environment->getFont(fontName.c_str()) ); + } updateAbsolutePosition(); } diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIButton.h Irrlicht_starsonata/source/Irrlicht/CGUIButton.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIButton.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIButton.h 2008-03-20 04:50:26.000000000 +0100 @@ -34,6 +34,10 @@ 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); + // Starsonata, Micha + //! Return the font which is used for this button + virtual IGUIFont* getCurrentFont(); + //! Sets an image which should be displayed on the button when it is in normal state. virtual void setImage(video::ITexture* image); @@ -46,6 +50,15 @@ namespace gui //! Sets an image which should be displayed on the button when it is in pressed state. virtual void setPressedImage(video::ITexture* image, const core::rect& pos); + //! Sets the background image which should be displayed on the button when it is in disabled state. + /** \param image: Image to be displayed */ + virtual void setDisabledImage(video::ITexture* image); + + //! Sets the background image which should be displayed on the button when it is in disabled state. + /** \param image: Texture containing the image to be displayed + \param pos: Position in the texture, where the image is located */ + virtual void setDisabledImage(video::ITexture* image, const core::rect& pos); + //! Sets the sprite bank used by the button virtual void setSpriteBank(IGUISpriteBank* bank); @@ -67,6 +80,7 @@ namespace gui virtual bool isPressed(); //! Sets the pressed state of the button if this is a pushbutton + //! This will not cause EGET_PUSHBUTTON_STATE_CHANGED events virtual void setPressed(bool pressed); //! Sets if the button should use the skin to draw its border @@ -84,6 +98,31 @@ namespace gui //! Returns whether the button is a push button virtual bool isPushButton(); + // starsonata, micha: flashing background + //! enabled/disable flashing of the button background + virtual void setFlashing(bool flash_); + + // starsonata, micha: flashing background + //! is the button background flashing + virtual bool isFlashing() const; + + // starsonata, micha: flashing background + //! get the state of the shift key when the last click event was created + virtual bool getClickShiftState() const { return ClickShiftState; } + + // starsonata, micha: flashing background + //! get the state of the control key when the last click event was created + virtual bool getClickControlState() const { return ClickControlState; } + + // starsonata, micha: override the usual text color + //! set a new textcolor which can override the default from the skin + //! the override color will only be used if enableOverrideColor is set to true + virtual void setOverrideTextColor( video::SColor color=video::SColor(255,255,255,255) ); + + // starsonata, micha: override the usual text color + //! use the color from setOverrideTextColor instead of the skin color + virtual void enableOverrideTextColor(bool enable); + //! Writes attributes of the element. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options); @@ -102,23 +141,30 @@ namespace gui bool Pressed; bool IsPushButton; bool UseAlphaChannel; + bool IsFlashing; bool Border; - u32 MouseOverTime; - u32 FocusTime; u32 ClickTime; + bool ClickShiftState; + bool ClickControlState; + IGUISpriteBank* SpriteBank; IGUIFont* OverrideFont; + bool EnabledOverrideTextColor; + video::SColor OverrideTextColor; + ButtonSprite ButtonSprites[EGBS_COUNT]; video::ITexture* Image; video::ITexture* PressedImage; + video::ITexture* DisabledImage; core::rect ImageRect; core::rect PressedImageRect; + core::rect DisabledImageRect; }; } // end namespace gui