← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/plot-improvements into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/plot-improvements into lp:widelands with lp:~nomeata/widelands/statistics-menu-settings-persistent as a prerequisite.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #536543 in widelands: "Add "whole game" to the time axis in statistics"
  https://bugs.launchpad.net/widelands/+bug/536543
  Bug #672085 in widelands: "New stock menu layout too high for small resolutions"
  https://bugs.launchpad.net/widelands/+bug/672085
  Bug #886709 in widelands: "new slider statistics menu opens in wrong position or so"
  https://bugs.launchpad.net/widelands/+bug/886709

For more details, see:
https://code.launchpad.net/~nomeata/widelands/plot-improvements/+merge/81412

This fixes a small visual bug with the slider, whereas if the slider widget is resized, the position of the cursor was not recalculated.
-- 
https://code.launchpad.net/~nomeata/widelands/plot-improvements/+merge/81412
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/plot-improvements into lp:widelands.
=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc	2011-11-06 12:23:20 +0000
+++ src/ui_basic/slider.cc	2011-11-06 18:28:26 +0000
@@ -71,13 +71,10 @@
 	m_x_gap          (x_gap),
 	m_y_gap          (y_gap),
 	m_bar_size       (bar_size),
-	m_cursor_pos
-		(m_value <= m_min_value ? 0              :
-		 m_value >= m_max_value ? get_bar_size() :
-		 (m_value - m_min_value) * get_bar_size() / (m_max_value - m_min_value)),
 	m_cursor_size (cursor_size)
 {
 	set_think(false);
+	calc_cursor_pos();
 }
 
 void Slider::set_value(int32_t new_value)
@@ -86,17 +83,32 @@
 
 	if (new_value != m_value) {
 		m_value = new_value;
+		calc_cursor_pos();
+		send_value_changed();
+		update();
+	}
+}
+
+void Slider::calc_cursor_pos() {
+	if (m_max_value == m_min_value) {
+		m_cursor_pos = m_min_value;
+	} else if (m_value == m_min_value) {
+		m_cursor_pos = 0;
+	} else if (m_value == m_max_value) {
+		m_cursor_pos = get_bar_size();
+	} else {
 		m_cursor_pos =
-			m_value <= m_min_value ? 0              :
-			m_value >= m_max_value ? get_bar_size() :
 			(m_value - m_min_value) * get_bar_size()
 			/
 			(m_max_value - m_min_value);
-		send_value_changed();
-		update();
 	}
 }
 
+void Slider::layout() {
+	Panel::layout();
+	calc_cursor_pos();
+}
+
 /**
  * \brief Sets max value.
  *
@@ -245,18 +257,7 @@
 		m_pressed = false;
 
 		//  cursor position: align to integer value
-		if (m_max_value == m_min_value) {
-			m_cursor_pos = m_min_value;
-		} else if (m_value == m_min_value) {
-			m_cursor_pos = 0;
-		} else if (m_value == m_max_value) {
-			m_cursor_pos = get_bar_size();
-		} else {
-			m_cursor_pos =
-				(m_value - m_min_value) * get_bar_size()
-				/
-				(m_max_value - m_min_value);
-		}
+		calc_cursor_pos();
 
 		update();
 	}
@@ -464,9 +465,9 @@
 }
 
 void HorizontalSlider::layout() {
-	Slider::layout();
 	m_y_gap = get_h() / 2 - 2;
 	m_bar_size = get_w() - m_cursor_size;
+	Slider::layout();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

=== modified file 'src/ui_basic/slider.h'
--- src/ui_basic/slider.h	2011-11-06 12:23:20 +0000
+++ src/ui_basic/slider.h	2011-11-06 18:28:26 +0000
@@ -62,6 +62,9 @@
 
 
 protected:
+	void layout();
+	void calc_cursor_pos();
+
 	//  drawing
 	int32_t get_x_gap()    const {return m_x_gap;}
 	int32_t get_y_gap()    const {return m_y_gap;}


Follow ups