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