Mercurial > mm7
comparison NewUI/Core/UIControl.h @ 2054:62a27b2cfcc2
Player.swig
author | Nomad |
---|---|
date | Sat, 30 Nov 2013 21:00:37 +0200 |
parents | 6788e58c1715 |
children |
comparison
equal
deleted
inserted
replaced
2053:64e23bf9d27e | 2054:62a27b2cfcc2 |
---|---|
8 virtual void Show() = 0; | 8 virtual void Show() = 0; |
9 | 9 |
10 virtual bool Focused() = 0; | 10 virtual bool Focused() = 0; |
11 | 11 |
12 // Events | 12 // Events |
13 virtual bool OnKey(int key) | 13 virtual bool OnKey(int key) {return DefaultOnKey(key);} |
14 { | 14 virtual bool OnMouseLeftClick(int x, int y) {return DefaultOnMouseLeftClick(x, y);} |
15 for (auto i = children.begin(); i != children.end(); ++i) | 15 virtual bool OnMouseRightClick(int x, int y) {return DefaultOnMouseRightClick(x, y);} |
16 if ((*i)->OnKey(key)) | 16 virtual bool OnMouseEnter() {return DefaultOnMouseEnter();} |
17 return true; | 17 virtual bool OnMouseLeave() {return DefaultOnMouseLeave();} |
18 return false; | |
19 } | |
20 | |
21 virtual bool OnMouseLeftClick(int x, int y) | |
22 { | |
23 for (auto i = children.begin(); i != children.end(); ++i) | |
24 if ((*i)->OnMouseLeftClick(x, y)) | |
25 return true; | |
26 return false; | |
27 } | |
28 | |
29 virtual bool OnMouseRightClick(int x, int y) | |
30 { | |
31 for (auto i = children.begin(); i != children.end(); ++i) | |
32 if ((*i)->OnMouseRightClick(x, y)) | |
33 return true; | |
34 return false; | |
35 } | |
36 | |
37 virtual bool OnMouseEnter() | |
38 { | |
39 for (auto i = children.begin(); i != children.end(); ++i) | |
40 if ((*i)->OnMouseEnter()) | |
41 return true; | |
42 return false; | |
43 } | |
44 | |
45 virtual bool OnMouseLeave() | |
46 { | |
47 for (auto i = children.begin(); i != children.end(); ++i) | |
48 if ((*i)->OnMouseLeave()) | |
49 return true; | |
50 return false; | |
51 } | |
52 | 18 |
53 // Container | 19 // Container |
54 virtual bool AddControl(UIControl *ctrl) | 20 virtual bool AddControl(UIControl *ctrl) |
55 { | 21 { |
56 if (std::find(children.begin(), children.end(), ctrl) == children.end()) | 22 if (std::find(children.begin(), children.end(), ctrl) == children.end()) |
57 { | 23 { |
58 children.push_back(ctrl); | 24 children.push_back(ctrl); |
25 ctrl->parent = this; | |
59 return true; | 26 return true; |
60 } | 27 } |
61 return false; | 28 return false; |
62 } | 29 } |
63 | 30 |
65 { | 32 { |
66 auto i = std::find(children.begin(), children.end(), ctrl); | 33 auto i = std::find(children.begin(), children.end(), ctrl); |
67 | 34 |
68 children.remove(ctrl); | 35 children.remove(ctrl); |
69 if (i != children.end()) | 36 if (i != children.end()) |
37 { | |
38 ctrl->parent = nullptr; | |
70 return true; | 39 return true; |
40 } | |
71 return false; | 41 return false; |
72 } | 42 } |
73 | 43 |
74 protected: | 44 protected: |
75 std::list<UIControl *> children; | 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 } | |
76 }; | 88 }; |