|
1 /* $Id$ */ |
|
2 |
|
3 #include "../stdafx.h" |
|
4 #include <stdarg.h> |
|
5 #include "../openttd.h" |
|
6 #include "../debug.h" |
|
7 #include "../functions.h" |
|
8 #include "../map.h" |
|
9 #include "../player.h" |
|
10 #include "../window.h" |
|
11 #include "../gfx.h" |
|
12 #include "../viewport.h" |
|
13 #include "../console.h" |
|
14 #include "../variables.h" |
|
15 #include "../table/sprites.h" |
|
16 #include "../genworld.h" |
|
17 #include "../helpers.hpp" |
|
18 |
|
19 |
|
20 void CompositeWidget::AddWidget(Widget *wd) |
|
21 { |
|
22 WidgetId id = wd->GetId(); |
|
23 std::pair<WidgetIterator, bool> pib = m_widgets.insert(Widgets::value_type(id, wd)); |
|
24 assert(pib.second); |
|
25 } |
|
26 |
|
27 Widget* CompositeWidget::GetWidget(WidgetId id) |
|
28 { |
|
29 WidgetIterator it = m_widgets.find(id); |
|
30 return (it != m_widgets.end()) ? (*it).second : NULL; |
|
31 } |
|
32 |
|
33 Widget* CompositeWidget::RemoveWidget(WidgetId id) |
|
34 { |
|
35 WidgetIterator it = m_widgets.find(id); |
|
36 if (it == m_widgets.end()) return NULL; |
|
37 Widget *wd = (*it).second; |
|
38 assert(wd->m_container == this); |
|
39 wd->m_container = NULL; |
|
40 m_widgets.erase(it); |
|
41 return wd; |
|
42 } |
|
43 |
|
44 /*virtual*/ Widget* CompositeWidget::WidgetFromPt(const Point16 &pt_parent) |
|
45 { |
|
46 Point16 pt_local = pt_parent - TopLeft(); |
|
47 bool inside_me = m_rect.PtInRect(pt_parent); |
|
48 for (WidgetReverseIterator rit = m_widgets.rbegin(); rit != m_widgets.rend(); ++rit) { |
|
49 /* get next child */ |
|
50 Widget *wd_child = (*rit).second; |
|
51 /* ask the child recursively */ |
|
52 Widget *wd = wd_child->WidgetFromPt(pt_local); |
|
53 if (wd != NULL) { |
|
54 /* if the widget we found is inside me it is what we are searching for */ |
|
55 if (inside_me) return wd; |
|
56 /* the point is outside me. The widget is clipped unless it is on-top widget */ |
|
57 if (wd->m_dont_clip) return wd; |
|
58 /* try next child */ |
|
59 } |
|
60 } |
|
61 return inside_me ? this : NULL; |
|
62 } |
|
63 |
|
64 /*virtual*/ void CompositeWidget::Close() |
|
65 { |
|
66 /* mark all children as closed in safe way */ |
|
67 for (WidgetReverseIterator rit_next = m_widgets.rbegin(); rit_next != m_widgets.rend(); ) { |
|
68 /* save the iterator (it can be invalidated) and move forward */ |
|
69 WidgetReverseIterator rit = rit_next++; |
|
70 /* get child */ |
|
71 Widget *wd_child = (*rit).second; |
|
72 /* tell him we are closing */ |
|
73 wd_child->Close(); |
|
74 } |
|
75 /* remove children */ |
|
76 m_widgets.clear(); |
|
77 /* mark self as closed */ |
|
78 super::Close(); |
|
79 } |