annotate GUI/NewUI/Core/UIControl.h @ 2537:5c03054c72b8

VS 2013 project
author a.parshin
date Sat, 09 May 2015 11:29:28 +0200
parents 0ff6a9e9bf7f
children
rev   line source
2501
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
1 #pragma once
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
2 #include <list>
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
3 #include <algorithm>
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
4
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
5 class UIControl
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
6 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
7 public:
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
8 virtual void Show() = 0;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
9
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
10 virtual bool Focused() = 0;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
11
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
12 // Events
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
13 virtual bool OnKey(int key) {return DefaultOnKey(key);}
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
14 virtual bool OnMouseLeftClick(int x, int y) {return DefaultOnMouseLeftClick(x, y);}
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
15 virtual bool OnMouseRightClick(int x, int y) {return DefaultOnMouseRightClick(x, y);}
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
16 virtual bool OnMouseEnter() {return DefaultOnMouseEnter();}
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
17 virtual bool OnMouseLeave() {return DefaultOnMouseLeave();}
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
18
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
19 // Container
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
20 virtual bool AddControl(UIControl *ctrl)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
21 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
22 if (std::find(children.begin(), children.end(), ctrl) == children.end())
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
23 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
24 children.push_back(ctrl);
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
25 ctrl->parent = this;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
26 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
27 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
28 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
29 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
30
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
31 virtual bool RemoveControl(UIControl *ctrl)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
32 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
33 auto i = std::find(children.begin(), children.end(), ctrl);
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
34
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
35 children.remove(ctrl);
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
36 if (i != children.end())
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
37 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
38 ctrl->parent = nullptr;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
39 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
40 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
41 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
42 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
43
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
44 protected:
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
45 UIControl *parent;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
46 std::list<UIControl *> children;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
47
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
48
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
49 bool DefaultOnKey(int key)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
50 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
51 for (auto i = children.begin(); i != children.end(); ++i)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
52 if ((*i)->OnKey(key))
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
53 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
54 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
55 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
56
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
57 bool DefaultOnMouseLeftClick(int x, int y)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
58 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
59 for (auto i = children.begin(); i != children.end(); ++i)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
60 if ((*i)->OnMouseLeftClick(x, y))
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
61 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
62 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
63 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
64
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
65 bool DefaultOnMouseRightClick(int x, int y)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
66 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
67 for (auto i = children.begin(); i != children.end(); ++i)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
68 if ((*i)->OnMouseRightClick(x, y))
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
69 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
70 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
71 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
72
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
73 bool DefaultOnMouseEnter()
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
74 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
75 for (auto i = children.begin(); i != children.end(); ++i)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
76 if ((*i)->OnMouseEnter())
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
77 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
78 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
79 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
80
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
81 bool DefaultOnMouseLeave()
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
82 {
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
83 for (auto i = children.begin(); i != children.end(); ++i)
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
84 if ((*i)->OnMouseLeave())
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
85 return true;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
86 return false;
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
87 }
0ff6a9e9bf7f GUI folger
Ritor1
parents:
diff changeset
88 };