1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_GUI_BUTTON_H_INCLUDED__
6
#define __C_GUI_BUTTON_H_INCLUDED__
8
#include "IrrCompileConfig.h"
9
#ifdef _IRR_COMPILE_WITH_GUI_
11
#include "IGUIButton.h"
12
#include "IGUISpriteBank.h"
20
class CGUIButton : public IGUIButton
25
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
26
s32 id, core::rect<s32> rectangle, bool noclip=false);
29
virtual ~CGUIButton();
31
//! called if an event happened.
32
virtual bool OnEvent(const SEvent& event);
34
//! draws the element and its children
37
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
38
virtual void setOverrideFont(IGUIFont* font=0);
40
//! Gets the override font (if any)
41
virtual IGUIFont* getOverrideFont() const;
43
//! Get the font which is used right now for drawing
44
virtual IGUIFont* getActiveFont() const;
46
//! Sets an image which should be displayed on the button when it is in normal state.
47
virtual void setImage(video::ITexture* image=0);
49
//! Sets an image which should be displayed on the button when it is in normal state.
50
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
52
//! Sets an image which should be displayed on the button when it is in pressed state.
53
virtual void setPressedImage(video::ITexture* image=0);
55
//! Sets an image which should be displayed on the button when it is in pressed state.
56
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
58
//! Sets the sprite bank used by the button
59
virtual void setSpriteBank(IGUISpriteBank* bank=0);
61
//! Sets the animated sprite for a specific button state
62
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
63
\param state: State of the button to set the sprite for
64
\param index: The sprite number from the current sprite bank
65
\param color: The color of the sprite
67
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
68
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
70
//! Sets if the button should behave like a push button. Which means it
71
//! can be in two states: Normal or Pressed. With a click on the button,
72
//! the user can change the state of the button.
73
virtual void setIsPushButton(bool isPushButton=true);
75
//! Checks whether the button is a push button
76
virtual bool isPushButton() const;
78
//! Sets the pressed state of the button if this is a pushbutton
79
virtual void setPressed(bool pressed=true);
81
//! Returns if the button is currently pressed
82
virtual bool isPressed() const;
84
//! Sets if the button should use the skin to draw its border
85
virtual void setDrawBorder(bool border=true);
87
//! Checks if the button face and border are being drawn
88
virtual bool isDrawingBorder() const;
90
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
91
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
93
//! Checks if the alpha channel should be used for drawing images on the button
94
virtual bool isAlphaChannelUsed() const;
96
//! Sets if the button should scale the button images to fit
97
virtual void setScaleImage(bool scaleImage=true);
99
//! Checks whether the button scales the used images
100
virtual bool isScalingImage() const;
102
//! Writes attributes of the element.
103
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
105
//! Reads attributes of the element
106
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
117
ButtonSprite ButtonSprites[EGBS_COUNT];
119
IGUISpriteBank* SpriteBank;
120
IGUIFont* OverrideFont;
122
video::ITexture* Image;
123
video::ITexture* PressedImage;
125
core::rect<s32> ImageRect;
126
core::rect<s32> PressedImageRect;
132
bool UseAlphaChannel;
137
} // end namespace gui
138
} // end namespace irr
140
#endif // _IRR_COMPILE_WITH_GUI_
142
#endif // __C_GUI_BUTTON_H_INCLUDED__