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 "IrrCompileConfig.h"
\r
9 #include "IGUIButton.h"
\r
10 #include "IGUISpriteBank.h"
\r
11 #include "ITexture.h"
\r
19 class CGUIButton : public IGUIButton
\r
24 CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
\r
25 s32 id, core::rect<s32> rectangle, bool noclip=false);
\r
28 virtual ~CGUIButton();
\r
30 //! called if an event happened.
\r
31 bool OnEvent(const SEvent& event) override;
\r
33 //! draws the element and its children
\r
34 void draw() override;
\r
36 //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
\r
37 void setOverrideFont(IGUIFont* font=0) override;
\r
39 //! Gets the override font (if any)
\r
40 IGUIFont* getOverrideFont() const override;
\r
42 //! Get the font which is used right now for drawing
\r
43 IGUIFont* getActiveFont() const override;
\r
45 //! Sets another color for the button text.
\r
46 void setOverrideColor(video::SColor color) override;
\r
48 //! Gets the override color
\r
49 video::SColor getOverrideColor(void) const override;
\r
51 //! Gets the currently used text color
\r
52 video::SColor getActiveColor() const override;
\r
54 //! Sets if the button text should use the override color or the color in the gui skin.
\r
55 void enableOverrideColor(bool enable) override;
\r
57 //! Checks if an override color is enabled
\r
58 bool isOverrideColorEnabled(void) const override;
\r
60 //! Sets an image which should be displayed on the button when it is in the given state.
\r
61 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
63 //! Sets an image which should be displayed on the button when it is in normal state.
\r
64 void setImage(video::ITexture* image=0) override
\r
66 setImage(EGBIS_IMAGE_UP, image);
\r
69 //! Sets an image which should be displayed on the button when it is in normal state.
\r
70 void setImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
72 setImage(EGBIS_IMAGE_UP, image, pos);
\r
75 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
76 void setPressedImage(video::ITexture* image=0) override
\r
78 setImage(EGBIS_IMAGE_DOWN, image);
\r
81 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
82 void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
84 setImage(EGBIS_IMAGE_DOWN, image, pos);
\r
87 //! Sets the sprite bank used by the button
\r
88 void setSpriteBank(IGUISpriteBank* bank=0) override;
\r
90 //! Sets the animated sprite for a specific button state
\r
91 /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\r
92 \param state: State of the button to set the sprite for
\r
93 \param index: The sprite number from the current sprite bank
\r
94 \param color: The color of the sprite
\r
96 virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
\r
97 video::SColor color=video::SColor(255,255,255,255),
\r
98 bool loop=false, bool scale=false) override;
\r
100 //! Get the sprite-index for the given state or -1 when no sprite is set
\r
101 s32 getSpriteIndex(EGUI_BUTTON_STATE state) const override;
\r
103 //! Get the sprite color for the given state. Color is only used when a sprite is set.
\r
104 video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const override;
\r
106 //! Returns if the sprite in the given state does loop
\r
107 bool getSpriteLoop(EGUI_BUTTON_STATE state) const override;
\r
109 //! Returns if the sprite in the given state is scaled
\r
110 bool getSpriteScale(EGUI_BUTTON_STATE state) const override;
\r
112 //! Sets if the button should behave like a push button. Which means it
\r
113 //! can be in two states: Normal or Pressed. With a click on the button,
\r
114 //! the user can change the state of the button.
\r
115 void setIsPushButton(bool isPushButton=true) override;
\r
117 //! Checks whether the button is a push button
\r
118 bool isPushButton() const override;
\r
120 //! Sets the pressed state of the button if this is a pushbutton
\r
121 void setPressed(bool pressed=true) override;
\r
123 //! Returns if the button is currently pressed
\r
124 bool isPressed() const override;
\r
126 //! Sets if the button should use the skin to draw its border
\r
127 void setDrawBorder(bool border=true) override;
\r
129 //! Checks if the button face and border are being drawn
\r
130 bool isDrawingBorder() const override;
\r
132 //! Sets if the alpha channel should be used for drawing images on the button (default is false)
\r
133 void setUseAlphaChannel(bool useAlphaChannel=true) override;
\r
135 //! Checks if the alpha channel should be used for drawing images on the button
\r
136 bool isAlphaChannelUsed() const override;
\r
138 //! Sets if the button should scale the button images to fit
\r
139 void setScaleImage(bool scaleImage=true) override;
\r
141 //! Checks whether the button scales the used images
\r
142 bool isScalingImage() const override;
\r
144 //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
\r
145 bool getClickShiftState() const override
\r
147 return ClickShiftState;
\r
150 //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
\r
151 bool getClickControlState() const override
\r
153 return ClickControlState;
\r
157 void drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
\r
158 EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
\r
162 struct ButtonSprite
\r
164 ButtonSprite() : Index(-1), Loop(false), Scale(false)
\r
168 bool operator==(const ButtonSprite& other) const
\r
170 return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
\r
174 video::SColor Color;
\r
179 ButtonSprite ButtonSprites[EGBS_COUNT];
\r
180 IGUISpriteBank* SpriteBank;
\r
184 ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
188 ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
199 ButtonImage& operator=(const ButtonImage& other)
\r
201 if ( this == &other )
\r
205 other.Texture->grab();
\r
208 Texture = other.Texture;
\r
209 SourceRect = other.SourceRect;
\r
213 bool operator==(const ButtonImage& other) const
\r
215 return Texture == other.Texture && SourceRect == other.SourceRect;
\r
219 video::ITexture* Texture;
\r
220 core::rect<s32> SourceRect;
\r
223 ButtonImage ButtonImages[EGBIS_COUNT];
\r
225 IGUIFont* OverrideFont;
\r
227 bool OverrideColorEnabled;
\r
228 video::SColor OverrideColor;
\r
230 u32 ClickTime, HoverTime, FocusTime;
\r
232 bool ClickShiftState;
\r
233 bool ClickControlState;
\r
237 bool UseAlphaChannel;
\r
242 } // end namespace gui
\r
243 } // end namespace irr
\r
245 #endif // __C_GUI_BUTTON_H_INCLUDED__
\r