UGDK  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
menu.h
Go to the documentation of this file.
1 #ifndef UGDK_UI_MENU_H_
2 #define UGDK_UI_MENU_H_
3 
4 #include <ugdk/input.h>
5 #include <ugdk/action.h>
6 #include <ugdk/graphic.h>
7 #include <ugdk/ui.h>
8 #include <ugdk/util.h>
10 
11 #include <ugdk/math/integer2D.h>
12 #include <ugdk/structure.h>
13 #include <ugdk/action/scene.h>
14 #include <ugdk/ui/hookpoint.h>
15 
16 #include <string>
17 #include <functional>
18 #include <memory>
19 #include <map>
20 
21 namespace ugdk {
22 namespace ui {
23 
24 typedef std::function<void (Menu*)> MenuCallback;
25 typedef std::map<input::Keycode, MenuCallback> InputCallbacks;
26 
27 class Menu: public ::ugdk::action::Scene {
29  public:
30  Menu(const structure::Box<2>& tree_bounding_box,
31  const math::Vector2D& offset,
33  ~Menu();
34 
35  std::shared_ptr< std::vector<UIElement *> > GetMouseCollision();
36 
37  void AddCallback(const ugdk::input::Keycode& key, const MenuCallback& callback);
38  void SetOptionDrawable(std::unique_ptr<Drawable>&& option_graphic, int index = 0);
39 
40  void AddObject(UIElement* obj);
41  void RemoveObject(UIElement* obj);
42  void RefreshObject(UIElement* obj);
43 
44  void InteractWithFocused();
45 
46  Node* node() { return node_.get(); }
47  const UIElement* focused_element() const { return focused_element_; }
48  const InputCallbacks& input_callbacks() const { return input_callbacks_; }
49 
50  private:
51  void CheckInteraction(const math::Vector2D& mouse_pos);
52  void SelectUIElement(UIElement* target);
53  void FocusNextElement(int offset);
54  void PositionSelectionDrawables();
55 
56  std::unique_ptr<Node> node_;
57  std::shared_ptr<Node> option_node_[2];
58 
59  math::Integer2D last_mouse_position_;
60  UIElement* focused_element_;
61  std::list< UIElement* > uielements_;
62  std::unique_ptr<ObjectTree> objects_tree_;
63  InputCallbacks input_callbacks_;
64  HookPoint hook_;
65 };
66 
67 } // namespace ui
68 } // namespace ugdk
69 
70 #endif // UGDK_UI_MENU_H_
A game scene, or screen.
Definition: scene.h:29
void InteractWithFocused()
Definition: vector2D.h:18
Definition: integer2D.h:20
std::map< input::Keycode, MenuCallback > InputCallbacks
Definition: menu.h:25
void RemoveObject(UIElement *obj)
Definition: animation.h:11
void SetOptionDrawable(std::unique_ptr< Drawable > &&option_graphic, int index=0)
Definition: intervalkdtree.h:21
Definition: menu.h:27
void AddCallback(const ugdk::input::Keycode &key, const MenuCallback &callback)
const InputCallbacks & input_callbacks() const
Definition: menu.h:48
std::shared_ptr< std::vector< UIElement * > > GetMouseCollision()
Node * node()
Definition: menu.h:46
Menu(const structure::Box< 2 > &tree_bounding_box, const math::Vector2D &offset, HookPoint hook=HookPoint::TOP_LEFT)
HookPoint
Definition: hookpoint.h:7
const UIElement * focused_element() const
Definition: menu.h:47
std::function< void(Menu *)> MenuCallback
Definition: menu.h:24
void AddObject(UIElement *obj)
void RefreshObject(UIElement *obj)
Definition: uielement.h:12
Definition: node.h:16
Keycode
The SDL virtual key representation.
Definition: keycode.h:49