annotate NewUI/Core/UIControl.h @ 2492:85a12b497698

BelongsToSupertype() clear
author Ritor1
date Mon, 15 Sep 2014 17:30:19 +0600
parents 62a27b2cfcc2
children
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
2054
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
13 virtual bool OnKey(int key) {return DefaultOnKey(key);}
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
14 virtual bool OnMouseLeftClick(int x, int y) {return DefaultOnMouseLeftClick(x, y);}
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
15 virtual bool OnMouseRightClick(int x, int y) {return DefaultOnMouseRightClick(x, y);}
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
16 virtual bool OnMouseEnter() {return DefaultOnMouseEnter();}
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
17 virtual bool OnMouseLeave() {return DefaultOnMouseLeave();}
1815
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
18
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
19 // Container
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
20 virtual bool AddControl(UIControl *ctrl)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
21 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
22 if (std::find(children.begin(), children.end(), ctrl) == children.end())
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
23 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
24 children.push_back(ctrl);
2054
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
25 ctrl->parent = this;
1815
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
26 return true;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
27 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
28 return false;
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
29 }
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
30
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
31 virtual bool RemoveControl(UIControl *ctrl)
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
32 {
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
33 auto i = std::find(children.begin(), children.end(), ctrl);
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
34
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
35 children.remove(ctrl);
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
36 if (i != children.end())
2054
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
37 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
38 ctrl->parent = nullptr;
1815
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
39 return true;
2054
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
40 }
1815
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 protected:
2054
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
45 UIControl *parent;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
46 std::list<UIControl *> children;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
47
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
48
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
49 bool DefaultOnKey(int key)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
50 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
51 for (auto i = children.begin(); i != children.end(); ++i)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
52 if ((*i)->OnKey(key))
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
53 return true;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
54 return false;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
55 }
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
56
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
57 bool DefaultOnMouseLeftClick(int x, int y)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
58 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
59 for (auto i = children.begin(); i != children.end(); ++i)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
60 if ((*i)->OnMouseLeftClick(x, y))
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
61 return true;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
62 return false;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
63 }
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
64
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
65 bool DefaultOnMouseRightClick(int x, int y)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
66 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
67 for (auto i = children.begin(); i != children.end(); ++i)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
68 if ((*i)->OnMouseRightClick(x, y))
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
69 return true;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
70 return false;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
71 }
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
72
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
73 bool DefaultOnMouseEnter()
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
74 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
75 for (auto i = children.begin(); i != children.end(); ++i)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
76 if ((*i)->OnMouseEnter())
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
77 return true;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
78 return false;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
79 }
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
80
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
81 bool DefaultOnMouseLeave()
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
82 {
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
83 for (auto i = children.begin(); i != children.end(); ++i)
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
84 if ((*i)->OnMouseLeave())
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
85 return true;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
86 return false;
62a27b2cfcc2 Player.swig
Nomad
parents: 1824
diff changeset
87 }
1815
bd899dfd976c MainMenuWindow
Nomad
parents:
diff changeset
88 };