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