← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~nomeata/widelands/buttons into lp:widelands

 

Joachim Breitner has proposed merging lp:~nomeata/widelands/buttons into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #674909 in widelands: "In the general statistict menu the time buttons should also be toggable"
  https://bugs.launchpad.net/widelands/+bug/674909

For more details, see:
https://code.launchpad.net/~nomeata/widelands/buttons/+merge/81338

Replaces the time span buttons by a slider and makes the work area button a toggle button. (Closes: 674909)
-- 
https://code.launchpad.net/~nomeata/widelands/buttons/+merge/81338
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/buttons into lp:widelands.
=== modified file 'src/ui_basic/button.h'
--- src/ui_basic/button.h	2011-01-30 15:13:23 +0000
+++ src/ui_basic/button.h	2011-11-04 22:11:28 +0000
@@ -110,7 +110,7 @@
 };
 
 
-/// A verion of Button that uses a function object to the the callback.
+/// A verion of Button that uses a function object for the callback.
 struct Callback_Button : public Button {
 	Callback_Button /// for textual buttons
 		(Panel * const parent,

=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc	2010-12-03 20:10:43 +0000
+++ src/ui_basic/slider.cc	2011-11-04 22:11:28 +0000
@@ -22,6 +22,9 @@
 #include "mouse_constants.h"
 #include "graphic/offscreensurface.h"
 #include "graphic/rendertarget.h"
+#include "graphic/font.h"
+#include "graphic/font_handler.h"
+
 
 #include <cmath>
 
@@ -518,5 +521,32 @@
 	} else return false;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+//                               DISCRETE                                     //
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * \brief Redraw the slide bar. The discrete horizontal bar is painted.
+ *
+ * \param dst The graphic destination.
+ */
+void DiscreteSlider::draw(RenderTarget & dst)
+{
+	Panel::draw(dst);
+
+	UI::TextStyle ts = UI::TextStyle::ui_small();
+
+	uint32_t gap_1 = get_w() / (2 * labels.size());
+	uint32_t gap_n = get_w() / labels.size();
+
+	for (uint32_t i = 0; i < labels.size(); i++) {
+		UI::g_fh->draw_text
+			(dst, ts,
+			 Point(gap_1 + i * gap_n, get_h() + 2),
+			 labels[i], UI::Align_BottomCenter);
+	}
+
+}
+
 
 }

=== modified file 'src/ui_basic/slider.h'
--- src/ui_basic/slider.h	2010-12-03 20:05:27 +0000
+++ src/ui_basic/slider.h	2011-11-04 22:11:28 +0000
@@ -21,6 +21,7 @@
 
 #include "panel.h"
 #include "m_signal.h"
+#include "graphic/font.h"
 
 namespace UI {
 
@@ -167,6 +168,49 @@
 	bool handle_mousepress(Uint8 btn, int32_t x, int32_t y);
 };
 
+/**
+ * \brief This class defines an discrete slide bar. We do not derive from
+ * Slider, but rather embed it, as we need to re-size it and add the lables.
+ */
+struct DiscreteSlider : public Panel {
+	DiscreteSlider
+		(Panel * const parent,
+		 const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
+		 const std::vector<std::string> labels_in,
+		 uint32_t m_value,
+		 const PictureID background_picture_id,
+		 const std::string & tooltip_text = std::string(),
+		 const uint32_t cursor_size = 20,
+		 const bool enabled = true)
+		:
+		Panel (parent, x, y, w, h, tooltip_text),
+		slider
+			(this,
+			 // here, we take into account the h_gap introduced by HorizontalSlider
+			 w / (2 * labels_in.size()) - cursor_size / 2, 0,
+			 w - (w / labels_in.size()) + cursor_size,
+			 h - UI::Font::ui_small()->lineskip() - 2,
+			 0, labels_in.size() - 1, m_value,
+			 background_picture_id,
+			 tooltip_text,
+			 cursor_size,
+			 enabled),
+		 changed(&slider.changed),
+		 changedto(&slider.changedto),
+		 labels(labels_in)
+	{}
+protected:
+	HorizontalSlider slider;
+public:
+	Signal *       changed;
+	Signal1<int32_t> *  changedto;
+protected:
+	const std::vector<std::string> labels;
+
+	void draw(RenderTarget & dst);
+};
+
+
 }
 
 #endif

=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc	2011-10-02 16:59:59 +0000
+++ src/wui/buildingwindow.cc	2011-11-04 22:11:28 +0000
@@ -221,6 +221,7 @@
 				 boost::bind(&Building_Window::toggle_workarea, boost::ref(*this)),
 				 _("Hide workarea"));
 			capsbuttons->add(m_toggle_workarea, UI::Box::AlignCenter);
+			configure_workarea_button();
 			set_fastclick_panel(m_toggle_workarea);
 		}
 
@@ -331,8 +332,7 @@
 		hollow_area.hole_radius = hollow_area.radius;
 	}
 
-	if (m_toggle_workarea)
-		m_toggle_workarea->set_tooltip(_("Hide workarea"));
+	configure_workarea_button();
 }
 
 /**
@@ -348,12 +348,28 @@
 		overlay_manager.remove_overlay(m_workarea_job_id);
 		m_workarea_job_id = Overlay_Manager::Job_Id::Null();
 
-		if (m_toggle_workarea)
+		configure_workarea_button();
+	}
+}
+
+/**
+ * Sets the perm_pressed state and the tooltip.
+ */
+void Building_Window::configure_workarea_button()
+{
+	if (m_toggle_workarea) {
+		if (m_workarea_job_id) {
+			m_toggle_workarea->set_tooltip(_("Hide workarea"));
+			m_toggle_workarea->set_perm_pressed(true);
+		} else {
 			m_toggle_workarea->set_tooltip(_("Show workarea"));
+			m_toggle_workarea->set_perm_pressed(false);
+		}
 	}
 }
 
 
+
 void Building_Window::toggle_workarea() {
 	if (m_workarea_job_id) {
 		hide_workarea();

=== modified file 'src/wui/buildingwindow.h'
--- src/wui/buildingwindow.h	2010-10-31 11:18:00 +0000
+++ src/wui/buildingwindow.h	2011-11-04 22:11:28 +0000
@@ -60,6 +60,7 @@
 	void show_workarea();
 	void hide_workarea();
 	void toggle_workarea();
+	void configure_workarea_button();
 	void act_start_stop();
 	void act_enhance(Widelands::Building_Index);
 	void clicked_goto();

=== modified file 'src/wui/general_statistics_menu.cc'
--- src/wui/general_statistics_menu.cc	2011-10-09 19:31:05 +0000
+++ src/wui/general_statistics_menu.cc	2011-11-04 22:11:28 +0000
@@ -34,6 +34,7 @@
 #include "ui_basic/button.h"
 #include "ui_basic/checkbox.h"
 #include "ui_basic/textarea.h"
+#include "ui_basic/slider.h"
 
 using namespace Widelands;
 
@@ -232,85 +233,15 @@
 		(this, &General_Statistics_Menu::radiogroup_changed);
 	pos.y += 25;
 
-
-	//  time buttons
-	button_size = (get_inner_w() - spacing * 5) / 4;
 	pos.x = spacing;
 	pos.y += spacing + spacing;
 
-	new UI::Callback_Button
-		(this, "15m",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_15_MINS),
-		 _("15 m"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "30m",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_30_MINS),
-		 _("30 m"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "1h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_ONE_HOUR),
-		 _("1 h"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "2h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_TWO_HOURS),
-		 _("2 h"));
-
-	pos.y += 25 + spacing;
-	pos.x = spacing;
-
-	new UI::Callback_Button
-		(this, "help",
-		 pos.x, pos.y, 32, 32,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
-		 boost::bind(&General_Statistics_Menu::clicked_help, boost::ref(*this)),
-		 _("Help"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "4h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_FOUR_HOURS),
-		 _("4 h"));
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "8h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_EIGHT_HOURS),
-		 _("8 h"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "16h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(m_plot), WUIPlot_Area::TIME_16_HOURS),
-		 _("16 h"));
-
-	pos.x += button_size + spacing;
-	pos.y += 32 + spacing;
+	new WUIPlot_Area_Slider
+		(this, m_plot,
+		 pos.x, pos.y, get_inner_w() - 2 * spacing, 45,
+		 g_gr->get_picture(PicMod_UI, "pics/but1.png"));
+
+	pos.y += 45 + spacing;
 
 	set_inner_size(get_inner_w(), pos.y);
 }

=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2011-10-03 21:00:07 +0000
+++ src/wui/plot_area.cc	2011-11-04 22:11:28 +0000
@@ -302,3 +302,7 @@
 void WUIPlot_Area::set_sample_rate(uint32_t const id) {
 	m_sample_rate = id;
 }
+
+std::string WUIPlot_Area::time_labels[WUIPlot_Area::TIME_LAST] =
+	{"15m", "30m", "1h", "2h", "4h", "8h", "16h"};
+

=== modified file 'src/wui/plot_area.h'
--- src/wui/plot_area.h	2009-05-06 20:54:01 +0000
+++ src/wui/plot_area.h	2011-11-04 22:11:28 +0000
@@ -21,6 +21,7 @@
 #define WUI_PLOT_AREA_H
 
 #include "ui_basic/panel.h"
+#include "ui_basic/slider.h"
 
 #include "rgbcolor.h"
 
@@ -40,7 +41,9 @@
 		TIME_FOUR_HOURS,
 		TIME_EIGHT_HOURS,
 		TIME_16_HOURS,
+		TIME_LAST,
 	};
+	static std::string time_labels[TIME_LAST];
 	enum PLOTMODE {
 		//  Always take the samples of some times together, so that the graph is
 		//  not completely zigg-zagged.
@@ -55,6 +58,8 @@
 	virtual void draw(RenderTarget &);
 
 	void set_time(TIME);
+	void set_time_int(int32_t time) {set_time(static_cast<TIME>(time)); };
+	TIME get_time() {return static_cast<TIME>(m_time); };
 	void set_sample_rate(uint32_t id); // in milliseconds
 
 	void register_plot_data
@@ -75,4 +80,33 @@
 	int32_t                 m_plotmode;
 };
 
+/**
+ * A discrete slider with plot time steps preconfigured and automatic signal
+ * setup.
+ */
+struct WUIPlot_Area_Slider : public UI::DiscreteSlider {
+	WUIPlot_Area_Slider
+		(Panel * const parent,
+		 WUIPlot_Area & plot_area,
+		 const int32_t x, const int32_t y, const uint32_t w, const uint32_t h,
+		 const PictureID background_picture_id,
+		 const std::string & tooltip_text = std::string(),
+		 const uint32_t cursor_size = 20,
+		 const bool enabled = true)
+	: DiscreteSlider
+		(parent,
+		 x, y, w, h,
+		 std::vector<std::string>
+		 	(WUIPlot_Area::time_labels,
+		 	 WUIPlot_Area::time_labels + WUIPlot_Area::TIME_LAST),
+		 plot_area.get_time(),
+		 background_picture_id,
+		 tooltip_text,
+		 cursor_size,
+		 enabled)
+	{
+		changedto->set(&plot_area, &WUIPlot_Area::set_time_int);
+	}
+};
+
 #endif

=== modified file 'src/wui/ware_statistics_menu.cc'
--- src/wui/ware_statistics_menu.cc	2010-12-03 22:51:25 +0000
+++ src/wui/ware_statistics_menu.cc	2011-11-04 22:11:28 +0000
@@ -31,7 +31,7 @@
 #include "ui_basic/button.h"
 #include "ui_basic/checkbox.h"
 #include "ui_basic/textarea.h"
-
+#include "ui_basic/slider.h"
 
 #define WARES_DISPLAY_BG "pics/ware_list_bg.png"
 
@@ -410,84 +410,15 @@
 
 	m_plot->set_size(get_inner_w() - 2 * spacing, PLOT_HEIGHT);
 
-
-	int32_t button_size = (get_inner_w() - spacing * 5) / 4;
 	pos.x  = spacing;
 	pos.y += spacing + spacing;
 
-	new UI::Callback_Button
-		(this, "15m",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_15_MINS),
-		 _("15 m"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "30m",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_30_MINS),
-		 _("30 m"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "1h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_ONE_HOUR),
-		 _("1 h"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "2h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_TWO_HOURS),
-		 _("2 h"));
-
-	pos.y += 25 + spacing;
-	pos.x  =      spacing;
-
-	new UI::Callback_Button
-		(this, "help",
-		 pos.x, pos.y, 32, 32,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 g_gr->get_picture(PicMod_Game, "pics/menu_help.png"),
-		 boost::bind(&Ware_Statistics_Menu::clicked_help, boost::ref(*this)),
-		 _("Help"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "4h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_FOUR_HOURS),
-		 _("4 h"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "8h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_EIGHT_HOURS),
-		 _("8 h"));
-
-	pos.x += button_size + spacing;
-
-	new UI::Callback_Button
-		(this, "16h",
-		 pos.x, pos.y, button_size, 25,
-		 g_gr->get_picture(PicMod_UI, "pics/but4.png"),
-		 boost::bind(&WUIPlot_Area::set_time, boost::ref(*m_plot), WUIPlot_Area::TIME_16_HOURS),
-		 _("16 h"));
-
-	pos += Point(button_size + spacing, 32 + spacing);
+	new WUIPlot_Area_Slider
+		(this, *m_plot,
+		 pos.x, pos.y, get_inner_w() - 2 * spacing, 45,
+		 g_gr->get_picture(PicMod_UI, "pics/but1.png"));
+
+	pos.y += 45 + spacing;
 
 	set_inner_size(get_inner_w(), pos.y);
 }


Follow ups