annotate NewUI/Core/UIControl.h @ 2035:cef3439340fa

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