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 #ifdef _IRR_COMPILE_WITH_GUI_
\r
11 #include "IGUIButton.h"
\r
12 #include "IGUISpriteBank.h"
\r
13 #include "ITexture.h"
\r
21 class CGUIButton : public IGUIButton
\r
26 CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
\r
27 s32 id, core::rect<s32> rectangle, bool noclip=false);
\r
30 virtual ~CGUIButton();
\r
32 //! called if an event happened.
\r
33 bool OnEvent(const SEvent& event) override;
\r
35 //! draws the element and its children
\r
36 void draw() override;
\r
38 //! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
\r
39 void setOverrideFont(IGUIFont* font=0) override;
\r
41 //! Gets the override font (if any)
\r
42 IGUIFont* getOverrideFont() const override;
\r
44 //! Get the font which is used right now for drawing
\r
45 IGUIFont* getActiveFont() const override;
\r
47 //! Sets another color for the button text.
\r
48 void setOverrideColor(video::SColor color) override;
\r
50 //! Gets the override color
\r
51 video::SColor getOverrideColor(void) const override;
\r
53 //! Gets the currently used text color
\r
54 video::SColor getActiveColor() const override;
\r
56 //! Sets if the button text should use the override color or the color in the gui skin.
\r
57 void enableOverrideColor(bool enable) override;
\r
59 //! Checks if an override color is enabled
\r
60 bool isOverrideColorEnabled(void) const override;
\r
62 //! Sets an image which should be displayed on the button when it is in the given state.
\r
63 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
65 //! Sets an image which should be displayed on the button when it is in normal state.
\r
66 void setImage(video::ITexture* image=0) override
\r
68 setImage(EGBIS_IMAGE_UP, image);
\r
71 //! Sets an image which should be displayed on the button when it is in normal state.
\r
72 void setImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
74 setImage(EGBIS_IMAGE_UP, image, pos);
\r
77 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
78 void setPressedImage(video::ITexture* image=0) override
\r
80 setImage(EGBIS_IMAGE_DOWN, image);
\r
83 //! Sets an image which should be displayed on the button when it is in pressed state.
\r
84 void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override
\r
86 setImage(EGBIS_IMAGE_DOWN, image, pos);
\r
89 //! Sets the sprite bank used by the button
\r
90 void setSpriteBank(IGUISpriteBank* bank=0) override;
\r
92 //! Sets the animated sprite for a specific button state
\r
93 /** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\r
94 \param state: State of the button to set the sprite for
\r
95 \param index: The sprite number from the current sprite bank
\r
96 \param color: The color of the sprite
\r
98 virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
\r
99 video::SColor color=video::SColor(255,255,255,255),
\r
100 bool loop=false, bool scale=false) override;
\r
102 //! Get the sprite-index for the given state or -1 when no sprite is set
\r
103 s32 getSpriteIndex(EGUI_BUTTON_STATE state) const override;
\r
105 //! Get the sprite color for the given state. Color is only used when a sprite is set.
\r
106 video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const override;
\r
108 //! Returns if the sprite in the given state does loop
\r
109 bool getSpriteLoop(EGUI_BUTTON_STATE state) const override;
\r
111 //! Returns if the sprite in the given state is scaled
\r
112 bool getSpriteScale(EGUI_BUTTON_STATE state) const override;
\r
114 //! Sets if the button should behave like a push button. Which means it
\r
115 //! can be in two states: Normal or Pressed. With a click on the button,
\r
116 //! the user can change the state of the button.
\r
117 void setIsPushButton(bool isPushButton=true) override;
\r
119 //! Checks whether the button is a push button
\r
120 bool isPushButton() const override;
\r
122 //! Sets the pressed state of the button if this is a pushbutton
\r
123 void setPressed(bool pressed=true) override;
\r
125 //! Returns if the button is currently pressed
\r
126 bool isPressed() const override;
\r
128 //! Sets if the button should use the skin to draw its border
\r
129 void setDrawBorder(bool border=true) override;
\r
131 //! Checks if the button face and border are being drawn
\r
132 bool isDrawingBorder() const override;
\r
134 //! Sets if the alpha channel should be used for drawing images on the button (default is false)
\r
135 void setUseAlphaChannel(bool useAlphaChannel=true) override;
\r
137 //! Checks if the alpha channel should be used for drawing images on the button
\r
138 bool isAlphaChannelUsed() const override;
\r
140 //! Sets if the button should scale the button images to fit
\r
141 void setScaleImage(bool scaleImage=true) override;
\r
143 //! Checks whether the button scales the used images
\r
144 bool isScalingImage() const override;
\r
146 //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
\r
147 bool getClickShiftState() const override
\r
149 return ClickShiftState;
\r
152 //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
\r
153 bool getClickControlState() const override
\r
155 return ClickControlState;
\r
159 void drawSprite(EGUI_BUTTON_STATE state, u32 startTime, const core::position2di& center);
\r
160 EGUI_BUTTON_IMAGE_STATE getImageState(bool pressed) const;
\r
164 struct ButtonSprite
\r
166 ButtonSprite() : Index(-1), Loop(false), Scale(false)
\r
170 bool operator==(const ButtonSprite& other) const
\r
172 return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;
\r
176 video::SColor Color;
\r
181 ButtonSprite ButtonSprites[EGBS_COUNT];
\r
182 IGUISpriteBank* SpriteBank;
\r
186 ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
190 ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))
\r
201 ButtonImage& operator=(const ButtonImage& other)
\r
203 if ( this == &other )
\r
207 other.Texture->grab();
\r
210 Texture = other.Texture;
\r
211 SourceRect = other.SourceRect;
\r
215 bool operator==(const ButtonImage& other) const
\r
217 return Texture == other.Texture && SourceRect == other.SourceRect;
\r
221 video::ITexture* Texture;
\r
222 core::rect<s32> SourceRect;
\r
225 ButtonImage ButtonImages[EGBIS_COUNT];
\r
227 IGUIFont* OverrideFont;
\r
229 bool OverrideColorEnabled;
\r
230 video::SColor OverrideColor;
\r
232 u32 ClickTime, HoverTime, FocusTime;
\r
234 bool ClickShiftState;
\r
235 bool ClickControlState;
\r
239 bool UseAlphaChannel;
\r
244 } // end namespace gui
\r
245 } // end namespace irr
\r
247 #endif // _IRR_COMPILE_WITH_GUI_
\r
249 #endif // __C_GUI_BUTTON_H_INCLUDED__
\r