1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __C_GUI_BUTTON_H_INCLUDED__
\r
6 #define __C_GUI_BUTTON_H_INCLUDED__
\r
8 #include "IGUIButton.h"
\r
9 #include "IGUISpriteBank.h"
\r
10 #include "ITexture.h"
\r
18 class CGUIButton : public IGUIButton
\r
23 CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
\r
24 s32 id, core::rect<s32> rectangle, bool noclip=false);
\r
27 virtual ~CGUIButton();
\r
29 //! called if an event happened.
\r
30 bool OnEvent(const SEvent& event) override;
\r
32 //! draws the element and its children
\r
33 void draw() override;
\r
35 //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
\r
36 void setOverrideFont(IGUIFont* font=0) override;
\r
38 //! Gets the override font (if any)
\r
39 IGUIFont* getOverrideFont() const override;
\r
41 //! Get the font which is used right now for drawing
\r
42 IGUIFont* getActiveFont() const override;
\r
44 //! Sets another color for the button text.
\r
45 void setOverrideColor(video::SColor color) override;
\r
47 //! Gets the override color
\r
48 video::SColor getOverrideColor(void) const override;
\r
50 //! Gets the currently used text color
\r
51 video::SColor getActiveColor() const override;
\r
53 //! Sets if the button text should use the override color or the color in the gui skin.
\r
54 void enableOverrideColor(bool enable) override;
\r
56 //! Checks if an override color is enabled
\r
57 bool isOverrideColorEnabled(void) const override;
\r
59 //! Sets an image which should be displayed on the button when it is in the given state.
\r
60 void setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture* image=0, const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0)) override;
\r
62 //! Sets an image which should be displayed on the button when it is in normal state.
\r
63 void setImage(video::ITexture* image=0) override
\r
65 setImage(EGBIS_IMAGE_UP, image);
\r
68 //! Sets an image which should be displayed on the button when it is in normal state.
\r
69 void setImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
71 setImage(EGBIS_IMAGE_UP, image, pos);
\r
74 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
75 void setPressedImage(video::ITexture* image=0) override
\r
77 setImage(EGBIS_IMAGE_DOWN, image);
\r
80 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
81 void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
83 setImage(EGBIS_IMAGE_DOWN, image, pos);
\r
86 //! Sets the sprite bank used by the button
\r
87 void setSpriteBank(IGUISpriteBank* bank=0) override;
\r
89 //! Sets the animated sprite for a specific button state
\r
90 /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\r
91 \param state: State of the button to set the sprite for
\r
92 \param index: The sprite number from the current sprite bank
\r
93 \param color: The color of the sprite
\r
95 virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
\r
96 video::SColor color=video::SColor(255,255,255,255),
\r
97 bool loop=false, bool scale=false) override;
\r
99 //! Get the sprite-index for the given state or -1 when no sprite is set
\r
100 s32 getSpriteIndex(EGUI_BUTTON_STATE state) const override;
\r
102 //! Get the sprite color for the given state. Color is only used when a sprite is set.
\r
103 video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const override;
\r
105 //! Returns if the sprite in the given state does loop
\r
106 bool getSpriteLoop(EGUI_BUTTON_STATE state) const override;
\r
108 //! Returns if the sprite in the given state is scaled
\r
109 bool getSpriteScale(EGUI_BUTTON_STATE state) const override;
\r
111 //! Sets if the button should behave like a push button. Which means it
\r
112 //! can be in two states: Normal or Pressed. With a click on the button,
\r
113 //! the user can change the state of the button.
\r
114 void setIsPushButton(bool isPushButton=true) override;
\r
116 //! Checks whether the button is a push button
\r
117 bool isPushButton() const override;
\r
119 //! Sets the pressed state of the button if this is a pushbutton
\r
120 void setPressed(bool pressed=true) override;
\r
122 //! Returns if the button is currently pressed
\r
123 bool isPressed() const override;
\r
125 //! Sets if the button should use the skin to draw its border
\r
126 void setDrawBorder(bool border=true) override;
\r
128 //! Checks if the button face and border are being drawn
\r
129 bool isDrawingBorder() const override;
\r
131 //! Sets if the alpha channel should be used for drawing images on the button (default is false)
\r
132 void setUseAlphaChannel(bool useAlphaChannel=true) override;
\r
134 //! Checks if the alpha channel should be used for drawing images on the button
\r
135 bool isAlphaChannelUsed() const override;
\r
137 //! Sets if the button should scale the button images to fit
\r
138 void setScaleImage(bool scaleImage=true) override;
\r
140 //! Checks whether the button scales the used images
\r
141 bool isScalingImage() const override;
\r
143 //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
\r
144 bool getClickShiftState() const override
\r
146 return ClickShiftState;
\r
149 //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
\r
150 bool getClickControlState() const override
\r
152 return ClickControlState;
\r
156 void drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
\r
157 EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
\r
161 struct ButtonSprite
\r
163 ButtonSprite() : Index(-1), Loop(false), Scale(false)
\r
167 bool operator==(const ButtonSprite& other) const
\r
169 return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
\r
173 video::SColor Color;
\r
178 ButtonSprite ButtonSprites[EGBS_COUNT];
\r
179 IGUISpriteBank* SpriteBank;
\r
183 ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
187 ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
198 ButtonImage& operator=(const ButtonImage& other)
\r
200 if ( this == &other )
\r
204 other.Texture->grab();
\r
207 Texture = other.Texture;
\r
208 SourceRect = other.SourceRect;
\r
212 bool operator==(const ButtonImage& other) const
\r
214 return Texture == other.Texture && SourceRect == other.SourceRect;
\r
218 video::ITexture* Texture;
\r
219 core::rect<s32> SourceRect;
\r
222 ButtonImage ButtonImages[EGBIS_COUNT];
\r
224 IGUIFont* OverrideFont;
\r
226 bool OverrideColorEnabled;
\r
227 video::SColor OverrideColor;
\r
229 u32 ClickTime, HoverTime, FocusTime;
\r
231 bool ClickShiftState;
\r
232 bool ClickControlState;
\r
236 bool UseAlphaChannel;
\r
241 } // end namespace gui
\r
242 } // end namespace irr
\r
244 #endif // __C_GUI_BUTTON_H_INCLUDED__
\r