← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/fix_huge_boxes into lp:widelands

 

SirVer has proposed merging lp:~widelands-dev/widelands/fix_huge_boxes into lp:widelands.

Commit message:
Fix ptr = 0 to *ptr = 0

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1538685 in widelands: "Some windows are huge"
  https://bugs.launchpad.net/widelands/+bug/1538685

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fix_huge_boxes/+merge/284176

Fixes huge boxes.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fix_huge_boxes into lp:widelands.
=== modified file 'src/ui_basic/box.cc'
--- src/ui_basic/box.cc	2016-01-27 08:06:40 +0000
+++ src/ui_basic/box.cc	2016-01-27 19:16:27 +0000
@@ -134,14 +134,14 @@
 	int totaldepth = 0;
 
 	for (size_t idx = 0; idx < m_items.size(); ++idx) {
-		int depth, tmp;
-		get_item_desired_size(idx, &depth, &tmp);
-
+		int depth, unused;
+		get_item_desired_size(idx, &depth, &unused);
 		totaldepth += depth;
 	}
 
-	if (!m_items.empty())
+	if (!m_items.empty()) {
 		totaldepth += (m_items.size() - 1) * m_inner_spacing;
+	}
 
 	bool needscrollbar = false;
 	if (m_orientation == Horizontal) {
@@ -170,27 +170,24 @@
 			sb_h = get_inner_h();
 			pagesize = get_inner_h() - Scrollbar::Size;
 		}
-		if (!m_scrollbar) {
-			m_scrollbar = new Scrollbar
-					(this, sb_x, sb_y, sb_w,
-					 sb_h, m_orientation == Horizontal);
+		if (m_scrollbar == nullptr) {
+			m_scrollbar.reset(
+			   new Scrollbar(this, sb_x, sb_y, sb_w, sb_h, m_orientation == Horizontal));
 			m_scrollbar->moved.connect(boost::bind(&Box::scrollbar_moved, this, _1));
 		} else {
 			m_scrollbar->set_pos(Point(sb_x, sb_y));
 			m_scrollbar->set_size(sb_w, sb_h);
 		}
-
 		m_scrollbar->set_steps(totaldepth - pagesize);
 		m_scrollbar->set_singlestepsize(Scrollbar::Size);
 		m_scrollbar->set_pagesize(pagesize);
 	} else {
-		delete m_scrollbar;
-		m_scrollbar = nullptr;
+		m_scrollbar.reset();
 	}
 
 	// Second pass: Count number of infinite spaces
-	uint32_t infspace_count = 0;
-	for (uint32_t idx = 0; idx < m_items.size(); ++idx)
+	int infspace_count = 0;
+	for (size_t idx = 0; idx < m_items.size(); ++idx)
 		if (m_items[idx].fillspace)
 			infspace_count++;
 
@@ -198,9 +195,8 @@
 	// avoid having some pixels left at the end due to rounding errors, we
 	// divide the remaining space by the number of remaining infinite
 	// spaces every time, and not just one.
-	uint32_t max_depths =
-		m_orientation == Horizontal ? get_inner_w() : get_inner_h();
-	for (uint32_t idx = 0; idx < m_items.size(); ++idx)
+	int max_depths = m_orientation == Horizontal ? get_inner_w() : get_inner_h();
+	for (size_t idx = 0; idx < m_items.size(); ++idx)
 		if (m_items[idx].fillspace) {
 			assert(infspace_count > 0);
 			m_items[idx].assigned_var_depth =
@@ -334,7 +330,7 @@
 
 	case Item::ItemSpace:
 		*depth = it.u.space;
-		breadth = 0;
+		*breadth = 0;
 		break;
 	}
 }

=== modified file 'src/ui_basic/box.h'
--- src/ui_basic/box.h	2016-01-27 08:06:40 +0000
+++ src/ui_basic/box.h	2016-01-27 19:16:27 +0000
@@ -20,12 +20,13 @@
 #ifndef WL_UI_BASIC_BOX_H
 #define WL_UI_BASIC_BOX_H
 
+#include <memory>
 #include <vector>
 
 #include "ui_basic/panel.h"
+#include "ui_basic/scrollbar.h"
 
 namespace UI {
-struct Scrollbar;
 
 /**
  * A layouting panel that holds a number of child panels.
@@ -104,7 +105,7 @@
 	};
 
 	bool m_scrolling;
-	Scrollbar * m_scrollbar;
+	std::unique_ptr<Scrollbar> m_scrollbar;
 	uint32_t m_orientation;
 	uint32_t m_mindesiredbreadth;
 	uint32_t m_inner_spacing;

=== modified file 'src/ui_basic/listselect.cc'
--- src/ui_basic/listselect.cc	2015-11-08 17:31:06 +0000
+++ src/ui_basic/listselect.cc	2016-01-27 19:16:27 +0000
@@ -355,13 +355,10 @@
 	dst.brighten_rect(Rect(Point(0, 0), get_w(), get_h()), ms_darken_value);
 
 	while (idx < m_entry_records.size()) {
-		assert
-			(get_h()
-			 <
-			 static_cast<int32_t>(std::numeric_limits<int32_t>::max()));
-
-		if (y >= static_cast<int32_t>(get_h()))
+		assert(get_h() < std::numeric_limits<int32_t>::max());
+		if (y >= get_h()) {
 			break;
+		}
 
 		const EntryRecord & er = *m_entry_records[idx];
 


Follow ups