1 /*************************************************************************/
2 /*  button_array.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 BUTTON_ARRAY_H
31 #define BUTTON_ARRAY_H
32 
33 #include "scene/gui/control.h"
34 
35 class ButtonArray : public Control {
36 
37 	OBJ_TYPE(ButtonArray, Control);
38 
39 public:
40 	enum Align {
41 		ALIGN_BEGIN,
42 		ALIGN_CENTER,
43 		ALIGN_END,
44 		ALIGN_FILL,
45 		ALIGN_EXPAND_FILL
46 	};
47 
48 private:
49 	Orientation orientation;
50 	Align align;
51 
52 	struct Button {
53 
54 		String text;
55 		String xl_text;
56 		String tooltip;
57 		Ref<Texture> icon;
58 		mutable int _ms_cache;
59 		mutable int _pos_cache;
60 		mutable int _size_cache;
61 	};
62 
63 	int selected;
64 	int hover;
65 	bool flat;
66 	double min_button_size;
67 
68 	Vector<Button> buttons;
69 
70 protected:
71 	bool _set(const StringName &p_name, const Variant &p_value);
72 	bool _get(const StringName &p_name, Variant &r_ret) const;
73 	void _get_property_list(List<PropertyInfo> *p_list) const;
74 
75 	void _notification(int p_what);
76 	static void _bind_methods();
77 
78 public:
79 	void _input_event(const InputEvent &p_event);
80 
81 	void set_align(Align p_align);
82 	Align get_align() const;
83 
84 	void set_flat(bool p_flat);
85 	bool is_flat() const;
86 
87 	void add_button(const String &p_button, const String &p_tooltip = "");
88 	void add_icon_button(const Ref<Texture> &p_icon, const String &p_button = "", const String &p_tooltip = "");
89 
90 	void set_button_text(int p_button, const String &p_text);
91 	void set_button_tooltip(int p_button, const String &p_text);
92 	void set_button_icon(int p_button, const Ref<Texture> &p_icon);
93 
94 	String get_button_text(int p_button) const;
95 	String get_button_tooltip(int p_button) const;
96 	Ref<Texture> get_button_icon(int p_button) const;
97 
98 	int get_selected() const;
99 	int get_hovered() const;
100 	void set_selected(int p_selected);
101 
102 	int get_button_count() const;
103 
104 	void erase_button(int p_button);
105 	void clear();
106 
107 	virtual Size2 get_minimum_size() const;
108 
109 	virtual void get_translatable_strings(List<String> *p_strings) const;
110 	virtual String get_tooltip(const Point2 &p_pos) const;
111 
112 	ButtonArray(Orientation p_orientation = HORIZONTAL);
113 };
114 
115 class HButtonArray : public ButtonArray {
116 	OBJ_TYPE(HButtonArray, ButtonArray);
117 
118 public:
HButtonArray()119 	HButtonArray() :
120 			ButtonArray(HORIZONTAL){};
121 };
122 
123 class VButtonArray : public ButtonArray {
124 	OBJ_TYPE(VButtonArray, ButtonArray);
125 
126 public:
VButtonArray()127 	VButtonArray() :
128 			ButtonArray(VERTICAL){};
129 };
130 
131 #endif // BUTTON_ARRAY_H
132