CGUIButton.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __C_GUI_BUTTON_H_INCLUDED__
  5. #define __C_GUI_BUTTON_H_INCLUDED__
  6. #include "IrrCompileConfig.h"
  7. #ifdef _IRR_COMPILE_WITH_GUI_
  8. #include "IGUIButton.h"
  9. #include "IGUISpriteBank.h"
  10. #include "SColor.h"
  11. namespace irr
  12. {
  13. namespace gui
  14. {
  15. class CGUIButton : public IGUIButton
  16. {
  17. public:
  18. //! constructor
  19. CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
  20. s32 id, core::rect<s32> rectangle, bool noclip=false);
  21. //! destructor
  22. virtual ~CGUIButton();
  23. //! called if an event happened.
  24. virtual bool OnEvent(const SEvent& event);
  25. //! draws the element and its children
  26. virtual void draw();
  27. //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
  28. virtual void setOverrideFont(IGUIFont* font=0);
  29. //! Gets the override font (if any)
  30. virtual IGUIFont* getOverrideFont() const;
  31. //! Get the font which is used right now for drawing
  32. virtual IGUIFont* getActiveFont() const;
  33. //! Sets an image which should be displayed on the button when it is in normal state.
  34. virtual void setImage(video::ITexture* image=0);
  35. //! Sets an image which should be displayed on the button when it is in normal state.
  36. virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
  37. //! Sets an image which should be displayed on the button when it is in pressed state.
  38. virtual void setPressedImage(video::ITexture* image=0);
  39. //! Sets an image which should be displayed on the button when it is in pressed state.
  40. virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
  41. //! Sets the sprite bank used by the button
  42. virtual void setSpriteBank(IGUISpriteBank* bank=0);
  43. //! Sets the animated sprite for a specific button state
  44. /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
  45. \param state: State of the button to set the sprite for
  46. \param index: The sprite number from the current sprite bank
  47. \param color: The color of the sprite
  48. */
  49. virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
  50. video::SColor color=video::SColor(255,255,255,255), bool loop=false);
  51. //! Sets if the button should behave like a push button. Which means it
  52. //! can be in two states: Normal or Pressed. With a click on the button,
  53. //! the user can change the state of the button.
  54. virtual void setIsPushButton(bool isPushButton=true);
  55. //! Checks whether the button is a push button
  56. virtual bool isPushButton() const;
  57. //! Sets the pressed state of the button if this is a pushbutton
  58. virtual void setPressed(bool pressed=true);
  59. //! Returns if the button is currently pressed
  60. virtual bool isPressed() const;
  61. //! Sets if the button should use the skin to draw its border
  62. virtual void setDrawBorder(bool border=true);
  63. //! Checks if the button face and border are being drawn
  64. virtual bool isDrawingBorder() const;
  65. //! Sets if the alpha channel should be used for drawing images on the button (default is false)
  66. virtual void setUseAlphaChannel(bool useAlphaChannel=true);
  67. //! Checks if the alpha channel should be used for drawing images on the button
  68. virtual bool isAlphaChannelUsed() const;
  69. //! Sets if the button should scale the button images to fit
  70. virtual void setScaleImage(bool scaleImage=true);
  71. //! Checks whether the button scales the used images
  72. virtual bool isScalingImage() const;
  73. //! Writes attributes of the element.
  74. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
  75. //! Reads attributes of the element
  76. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
  77. private:
  78. struct ButtonSprite
  79. {
  80. s32 Index;
  81. video::SColor Color;
  82. bool Loop;
  83. };
  84. ButtonSprite ButtonSprites[EGBS_COUNT];
  85. IGUISpriteBank* SpriteBank;
  86. IGUIFont* OverrideFont;
  87. video::ITexture* Image;
  88. video::ITexture* PressedImage;
  89. core::rect<s32> ImageRect;
  90. core::rect<s32> PressedImageRect;
  91. u32 ClickTime, HoverTime, FocusTime;
  92. bool IsPushButton;
  93. bool Pressed;
  94. bool UseAlphaChannel;
  95. bool DrawBorder;
  96. bool ScaleImage;
  97. };
  98. } // end namespace gui
  99. } // end namespace irr
  100. #endif // _IRR_COMPILE_WITH_GUI_
  101. #endif // __C_GUI_BUTTON_H_INCLUDED__