]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIButton.h
Reduce IrrCompileConfig usage to files that actually need it
[irrlicht.git] / source / Irrlicht / CGUIButton.h
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
4 \r
5 #ifndef __C_GUI_BUTTON_H_INCLUDED__\r
6 #define __C_GUI_BUTTON_H_INCLUDED__\r
7 \r
8 #include "IGUIButton.h"\r
9 #include "IGUISpriteBank.h"\r
10 #include "ITexture.h"\r
11 #include "SColor.h"\r
12 \r
13 namespace irr\r
14 {\r
15 namespace gui\r
16 {\r
17 \r
18         class CGUIButton : public IGUIButton\r
19         {\r
20         public:\r
21 \r
22                 //! constructor\r
23                 CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,\r
24                         s32 id, core::rect<s32> rectangle, bool noclip=false);\r
25 \r
26                 //! destructor\r
27                 virtual ~CGUIButton();\r
28 \r
29                 //! called if an event happened.\r
30                 bool OnEvent(const SEvent& event) override;\r
31 \r
32                 //! draws the element and its children\r
33                 void draw() override;\r
34 \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
37 \r
38                 //! Gets the override font (if any)\r
39                 IGUIFont* getOverrideFont() const override;\r
40 \r
41                 //! Get the font which is used right now for drawing\r
42                 IGUIFont* getActiveFont() const override;\r
43 \r
44                 //! Sets another color for the button text.\r
45                 void setOverrideColor(video::SColor color)  override;\r
46 \r
47                 //! Gets the override color\r
48                 video::SColor getOverrideColor(void) const  override;\r
49 \r
50                 //! Gets the currently used text color\r
51                 video::SColor getActiveColor() const override;\r
52 \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
55 \r
56                 //! Checks if an override color is enabled\r
57                 bool isOverrideColorEnabled(void) const  override;\r
58 \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
61 \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
64                 {\r
65                         setImage(EGBIS_IMAGE_UP, image);\r
66                 }\r
67 \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
70                 {\r
71                         setImage(EGBIS_IMAGE_UP, image, pos);\r
72                 }\r
73 \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
76                 {\r
77                         setImage(EGBIS_IMAGE_DOWN, image);\r
78                 }\r
79 \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
82                 {\r
83                         setImage(EGBIS_IMAGE_DOWN, image, pos);\r
84                 }\r
85 \r
86                 //! Sets the sprite bank used by the button\r
87                 void setSpriteBank(IGUISpriteBank* bank=0) override;\r
88 \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
94                 */\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
98 \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
101 \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
104 \r
105                 //! Returns if the sprite in the given state does loop\r
106                 bool getSpriteLoop(EGUI_BUTTON_STATE state) const override;\r
107 \r
108                 //! Returns if the sprite in the given state is scaled\r
109                 bool getSpriteScale(EGUI_BUTTON_STATE state) const override;\r
110 \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
115 \r
116                 //! Checks whether the button is a push button\r
117                 bool isPushButton() const override;\r
118 \r
119                 //! Sets the pressed state of the button if this is a pushbutton\r
120                 void setPressed(bool pressed=true) override;\r
121 \r
122                 //! Returns if the button is currently pressed\r
123                 bool isPressed() const override;\r
124 \r
125                 //! Sets if the button should use the skin to draw its border\r
126                 void setDrawBorder(bool border=true) override;\r
127 \r
128                 //! Checks if the button face and border are being drawn\r
129                 bool isDrawingBorder() const override;\r
130 \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
133 \r
134                 //! Checks if the alpha channel should be used for drawing images on the button\r
135                 bool isAlphaChannelUsed() const override;\r
136 \r
137                 //! Sets if the button should scale the button images to fit\r
138                 void setScaleImage(bool scaleImage=true) override;\r
139 \r
140                 //! Checks whether the button scales the used images\r
141                 bool isScalingImage() const override;\r
142 \r
143                 //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event\r
144                 bool getClickShiftState() const override\r
145                 {\r
146                         return ClickShiftState;\r
147                 }\r
148 \r
149                 //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event\r
150                 bool getClickControlState() const override\r
151                 {\r
152                         return ClickControlState;\r
153                 }\r
154 \r
155         protected:\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
158 \r
159         private:\r
160 \r
161                 struct ButtonSprite\r
162                 {\r
163                         ButtonSprite() : Index(-1), Loop(false), Scale(false)\r
164                         {\r
165                         }\r
166 \r
167                         bool operator==(const ButtonSprite& other) const\r
168                         {\r
169                                 return Index == other.Index && Color == other.Color && Loop == other.Loop && Scale == other.Scale;\r
170                         }\r
171 \r
172                         s32 Index;\r
173                         video::SColor Color;\r
174                         bool Loop;\r
175                         bool Scale;\r
176                 };\r
177 \r
178                 ButtonSprite ButtonSprites[EGBS_COUNT];\r
179                 IGUISpriteBank* SpriteBank;\r
180 \r
181                 struct ButtonImage\r
182                 {\r
183                         ButtonImage() : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))\r
184                         {\r
185                         }\r
186 \r
187                         ButtonImage(const ButtonImage& other) : Texture(0), SourceRect(core::rect<s32>(0,0,0,0))\r
188                         {\r
189                                 *this = other;\r
190                         }\r
191 \r
192                         ~ButtonImage()\r
193                         {\r
194                                 if ( Texture )\r
195                                         Texture->drop();\r
196                         }\r
197 \r
198                         ButtonImage& operator=(const ButtonImage& other)\r
199                         {\r
200                                 if ( this == &other )\r
201                                         return *this;\r
202 \r
203                                 if (other.Texture)\r
204                                         other.Texture->grab();\r
205                                 if ( Texture )\r
206                                         Texture->drop();\r
207                                 Texture = other.Texture;\r
208                                 SourceRect = other.SourceRect;\r
209                                 return *this;\r
210                         }\r
211 \r
212                         bool operator==(const ButtonImage& other) const\r
213                         {\r
214                                 return Texture == other.Texture && SourceRect == other.SourceRect;\r
215                         }\r
216 \r
217 \r
218                         video::ITexture* Texture;\r
219                         core::rect<s32> SourceRect;\r
220                 };\r
221 \r
222                 ButtonImage ButtonImages[EGBIS_COUNT];\r
223 \r
224                 IGUIFont* OverrideFont;\r
225 \r
226                 bool OverrideColorEnabled;\r
227                 video::SColor OverrideColor;\r
228 \r
229                 u32 ClickTime, HoverTime, FocusTime;\r
230 \r
231                 bool ClickShiftState;\r
232                 bool ClickControlState;\r
233 \r
234                 bool IsPushButton;\r
235                 bool Pressed;\r
236                 bool UseAlphaChannel;\r
237                 bool DrawBorder;\r
238                 bool ScaleImage;\r
239         };\r
240 \r
241 } // end namespace gui\r
242 } // end namespace irr\r
243 \r
244 #endif // __C_GUI_BUTTON_H_INCLUDED__\r