base_button.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*************************************************************************/
  2. /* base_button.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef BASE_BUTTON_H
  30. #define BASE_BUTTON_H
  31. #include "scene/gui/control.h"
  32. /**
  33. @author Juan Linietsky <[email protected]>
  34. */
  35. class ButtonGroup;
  36. class BaseButton : public Control {
  37. OBJ_TYPE( BaseButton, Control );
  38. bool toggle_mode;
  39. struct Status {
  40. bool pressed;
  41. bool hovering;
  42. bool press_attempt;
  43. bool pressing_inside;
  44. bool disabled;
  45. bool click_on_press;
  46. int pressing_button;
  47. } status;
  48. ButtonGroup *group;
  49. protected:
  50. enum DrawMode {
  51. DRAW_NORMAL,
  52. DRAW_PRESSED,
  53. DRAW_HOVER,
  54. DRAW_DISABLED,
  55. };
  56. DrawMode get_draw_mode() const;
  57. virtual void pressed();
  58. virtual void toggled(bool p_pressed);
  59. static void _bind_methods();
  60. virtual void _input_event(InputEvent p_event);
  61. void _notification(int p_what);
  62. public:
  63. /* Signals */
  64. bool is_pressed() const; ///< return wether button is pressed (toggled in)
  65. bool is_pressing() const; ///< return wether button is pressed (toggled in)
  66. bool is_hovered() const;
  67. void set_pressed(bool p_pressed); ///only works in toggle mode
  68. void set_toggle_mode(bool p_on);
  69. bool is_toggle_mode() const;
  70. void set_disabled(bool p_disabled);
  71. bool is_disabled() const;
  72. void set_click_on_press(bool p_click_on_press);
  73. bool get_click_on_press() const;
  74. BaseButton();
  75. ~BaseButton();
  76. };
  77. #endif