1 #ifndef UI_SELECT_H
2 #define UI_SELECT_H
3 
4 #include "action.h"
5 #include "label.h"
6 #include "solid_layout.h"
7 
8 class UISelect;
9 
10 class UIIntSelectAction : public UIAction {
11     int* field;
12     int value;
13     UIAction* action;
14 public:
15     UIIntSelectAction(int* field, int value, UIAction* action = 0);
16 
17     void perform();
18 };
19 
20 class UIOptionLabel : public UILabel {
21     UISelect* select;
22     UIAction* action;
23 public:
24     std::string value;
25 
26     UIOptionLabel(UISelect* select, const std::string& text, const std::string& value, UIAction* action = 0);
27     UIOptionLabel(UISelect* select, const std::string& text, UIAction* action = 0);
28 
29     void click(const vec2& pos);
30 
31     bool submit();
32 };
33 
34 class UISelect : public UISolidLayout {
35     UILabel* label;
36     UILayout* options_layout;
37 
38     UIOptionLabel* selected_option;
39 
40     TextureResource* selectex;
41 public:
42     bool open;
43 
44     UISelect();
45     ~UISelect();
46 
getType()47     int getType() const { return UI_SELECT; };
48 
49     void setUI(UI* ui);
50 
51     void selectOption(UIOptionLabel* option, bool submit = true);
52 
53     UIOptionLabel* getSelectedOption();
54 
55     UIOptionLabel* addOption(const std::string& name, const std::string& value, bool select_option = false);
56     UIOptionLabel* addOption(const std::string& name, UIAction* action, bool select_option = false);
57 
58     void click(const vec2& pos);
59 
60     void elementsAt(const vec2& pos, std::list<UIElement*>& elements_found);
61 
62     void updatePos(const vec2& pos);
63     void update(float dt);
64 
65     void draw();
66 };
67 
68 #endif
69