Merge lp:~nomeata/widelands/bug887737 into lp:widelands

Proposed by Joachim Breitner
Status: Merged
Merged at revision: 6201
Proposed branch: lp:~nomeata/widelands/bug887737
Merge into: lp:widelands
Diff against target: 288 lines (+40/-43)
3 files modified
src/ui_basic/box.cc (+18/-25)
src/ui_basic/box.h (+7/-3)
src/wui/general_statistics_menu.cc (+15/-15)
To merge this branch: bzr merge lp:~nomeata/widelands/bug887737
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+90035@code.launchpad.net
To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

Joachim, thanks! I much appreciate the democratical sense you've shown by implementing this against your own opinion.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/box.cc'
2--- src/ui_basic/box.cc 2011-11-30 21:38:37 +0000
3+++ src/ui_basic/box.cc 2012-01-25 03:00:32 +0000
4@@ -195,7 +195,7 @@
5 // Second pass: Count number of infinite spaces
6 uint32_t infspace_count = 0;
7 for (uint32_t idx = 0; idx < m_items.size(); ++idx)
8- if (m_items[idx].type == Item::ItemInfSpace)
9+ if (m_items[idx].fillspace)
10 infspace_count++;
11
12 // Third pass: Distribute left over space to all infinite spaces. To
13@@ -205,10 +205,10 @@
14 uint32_t max_depths =
15 m_orientation == Horizontal ? get_inner_w() : get_inner_h();
16 for (uint32_t idx = 0; idx < m_items.size(); ++idx)
17- if (m_items[idx].type == Item::ItemInfSpace) {
18- m_items[idx].u.assigned_space =
19+ if (m_items[idx].fillspace) {
20+ m_items[idx].assigned_var_depth =
21 (max_depths - totaldepth) / infspace_count;
22- totaldepth += m_items[idx].u.assigned_space;
23+ totaldepth += m_items[idx].assigned_var_depth;
24 infspace_count--;
25 }
26
27@@ -256,8 +256,11 @@
28 * @param fullsize when true, @p panel will be extended to cover the entire width (or height)
29 * of the box for horizontal (vertical) panels. If false, then @p panel may end up smaller;
30 * in that case, it will be aligned according to @p align
31+ *
32+ * @param fillspace when true, @p panel will be expanded as an infinite space would be. This can be used to make buttons fill a box completely.
33+ *
34 */
35-void Box::add(Panel * const panel, uint32_t const align, bool fullsize)
36+void Box::add(Panel * const panel, uint32_t const align, bool fullsize, bool fillspace)
37 {
38 Item it;
39
40@@ -265,6 +268,8 @@
41 it.u.panel.panel = panel;
42 it.u.panel.align = align;
43 it.u.panel.fullsize = fullsize;
44+ it.fillspace = fillspace;
45+ it.assigned_var_depth = 0;
46
47 m_items.push_back(it);
48
49@@ -281,6 +286,7 @@
50
51 it.type = Item::ItemSpace;
52 it.u.space = space;
53+ it.fillspace = false;
54
55 m_items.push_back(it);
56
57@@ -295,8 +301,10 @@
58 {
59 Item it;
60
61- it.type = Item::ItemInfSpace;
62- it.u.assigned_space = 0;
63+ it.type = Item::ItemSpace;
64+ it.u.space = 0;
65+ it.assigned_var_depth = 0;
66+ it.fillspace = true;
67
68 m_items.push_back(it);
69
70@@ -330,11 +338,6 @@
71 breadth = 0;
72 break;
73
74- case Item::ItemInfSpace:
75- depth = 0;
76- breadth = 0;
77- break;
78-
79 default:
80 throw wexception("Box::get_item_size: bad type %u", it.type);
81 }
82@@ -342,7 +345,7 @@
83
84 /**
85 * Retrieve the given item's size. This differs from get_item_desired_size only
86- * for InfSpace items, at least for now.
87+ * for expanding items, at least for now.
88 */
89 void Box::get_item_size
90 (uint32_t const idx, uint32_t & depth, uint32_t & breadth)
91@@ -351,16 +354,8 @@
92
93 Item const & it = m_items[idx];
94
95- switch (it.type) {
96- case Item::ItemInfSpace:
97- depth = it.u.assigned_space;
98- breadth = 0;
99- break;
100-
101- default:
102- get_item_desired_size(idx, depth, breadth);
103- }
104-
105+ get_item_desired_size(idx, depth, breadth);
106+ depth += it.assigned_var_depth;
107 }
108
109 /**
110@@ -424,8 +419,6 @@
111 }
112
113 case Item::ItemSpace:; // no need to do anything
114-
115- case Item::ItemInfSpace:; // no need to do anything
116 };
117 }
118
119
120=== modified file 'src/ui_basic/box.h'
121--- src/ui_basic/box.h 2011-11-30 21:38:37 +0000
122+++ src/ui_basic/box.h 2012-01-25 03:00:32 +0000
123@@ -55,7 +55,10 @@
124
125 int32_t get_nritems() const {return m_items.size();}
126
127- void add(Panel * panel, uint32_t align, bool fullsize = false);
128+ void add(Panel * panel,
129+ uint32_t align,
130+ bool fullsize = false,
131+ bool fillspace = false);
132 void add_space(uint32_t space);
133 void add_inf_space();
134 bool is_snap_target() const {return true;}
135@@ -82,7 +85,6 @@
136 enum Type {
137 ItemPanel,
138 ItemSpace,
139- ItemInfSpace
140 };
141
142 Type type;
143@@ -94,8 +96,10 @@
144 bool fullsize;
145 } panel;
146 uint32_t space;
147- uint32_t assigned_space;
148 } u;
149+
150+ bool fillspace;
151+ uint32_t assigned_var_depth;
152 };
153
154 bool m_scrolling;
155
156=== modified file 'src/wui/general_statistics_menu.cc'
157--- src/wui/general_statistics_menu.cc 2011-11-30 21:38:37 +0000
158+++ src/wui/general_statistics_menu.cc 2012-01-25 03:00:32 +0000
159@@ -157,11 +157,11 @@
160
161 m_cbs[p - 1] = &cb;
162
163- hbox1->add(&cb, UI::Box::AlignLeft);
164+ hbox1->add(&cb, UI::Box::AlignLeft, false, true);
165 } else // player nr p does not exist
166 m_cbs[p - 1] = 0;
167
168- m_box.add(hbox1, UI::Box::AlignTop);
169+ m_box.add(hbox1, UI::Box::AlignTop, true);
170
171 UI::Box * hbox2 = new UI::Box(&m_box, 0, 0, UI::Box::Horizontal, 0, 0, 1);
172
173@@ -173,7 +173,7 @@
174 g_gr->get_picture(PicMod_Game, "pics/genstats_landsize.png"),
175 _("Land"),
176 &btn);
177- hbox2->add(btn, UI::Box::AlignLeft);
178+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
179
180 m_radiogroup.add_button
181 (hbox2,
182@@ -181,7 +181,7 @@
183 g_gr->get_picture(PicMod_Game, "pics/genstats_nrworkers.png"),
184 _("Workers"),
185 &btn);
186- hbox2->add(btn, UI::Box::AlignLeft);
187+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
188
189 m_radiogroup.add_button
190 (hbox2,
191@@ -189,7 +189,7 @@
192 g_gr->get_picture(PicMod_Game, "pics/genstats_nrbuildings.png"),
193 _("Buildings"),
194 &btn);
195- hbox2->add(btn, UI::Box::AlignLeft);
196+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
197
198 m_radiogroup.add_button
199 (hbox2,
200@@ -197,7 +197,7 @@
201 g_gr->get_picture(PicMod_Game, "pics/genstats_nrwares.png"),
202 _("Wares"),
203 &btn);
204- hbox2->add(btn, UI::Box::AlignLeft);
205+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
206
207 m_radiogroup.add_button
208 (hbox2,
209@@ -205,7 +205,7 @@
210 g_gr->get_picture(PicMod_Game, "pics/genstats_productivity.png"),
211 _("Productivity"),
212 &btn);
213- hbox2->add(btn, UI::Box::AlignLeft);
214+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
215
216 m_radiogroup.add_button
217 (hbox2,
218@@ -213,7 +213,7 @@
219 g_gr->get_picture(PicMod_Game, "pics/genstats_casualties.png"),
220 _("Casualties"),
221 &btn);
222- hbox2->add(btn, UI::Box::AlignLeft);
223+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
224
225 m_radiogroup.add_button
226 (hbox2,
227@@ -221,7 +221,7 @@
228 g_gr->get_picture(PicMod_Game, "pics/genstats_kills.png"),
229 _("Kills"),
230 &btn);
231- hbox2->add(btn, UI::Box::AlignLeft);
232+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
233
234 m_radiogroup.add_button
235 (hbox2,
236@@ -229,7 +229,7 @@
237 g_gr->get_picture(PicMod_Game, "pics/genstats_msites_lost.png"),
238 _("Military buildings lost"),
239 &btn);
240- hbox2->add(btn, UI::Box::AlignLeft);
241+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
242
243 m_radiogroup.add_button
244 (hbox2,
245@@ -237,7 +237,7 @@
246 g_gr->get_picture(PicMod_Game, "pics/genstats_msites_defeated.png"),
247 _("Military buildings defeated"),
248 &btn);
249- hbox2->add(btn, UI::Box::AlignLeft);
250+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
251
252 m_radiogroup.add_button
253 (hbox2,
254@@ -245,7 +245,7 @@
255 g_gr->get_picture(PicMod_Game, "pics/genstats_civil_blds_lost.png"),
256 _("Civilian buildings lost"),
257 &btn);
258- hbox2->add(btn, UI::Box::AlignLeft);
259+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
260
261 m_radiogroup.add_button
262 (hbox2,
263@@ -253,7 +253,7 @@
264 g_gr->get_picture(PicMod_Game, "pics/genstats_militarystrength.png"),
265 _("Military"),
266 &btn);
267- hbox2->add(btn, UI::Box::AlignLeft);
268+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
269
270 if (hook) {
271 m_radiogroup.add_button
272@@ -262,14 +262,14 @@
273 g_gr->get_picture(PicMod_Game, cs_pic),
274 cs_name.c_str(),
275 &btn);
276- hbox2->add(btn, UI::Box::AlignLeft);
277+ hbox2->add(btn, UI::Box::AlignLeft, false, true);
278 }
279
280 m_radiogroup.set_state(m_selected_information);
281 m_radiogroup.changedto.connect
282 (boost::bind(&General_Statistics_Menu::radiogroup_changed, this, _1));
283
284- m_box.add(hbox2, UI::Box::AlignTop);
285+ m_box.add(hbox2, UI::Box::AlignTop, true);
286
287 m_box.add
288 (new WUIPlot_Area_Slider

Subscribers

People subscribed via source and target branches

to status/vote changes: