author | KUDr |
Sun, 18 Feb 2007 19:55:35 +0000 | |
branch | cpp_gui |
changeset 6260 | 740c702f6871 |
parent 6258 | a2f86b8fd99b |
child 6264 | 9fc3b5467396 |
permissions | -rw-r--r-- |
6258
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
1 |
/* $Id$ */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
2 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
3 |
#include "../stdafx.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
4 |
#include <stdarg.h> |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
5 |
#include "../openttd.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
6 |
#include "../debug.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
7 |
#include "../functions.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
8 |
#include "../map.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
9 |
#include "../player.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
10 |
#include "../window.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
11 |
#include "../gfx.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
12 |
#include "../viewport.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
13 |
#include "../console.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
14 |
#include "../variables.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
15 |
#include "../table/sprites.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
16 |
#include "../genworld.h" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
17 |
#include "../helpers.hpp" |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
18 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
19 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
20 |
void CompositeWidget::AddWidget(Widget *wd) |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
21 |
{ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
22 |
WidgetId id = wd->GetId(); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
23 |
std::pair<WidgetIterator, bool> pib = m_widgets.insert(Widgets::value_type(id, wd)); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
24 |
assert(pib.second); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
25 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
26 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
27 |
Widget* CompositeWidget::GetWidget(WidgetId id) |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
28 |
{ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
29 |
WidgetIterator it = m_widgets.find(id); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
30 |
return (it != m_widgets.end()) ? (*it).second : NULL; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
31 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
32 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
33 |
Widget* CompositeWidget::RemoveWidget(WidgetId id) |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
34 |
{ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
35 |
WidgetIterator it = m_widgets.find(id); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
36 |
if (it == m_widgets.end()) return NULL; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
37 |
Widget *wd = (*it).second; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
38 |
assert(wd->m_container == this); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
39 |
wd->m_container = NULL; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
40 |
m_widgets.erase(it); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
41 |
return wd; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
42 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
43 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
44 |
/*virtual*/ Widget* CompositeWidget::WidgetFromPt(const Point16 &pt_parent) |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
45 |
{ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
46 |
Point16 pt_local = pt_parent - TopLeft(); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
47 |
bool inside_me = m_rect.PtInRect(pt_parent); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
48 |
for (WidgetReverseIterator rit = m_widgets.rbegin(); rit != m_widgets.rend(); ++rit) { |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
49 |
/* get next child */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
50 |
Widget *wd_child = (*rit).second; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
51 |
/* ask the child recursively */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
52 |
Widget *wd = wd_child->WidgetFromPt(pt_local); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
53 |
if (wd != NULL) { |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
54 |
/* if the widget we found is inside me it is what we are searching for */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
55 |
if (inside_me) return wd; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
56 |
/* the point is outside me. The widget is clipped unless it is on-top widget */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
57 |
if (wd->m_dont_clip) return wd; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
58 |
/* try next child */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
59 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
60 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
61 |
return inside_me ? this : NULL; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
62 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
63 |
|
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
64 |
/*virtual*/ void CompositeWidget::Close() |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
65 |
{ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
66 |
/* mark all children as closed in safe way */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
67 |
for (WidgetReverseIterator rit_next = m_widgets.rbegin(); rit_next != m_widgets.rend(); ) { |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
68 |
/* save the iterator (it can be invalidated) and move forward */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
69 |
WidgetReverseIterator rit = rit_next++; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
70 |
/* get child */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
71 |
Widget *wd_child = (*rit).second; |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
72 |
/* tell him we are closing */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
73 |
wd_child->Close(); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
74 |
} |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
75 |
/* remove children */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
76 |
m_widgets.clear(); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
77 |
/* mark self as closed */ |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
78 |
super::Close(); |
a2f86b8fd99b
(svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents:
diff
changeset
|
79 |
} |
6260
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
80 |
|
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
81 |
/*virtual*/ bool CompositeWidget::OnLeftClick(WindowEvent *ev) |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
82 |
{ |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
83 |
//Point16 pt(ev->we.click.pt.x, ev->we.click.pt.y); |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
84 |
Widget *wd_child = WidgetFromPt(ev->we.click.pt); |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
85 |
if (wd_child != NULL) { |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
86 |
return wd_child->OnLeftClick(ev); |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
87 |
} |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
88 |
return false; |
740c702f6871
(svn r8804) [cpp_gui] -Codechange: BaseWindow now inherits from CompositeWidget (with no benefits yet)
KUDr
parents:
6258
diff
changeset
|
89 |
} |