annotate NewUI/Core/UIControl.h @ 1823:24b70fa98474

Merge
author Grumpy7
date Wed, 09 Oct 2013 08:09:48 +0200
parents bd899dfd976c
children 6788e58c1715
rev   line source
1815
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
1 #pragma once
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
2 #include <list>
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
3
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
4 class UIControl
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
5 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
6 public:
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
7 virtual void Show() = 0;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
8
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
9 virtual bool Focused() = 0;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
10
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
11 // Events
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
12 virtual bool OnKey(int key)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
13 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
14 for (auto i = children.begin(); i != children.end(); ++i)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
15 if ((*i)->OnKey(key))
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
16 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
17 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
18 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
19
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
20 virtual bool OnMouseLeftClick(int x, int y)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
21 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
22 for (auto i = children.begin(); i != children.end(); ++i)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
23 if ((*i)->OnMouseLeftClick(x, y))
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
24 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
25 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
26 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
27
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
28 virtual bool OnMouseRightClick(int x, int y)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
29 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
30 for (auto i = children.begin(); i != children.end(); ++i)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
31 if ((*i)->OnMouseRightClick(x, y))
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
32 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
33 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
34 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
35
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
36 virtual bool OnMouseEnter()
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
37 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
38 for (auto i = children.begin(); i != children.end(); ++i)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
39 if ((*i)->OnMouseEnter())
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
40 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
41 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
42 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
43
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
44 virtual bool OnMouseLeave()
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
45 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
46 for (auto i = children.begin(); i != children.end(); ++i)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
47 if ((*i)->OnMouseLeave())
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
48 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
49 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
50 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
51
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
52 // Container
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
53 virtual bool AddControl(UIControl *ctrl)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
54 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
55 if (std::find(children.begin(), children.end(), ctrl) == children.end())
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
56 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
57 children.push_back(ctrl);
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
58 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
59 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
60 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
61 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
62
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
63 virtual bool RemoveControl(UIControl *ctrl)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
64 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
65 auto i = std::find(children.begin(), children.end(), ctrl);
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
66
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
67 children.remove(ctrl);
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
68 if (i != children.end())
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
69 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
70 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
71 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
72
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
73 protected:
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
74 std::list<UIControl *> children;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
75 };