Merge lp:~nomeata/widelands/help-button-right into lp:widelands

Proposed by Joachim Breitner
Status: Merged
Merged at revision: 6084
Proposed branch: lp:~nomeata/widelands/help-button-right
Merge into: lp:widelands
Diff against target: 251 lines (+98/-17)
5 files modified
src/ui_basic/box.cc (+73/-4)
src/ui_basic/box.h (+5/-1)
src/ui_basic/panel.cc (+5/-0)
src/ui_basic/table.cc (+1/-0)
src/wui/buildingwindow.cc (+14/-12)
To merge this branch: bzr merge lp:~nomeata/widelands/help-button-right
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+81404@code.launchpad.net

Description of the change

Move the help button to the right.

This also fixes the crash introduced in UI::Table and enhances UI::Box.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc 2011-11-06 12:20:01 +0000
+++ src/ui_basic/box.cc 2011-11-06 14:41:25 +0000
@@ -81,7 +81,9 @@
81}81}
8282
83/**83/**
84 * Compute the desired size based on our children.84 * Compute the desired size based on our children. This assumes that the
85 * infinite space is zero, and is later on also re-used to calculate the
86 * space assigned to an infinite space.
85 */87 */
86void Box::update_desired_size()88void Box::update_desired_size()
87{89{
@@ -105,7 +107,8 @@
105 maxbreadth += Scrollbar::Size;107 maxbreadth += Scrollbar::Size;
106 }108 }
107 set_desired_size109 set_desired_size
108 (std::min(totaldepth, m_max_x), std::min(maxbreadth, m_max_y));110 (std::min(totaldepth, m_max_x), // + get_lborder() + get_rborder(),
111 std::min(maxbreadth, m_max_y)); // + get_tborder() + get_bborder());
109 } else {112 } else {
110 if (totaldepth > m_max_y && m_scrolling) {113 if (totaldepth > m_max_y && m_scrolling) {
111 maxbreadth += Scrollbar::Size;114 maxbreadth += Scrollbar::Size;
@@ -188,7 +191,27 @@
188 m_scrollbar = 0;191 m_scrollbar = 0;
189 }192 }
190193
191 // Second pass: Update positions and sizes of all items194 // Second pass: Count number of infinite spaces
195 uint32_t infspace_count = 0;
196 for (uint32_t idx = 0; idx < m_items.size(); ++idx)
197 if (m_items[idx].type == Item::ItemInfSpace)
198 infspace_count++;
199
200 // Third pass: Distribute left over space to all infinite spaces. To
201 // avoid having some pixels left at the end due to rounding errors, we
202 // divide the remaining space by the number of remaining infinite
203 // spaces every time, and not just one.
204 uint32_t max_depths =
205 m_orientation == Horizontal ? get_inner_w() : get_inner_h();
206 for (uint32_t idx = 0; idx < m_items.size(); ++idx)
207 if (m_items[idx].type == Item::ItemInfSpace) {
208 m_items[idx].u.assigned_space =
209 (max_depths - totaldepth) / infspace_count;
210 totaldepth += m_items[idx].u.assigned_space;
211 infspace_count--;
212 }
213
214 // Forth pass: Update positions of all other items
192 update_positions();215 update_positions();
193}216}
194217
@@ -203,7 +226,7 @@
203226
204 for (uint32_t idx = 0; idx < m_items.size(); ++idx) {227 for (uint32_t idx = 0; idx < m_items.size(); ++idx) {
205 uint32_t depth, breadth;228 uint32_t depth, breadth;
206 get_item_desired_size(idx, depth, breadth);229 get_item_size(idx, depth, breadth);
207230
208 if (m_items[idx].type == Item::ItemPanel) {231 if (m_items[idx].type == Item::ItemPanel) {
209 set_item_size232 set_item_size
@@ -261,6 +284,22 @@
261284
262285
263/**286/**
287 * Add some infinite space (to align some buttons to the right)
288*/
289void Box::add_inf_space()
290{
291 Item it;
292
293 it.type = Item::ItemInfSpace;
294 it.u.assigned_space = 0;
295
296 m_items.push_back(it);
297
298 update_desired_size();
299}
300
301
302/**
264 * Retrieve the given item's desired size. depth is the size of the303 * Retrieve the given item's desired size. depth is the size of the
265 * item along the orientation axis, breadth is the size perpendicular304 * item along the orientation axis, breadth is the size perpendicular
266 * to the orientation axis.305 * to the orientation axis.
@@ -286,12 +325,40 @@
286 breadth = 0;325 breadth = 0;
287 break;326 break;
288327
328 case Item::ItemInfSpace:
329 depth = 0;
330 breadth = 0;
331 break;
332
289 default:333 default:
290 throw wexception("Box::get_item_size: bad type %u", it.type);334 throw wexception("Box::get_item_size: bad type %u", it.type);
291 }335 }
292}336}
293337
294/**338/**
339 * Retrieve the given item's size. This differs from get_item_desired_size only
340 * for InfSpace items, at least for now.
341 */
342void Box::get_item_size
343 (uint32_t const idx, uint32_t & depth, uint32_t & breadth)
344{
345 assert(idx < m_items.size());
346
347 Item const & it = m_items[idx];
348
349 switch (it.type) {
350 case Item::ItemInfSpace:
351 depth = it.u.assigned_space;
352 breadth = 0;
353 break;
354
355 default:
356 get_item_desired_size(idx, depth, breadth);
357 }
358
359}
360
361/**
295 * Set the given items actual size.362 * Set the given items actual size.
296 */363 */
297void Box::set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth)364void Box::set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth)
@@ -352,6 +419,8 @@
352 }419 }
353420
354 case Item::ItemSpace:; // no need to do anything421 case Item::ItemSpace:; // no need to do anything
422
423 case Item::ItemInfSpace:; // no need to do anything
355 };424 };
356}425}
357426
358427
=== modified file 'src/ui_basic/box.h'
--- src/ui_basic/box.h 2011-11-06 12:20:01 +0000
+++ src/ui_basic/box.h 2011-11-06 14:41:25 +0000
@@ -57,6 +57,7 @@
5757
58 void add(Panel * panel, uint32_t align, bool fullsize = false);58 void add(Panel * panel, uint32_t align, bool fullsize = false);
59 void add_space(uint32_t space);59 void add_space(uint32_t space);
60 void add_inf_space();
60 bool is_snap_target() const {return true;}61 bool is_snap_target() const {return true;}
6162
62 void set_min_desired_breadth(uint32_t min);63 void set_min_desired_breadth(uint32_t min);
@@ -67,6 +68,7 @@
6768
68private:69private:
69 void get_item_desired_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);70 void get_item_desired_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
71 void get_item_size(uint32_t idx, uint32_t & depth, uint32_t & breadth);
70 void set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth);72 void set_item_size(uint32_t idx, uint32_t depth, uint32_t breadth);
71 void set_item_pos(uint32_t idx, int32_t pos);73 void set_item_pos(uint32_t idx, int32_t pos);
72 void scrollbar_moved(int32_t);74 void scrollbar_moved(int32_t);
@@ -79,7 +81,8 @@
79 struct Item {81 struct Item {
80 enum Type {82 enum Type {
81 ItemPanel,83 ItemPanel,
82 ItemSpace84 ItemSpace,
85 ItemInfSpace
83 };86 };
8487
85 Type type;88 Type type;
@@ -91,6 +94,7 @@
91 bool fullsize;94 bool fullsize;
92 } panel;95 } panel;
93 uint32_t space;96 uint32_t space;
97 uint32_t assigned_space;
94 } u;98 } u;
95 };99 };
96100
97101
=== modified file 'src/ui_basic/panel.cc'
--- src/ui_basic/panel.cc 2011-11-04 22:49:27 +0000
+++ src/ui_basic/panel.cc 2011-11-06 14:41:25 +0000
@@ -311,6 +311,11 @@
311 if (_desired_w == w && _desired_h == h)311 if (_desired_w == w && _desired_h == h)
312 return;312 return;
313313
314 assert(w >= 0);
315 assert(h >= 0);
316 assert(w < 3000);
317 assert(h < 3000);
318
314 _desired_w = w;319 _desired_w = w;
315 _desired_h = h;320 _desired_h = h;
316 if (!get_layout_toplevel() && _parent) {321 if (!get_layout_toplevel() && _parent) {
317322
=== modified file 'src/ui_basic/table.cc'
--- src/ui_basic/table.cc 2011-11-05 16:32:47 +0000
+++ src/ui_basic/table.cc 2011-11-06 14:41:25 +0000
@@ -58,6 +58,7 @@
58 m_last_click_time (-10000),58 m_last_click_time (-10000),
59 m_last_selection (no_selection_index()),59 m_last_selection (no_selection_index()),
60 m_sort_column (0),60 m_sort_column (0),
61 m_total_width (0),
61 m_sort_descending (descending)62 m_sort_descending (descending)
62{63{
63 set_think(false);64 set_think(false);
6465
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2011-11-06 13:26:01 +0000
+++ src/wui/buildingwindow.cc 2011-11-06 14:41:25 +0000
@@ -67,7 +67,7 @@
67 vbox->add(m_tabs, UI::Box::AlignLeft, true);67 vbox->add(m_tabs, UI::Box::AlignLeft, true);
6868
69 m_capsbuttons = new UI::Box(vbox, 0, 0, UI::Box::Horizontal);69 m_capsbuttons = new UI::Box(vbox, 0, 0, UI::Box::Horizontal);
70 vbox->add(m_capsbuttons, UI::Box::AlignLeft);70 vbox->add(m_capsbuttons, UI::Box::AlignLeft, true);
71 // actually create buttons on the first call to think(),71 // actually create buttons on the first call to think(),
72 // so that overriding create_capsbuttons() works72 // so that overriding create_capsbuttons() works
7373
@@ -160,17 +160,6 @@
160 bool const can_see = igbase().can_see(owner_number);160 bool const can_see = igbase().can_see(owner_number);
161 bool const can_act = igbase().can_act(owner_number);161 bool const can_act = igbase().can_act(owner_number);
162162
163 if (m_building.descr().has_help_text())
164 capsbuttons->add
165 (new UI::Callback_Button
166 (capsbuttons, "help",
167 0, 0, 34, 34,
168 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
169 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
170 boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
171 _("Help")),
172 UI::Box::AlignCenter);
173
174 if (can_act) {163 if (can_act) {
175 if (upcast(Widelands::ProductionSite const, productionsite, &m_building))164 if (upcast(Widelands::ProductionSite const, productionsite, &m_building))
176 if (not dynamic_cast<Widelands::MilitarySite const *>(productionsite)) {165 if (not dynamic_cast<Widelands::MilitarySite const *>(productionsite)) {
@@ -274,6 +263,19 @@
274 g_gr->get_picture(PicMod_Game, "pics/menu_goto.png"),263 g_gr->get_picture(PicMod_Game, "pics/menu_goto.png"),
275 boost::bind(&Building_Window::clicked_goto, boost::ref(*this))),264 boost::bind(&Building_Window::clicked_goto, boost::ref(*this))),
276 UI::Box::AlignCenter);265 UI::Box::AlignCenter);
266
267 if (m_building.descr().has_help_text())
268 capsbuttons->add_inf_space();
269 capsbuttons->add
270 (new UI::Callback_Button
271 (capsbuttons, "help",
272 0, 0, 34, 34,
273 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
274 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
275 boost::bind(&Building_Window::help_clicked, boost::ref(*this)),
276 _("Help")),
277 UI::Box::AlignCenter);
278
277 }279 }
278}280}
279281

Subscribers

People subscribed via source and target branches

to status/vote changes: