base_button.h
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-2016 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 
32 #include "scene/gui/control.h"
38 class ButtonGroup;
39 
40 class BaseButton : public Control {
41 
42  OBJ_TYPE( BaseButton, Control );
43 
44  bool toggle_mode;
45 
46  struct Status {
47 
48  bool pressed;
49  bool hovering;
50  bool press_attempt;
51  bool pressing_inside;
52 
53  bool disabled;
54  bool click_on_press;
55  int pressing_button;
56 
57  } status;
58 
59  ButtonGroup *group;
60 
61 
62 protected:
63 
64 
65 
66 
67  virtual void pressed();
68  virtual void toggled(bool p_pressed);
69  static void _bind_methods();
70  virtual void _input_event(InputEvent p_event);
71  void _notification(int p_what);
72 
73 public:
74 
75  enum DrawMode {
76  DRAW_NORMAL,
77  DRAW_PRESSED,
78  DRAW_HOVER,
79  DRAW_DISABLED,
80  };
81 
82  DrawMode get_draw_mode() const;
83 
84  /* Signals */
85 
86  bool is_pressed() const;
87  bool is_pressing() const;
88  bool is_hovered() const;
89 
90  void set_pressed(bool p_pressed);
91  void set_toggle_mode(bool p_on);
92  bool is_toggle_mode() const;
93 
94  void set_disabled(bool p_disabled);
95  bool is_disabled() const;
96 
97  void set_click_on_press(bool p_click_on_press);
98  bool get_click_on_press() const;
99 
100 
101  BaseButton();
102  ~BaseButton();
103 
104 };
105 
106 VARIANT_ENUM_CAST( BaseButton::DrawMode );
107 
108 #endif
bool is_pressed() const
return wether button is pressed (toggled in)
Definition: base_button.cpp:316
Definition: base_button.h:40
Definition: input_event.h:263
bool is_pressing() const
return wether button is pressed (toggled in)
Definition: base_button.cpp:311
Definition: button_group.h:37
void set_toggle_mode(bool p_on)
only works in toggle mode
Definition: base_button.cpp:360
Definition: control.h:47