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