IGUIButton.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IGUIElement.h"
  6. namespace irr
  7. {
  8. namespace video
  9. {
  10. class ITexture;
  11. } // end namespace video
  12. namespace gui
  13. {
  14. class IGUIFont;
  15. class IGUISpriteBank;
  16. //! Current state of buttons used for drawing sprites.
  17. //! Note that up to 3 states can be active at the same time:
  18. //! EGBS_BUTTON_UP or EGBS_BUTTON_DOWN
  19. //! EGBS_BUTTON_MOUSE_OVER or EGBS_BUTTON_MOUSE_OFF
  20. //! EGBS_BUTTON_FOCUSED or EGBS_BUTTON_NOT_FOCUSED
  21. enum EGUI_BUTTON_STATE
  22. {
  23. //! The button is not pressed.
  24. EGBS_BUTTON_UP = 0,
  25. //! The button is currently pressed down.
  26. EGBS_BUTTON_DOWN,
  27. //! The mouse cursor is over the button
  28. EGBS_BUTTON_MOUSE_OVER,
  29. //! The mouse cursor is not over the button
  30. EGBS_BUTTON_MOUSE_OFF,
  31. //! The button has the focus
  32. EGBS_BUTTON_FOCUSED,
  33. //! The button doesn't have the focus
  34. EGBS_BUTTON_NOT_FOCUSED,
  35. //! The button is disabled All other states are ignored in that case.
  36. EGBS_BUTTON_DISABLED,
  37. //! not used, counts the number of enumerated items
  38. EGBS_COUNT
  39. };
  40. //! Names for gui button state icons
  41. const c8 *const GUIButtonStateNames[EGBS_COUNT + 1] = {
  42. "buttonUp",
  43. "buttonDown",
  44. "buttonMouseOver",
  45. "buttonMouseOff",
  46. "buttonFocused",
  47. "buttonNotFocused",
  48. "buttonDisabled",
  49. 0, // count
  50. };
  51. //! State of buttons used for drawing texture images.
  52. //! Note that only a single state is active at a time
  53. //! Also when no image is defined for a state it will use images from another state
  54. //! and if that state is not set from the replacement for that,etc.
  55. //! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
  56. enum EGUI_BUTTON_IMAGE_STATE
  57. {
  58. //! When no other states have images they will all use this one.
  59. EGBIS_IMAGE_UP,
  60. //! When not set EGBIS_IMAGE_UP is used.
  61. EGBIS_IMAGE_UP_MOUSEOVER,
  62. //! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
  63. EGBIS_IMAGE_UP_FOCUSED,
  64. //! When not set EGBIS_IMAGE_UP_FOCUSED is used.
  65. EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
  66. //! When not set EGBIS_IMAGE_UP is used.
  67. EGBIS_IMAGE_DOWN,
  68. //! When not set EGBIS_IMAGE_DOWN is used.
  69. EGBIS_IMAGE_DOWN_MOUSEOVER,
  70. //! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
  71. EGBIS_IMAGE_DOWN_FOCUSED,
  72. //! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
  73. EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
  74. //! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button state).
  75. EGBIS_IMAGE_DISABLED,
  76. //! not used, counts the number of enumerated items
  77. EGBIS_COUNT
  78. };
  79. //! Names for gui button image states
  80. const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] = {
  81. "Image", // not "ImageUp" as it otherwise breaks serialization of old files
  82. "ImageUpOver",
  83. "ImageUpFocused",
  84. "ImageUpFocusedOver",
  85. "PressedImage", // not "ImageDown" as it otherwise breaks serialization of old files
  86. "ImageDownOver",
  87. "ImageDownFocused",
  88. "ImageDownFocusedOver",
  89. "ImageDisabled",
  90. 0, // count
  91. };
  92. //! GUI Button interface.
  93. /** \par This element can create the following events of type EGUI_EVENT_TYPE:
  94. \li EGET_BUTTON_CLICKED
  95. */
  96. class IGUIButton : public IGUIElement
  97. {
  98. public:
  99. //! constructor
  100. IGUIButton(IGUIEnvironment *environment, IGUIElement *parent, s32 id, core::rect<s32> rectangle) :
  101. IGUIElement(EGUIET_BUTTON, environment, parent, id, rectangle) {}
  102. //! Sets another skin independent font.
  103. /** If this is set to zero, the button uses the font of the skin.
  104. \param font: New font to set. */
  105. virtual void setOverrideFont(IGUIFont *font = 0) = 0;
  106. //! Gets the override font (if any)
  107. /** \return The override font (may be 0) */
  108. virtual IGUIFont *getOverrideFont(void) const = 0;
  109. //! Get the font which is used right now for drawing
  110. /** Currently this is the override font when one is set and the
  111. font of the active skin otherwise */
  112. virtual IGUIFont *getActiveFont() const = 0;
  113. //! Sets another color for the button text.
  114. /** When set, this color is used instead of EGDC_BUTTON_TEXT/EGDC_GRAY_TEXT.
  115. You don't need to call enableOverrideColor(true), that's done by this function.
  116. If you want the the color of the skin back, call enableOverrideColor(false);
  117. \param color: New color of the text. */
  118. virtual void setOverrideColor(video::SColor color) = 0;
  119. //! Gets the override color
  120. /** \return: The override color */
  121. virtual video::SColor getOverrideColor(void) const = 0;
  122. //! Gets the currently used text color
  123. /** Either a skin-color for the current state or the override color */
  124. virtual video::SColor getActiveColor() const = 0;
  125. //! Sets if the button text should use the override color or the color in the gui skin.
  126. /** \param enable: If set to true, the override color, which can be set
  127. with IGUIStaticText::setOverrideColor is used, otherwise the
  128. EGDC_BUTTON_TEXT or EGDC_GRAY_TEXT color of the skin. */
  129. virtual void enableOverrideColor(bool enable) = 0;
  130. //! Checks if an override color is enabled
  131. /** \return true if the override color is enabled, false otherwise */
  132. virtual bool isOverrideColorEnabled(void) const = 0;
  133. //! Sets an image which should be displayed on the button when it is in the given state.
  134. /** Only one image-state can be active at a time. Images are drawn below sprites.
  135. If a state is without image it will try to use images from other states as described
  136. in ::EGUI_BUTTON_IMAGE_STATE.
  137. Images are a little less flexible than sprites, but easier to use.
  138. \param state: One of ::EGUI_BUTTON_IMAGE_STATE
  139. \param image: Image to be displayed or NULL to remove the image
  140. \param sourceRect: Source rectangle on the image texture. When width or height are 0 then the full texture-size is used (default). */
  141. virtual void setImage(EGUI_BUTTON_IMAGE_STATE state, video::ITexture *image = 0, const core::rect<s32> &sourceRect = core::rect<s32>(0, 0, 0, 0)) = 0;
  142. //! Sets an image which should be displayed on the button when it is in normal state.
  143. /** This is identical to calling setImage(EGBIS_IMAGE_UP, image); and might be deprecated in future revisions.
  144. \param image: Image to be displayed */
  145. virtual void setImage(video::ITexture *image = 0) = 0;
  146. //! Sets a background image for the button when it is in normal state.
  147. /** This is identical to calling setImage(EGBIS_IMAGE_UP, image, sourceRect); and might be deprecated in future revisions.
  148. \param image: Texture containing the image to be displayed
  149. \param sourceRect: Position in the texture, where the image is located.
  150. When width or height are 0 then the full texture-size is used */
  151. virtual void setImage(video::ITexture *image, const core::rect<s32> &sourceRect) = 0;
  152. //! Sets a background image for the button when it is in pressed state.
  153. /** This is identical to calling setImage(EGBIS_IMAGE_DOWN, image); and might be deprecated in future revisions.
  154. If no images is specified for the pressed state via
  155. setPressedImage(), this image is also drawn in pressed state.
  156. \param image: Image to be displayed */
  157. virtual void setPressedImage(video::ITexture *image = 0) = 0;
  158. //! Sets an image which should be displayed on the button when it is in pressed state.
  159. /** This is identical to calling setImage(EGBIS_IMAGE_DOWN, image, sourceRect); and might be deprecated in future revisions.
  160. \param image: Texture containing the image to be displayed
  161. \param sourceRect: Position in the texture, where the image is located */
  162. virtual void setPressedImage(video::ITexture *image, const core::rect<s32> &sourceRect) = 0;
  163. //! Sets the sprite bank used by the button
  164. /** NOTE: The spritebank itself is _not_ serialized so far. The sprites are serialized.
  165. Which means after loading the gui you still have to set the spritebank manually. */
  166. virtual void setSpriteBank(IGUISpriteBank *bank = 0) = 0;
  167. //! Sets the animated sprite for a specific button state
  168. /** Several sprites can be drawn at the same time.
  169. Sprites can be animated.
  170. Sprites are drawn above the images.
  171. \param index: Number of the sprite within the sprite bank, use -1 for no sprite
  172. \param state: State of the button to set the sprite for
  173. \param index: The sprite number from the current sprite bank
  174. \param color: The color of the sprite
  175. \param loop: True if the animation should loop, false if not
  176. \param scale: True if the sprite should scale to button size, false if not */
  177. virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
  178. video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false, bool scale = false) = 0;
  179. //! Get the sprite-index for the given state or -1 when no sprite is set
  180. virtual s32 getSpriteIndex(EGUI_BUTTON_STATE state) const = 0;
  181. //! Get the sprite color for the given state. Color is only used when a sprite is set.
  182. virtual video::SColor getSpriteColor(EGUI_BUTTON_STATE state) const = 0;
  183. //! Returns if the sprite in the given state does loop
  184. virtual bool getSpriteLoop(EGUI_BUTTON_STATE state) const = 0;
  185. //! Returns if the sprite in the given state is scaled
  186. virtual bool getSpriteScale(EGUI_BUTTON_STATE state) const = 0;
  187. //! Sets if the button should behave like a push button.
  188. /** Which means it can be in two states: Normal or Pressed. With a click on the button,
  189. the user can change the state of the button. */
  190. virtual void setIsPushButton(bool isPushButton = true) = 0;
  191. //! Sets the pressed state of the button if this is a pushbutton
  192. virtual void setPressed(bool pressed = true) = 0;
  193. //! Returns if the button is currently pressed
  194. virtual bool isPressed() const = 0;
  195. //! Sets if the alpha channel should be used for drawing background images on the button (default is false)
  196. virtual void setUseAlphaChannel(bool useAlphaChannel = true) = 0;
  197. //! Returns if the alpha channel should be used for drawing background images on the button
  198. virtual bool isAlphaChannelUsed() const = 0;
  199. //! Returns whether the button is a push button
  200. virtual bool isPushButton() const = 0;
  201. //! Sets if the button should use the skin to draw its border and button face (default is true)
  202. virtual void setDrawBorder(bool border = true) = 0;
  203. //! Returns if the border and button face are being drawn using the skin
  204. virtual bool isDrawingBorder() const = 0;
  205. //! Sets if the button should scale the button images to fit
  206. virtual void setScaleImage(bool scaleImage = true) = 0;
  207. //! Checks whether the button scales the used images
  208. virtual bool isScalingImage() const = 0;
  209. //! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
  210. /** Generated together with event, so info is available in the event-receiver. */
  211. virtual bool getClickShiftState() const = 0;
  212. //! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
  213. /** Generated together with event, so info is available in the event-receiver. */
  214. virtual bool getClickControlState() const = 0;
  215. };
  216. } // end namespace gui
  217. } // end namespace irr