Mercurial > mm7
annotate NewUI/Core/UIControl.h @ 2445:b10125a9c772
fix crash in keyboard option
author | Ritor1 |
---|---|
date | Thu, 24 Jul 2014 12:44:14 +0600 |
parents | 62a27b2cfcc2 |
children |
rev | line source |
---|---|
1815 | 1 #pragma once |
2 #include <list> | |
1824
6788e58c1715
adding <algorithm> to uicontrol to fix build issue with vs2008
Grumpy7
parents:
1815
diff
changeset
|
3 #include <algorithm> |
1815 | 4 |
5 class UIControl | |
6 { | |
7 public: | |
8 virtual void Show() = 0; | |
9 | |
10 virtual bool Focused() = 0; | |
11 | |
12 // Events | |
2054 | 13 virtual bool OnKey(int key) {return DefaultOnKey(key);} |
14 virtual bool OnMouseLeftClick(int x, int y) {return DefaultOnMouseLeftClick(x, y);} | |
15 virtual bool OnMouseRightClick(int x, int y) {return DefaultOnMouseRightClick(x, y);} | |
16 virtual bool OnMouseEnter() {return DefaultOnMouseEnter();} | |
17 virtual bool OnMouseLeave() {return DefaultOnMouseLeave();} | |
1815 | 18 |
19 // Container | |
20 virtual bool AddControl(UIControl *ctrl) | |
21 { | |
22 if (std::find(children.begin(), children.end(), ctrl) == children.end()) | |
23 { | |
24 children.push_back(ctrl); | |
2054 | 25 ctrl->parent = this; |
1815 | 26 return true; |
27 } | |
28 return false; | |
29 } | |
30 | |
31 virtual bool RemoveControl(UIControl *ctrl) | |
32 { | |
33 auto i = std::find(children.begin(), children.end(), ctrl); | |
34 | |
35 children.remove(ctrl); | |
36 if (i != children.end()) | |
2054 | 37 { |
38 ctrl->parent = nullptr; | |
1815 | 39 return true; |
2054 | 40 } |
1815 | 41 return false; |
42 } | |
43 | |
44 protected: | |
2054 | 45 UIControl *parent; |
46 std::list<UIControl *> children; | |
47 | |
48 | |
49 bool DefaultOnKey(int key) | |
50 { | |
51 for (auto i = children.begin(); i != children.end(); ++i) | |
52 if ((*i)->OnKey(key)) | |
53 return true; | |
54 return false; | |
55 } | |
56 | |
57 bool DefaultOnMouseLeftClick(int x, int y) | |
58 { | |
59 for (auto i = children.begin(); i != children.end(); ++i) | |
60 if ((*i)->OnMouseLeftClick(x, y)) | |
61 return true; | |
62 return false; | |
63 } | |
64 | |
65 bool DefaultOnMouseRightClick(int x, int y) | |
66 { | |
67 for (auto i = children.begin(); i != children.end(); ++i) | |
68 if ((*i)->OnMouseRightClick(x, y)) | |
69 return true; | |
70 return false; | |
71 } | |
72 | |
73 bool DefaultOnMouseEnter() | |
74 { | |
75 for (auto i = children.begin(); i != children.end(); ++i) | |
76 if ((*i)->OnMouseEnter()) | |
77 return true; | |
78 return false; | |
79 } | |
80 | |
81 bool DefaultOnMouseLeave() | |
82 { | |
83 for (auto i = children.begin(); i != children.end(); ++i) | |
84 if ((*i)->OnMouseLeave()) | |
85 return true; | |
86 return false; | |
87 } | |
1815 | 88 }; |