← 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.

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

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

Now with the horizontal layout for wares, related to https://bugs.launchpad.net/widelands/+bug/672085
-- 
https://code.launchpad.net/~nomeata/widelands/plot-improvements/+merge/81371
Your team Widelands Developers is requested to review the proposed merge of lp:~nomeata/widelands/plot-improvements into lp:widelands.
=== modified file 'src/graphic/render/gl_surface_screen.cc'
--- src/graphic/render/gl_surface_screen.cc	2011-02-21 18:04:56 +0000
+++ src/graphic/render/gl_surface_screen.cc	2011-11-05 18:50:31 +0000
@@ -230,15 +230,8 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color,
-		 const Rect * clip)
+		 RGBColor color)
 {
-	if (clip) {
-		glPushAttrib(GL_ENABLE_BIT | GL_SCISSOR_BIT);
-		glScissor
-			(clip->x, g_gr->get_yres() - clip->y - clip->h, clip->w, clip->h);
-		glEnable(GL_SCISSOR_TEST);
-	}
 	glDisable(GL_BLEND);
 	glDisable(GL_TEXTURE_2D);
 	glBegin(GL_LINES); {
@@ -246,9 +239,6 @@
 		glVertex2f(x1 + 0.5f, y1 + 0.5f);
 		glVertex2f(x2 + 0.5f, y2 + 0.5f);
 	} glEnd();
-	if (clip) {
-		glPopAttrib();
-	}
 }
 
 /**

=== modified file 'src/graphic/render/gl_surface_screen.h'
--- src/graphic/render/gl_surface_screen.h	2011-02-20 16:42:42 +0000
+++ src/graphic/render/gl_surface_screen.h	2011-11-05 18:50:31 +0000
@@ -57,7 +57,7 @@
 	virtual void draw_line
 		(int32_t x1, int32_t y1,
 		 int32_t x2, int32_t y2,
-		 RGBColor, Rect const * clip = 0);
+		 RGBColor);
 
 	virtual void blit(Point, PictureID, Rect srcrc, Composite cm);
 	virtual void fast_blit(PictureID);

=== modified file 'src/graphic/render/render_sdl.cc'
--- src/graphic/render/render_sdl.cc	2010-12-04 23:11:18 +0000
+++ src/graphic/render/render_sdl.cc	2011-11-05 18:50:31 +0000
@@ -204,8 +204,7 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color,
-		 const Rect * clip)
+		 RGBColor color)
 {
 	int32_t dx = x2 - x1;      /* the horizontal distance of the line */
 	int32_t dy = y2 - y1;      /* the vertical distance of the line */
@@ -217,7 +216,7 @@
 	uint32_t y = dxabs / 2;
 	Point p(x1, y1);
 
-	draw_pixel(p, *clip, color);
+	set_pixel(p.x, p.y, color.map(format()));
 
 	if (dxabs >= dyabs) //  the line is more horizontal than vertical
 		for (uint32_t i = 0; i < dxabs; ++i) {
@@ -229,7 +228,7 @@
 			}
 
 			p.x += sdx;
-			draw_pixel(p, *clip, color);
+			set_pixel(p.x, p.y, color.map(format()));
 		}
 	else                //  the line is more vertical than horizontal
 		for (uint32_t i = 0; i < dyabs; ++i) {
@@ -241,7 +240,7 @@
 			}
 
 			p.y += sdy;
-			draw_pixel(p, *clip, color);
+			set_pixel(p.x, p.y, color.map(format()));
 		}
 }
 

=== modified file 'src/graphic/render/surface_sdl.h'
--- src/graphic/render/surface_sdl.h	2010-11-27 16:23:39 +0000
+++ src/graphic/render/surface_sdl.h	2011-11-05 18:50:31 +0000
@@ -80,7 +80,7 @@
 	void draw_line
 		(int32_t x1, int32_t y1,
 		 int32_t x2, int32_t y2,
-		 RGBColor, Rect const * clip = 0);
+		 RGBColor);
 
 	void blit(Point, PictureID, Rect srcrc, Composite cm);
 	void fast_blit(PictureID);

=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc	2010-11-27 16:23:39 +0000
+++ src/graphic/rendertarget.cc	2011-11-05 18:50:31 +0000
@@ -141,14 +141,9 @@
 	(int32_t const x1, int32_t const y1, int32_t const x2, int32_t const y2,
 	 RGBColor const color)
 {
-	Rect clipr = Rect
-		(Point(m_rect.x + m_offset.x, m_rect.y + m_offset.y),
-		 m_rect.w, m_rect.h);
-
 	m_surface->draw_line
 		(x1 + m_offset.x + m_rect.x, y1 + m_offset.y + m_rect.y,
-		 x2 + m_offset.x + m_rect.x, y2 + m_offset.y + m_rect.y, color,
-		 &clipr);
+		 x2 + m_offset.x + m_rect.x, y2 + m_offset.y + m_rect.y, color);
 }
 
 /**

=== modified file 'src/graphic/surface.h'
--- src/graphic/surface.h	2010-11-27 13:30:37 +0000
+++ src/graphic/surface.h	2011-11-05 18:50:31 +0000
@@ -60,8 +60,7 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color,
-		 Rect const * clip = 0)
+		 RGBColor color)
 	{
 		throw wexception("draw_line() not implemented");
 	}

=== modified file 'src/ui_basic/slider.cc'
--- src/ui_basic/slider.cc	2011-11-05 13:50:56 +0000
+++ src/ui_basic/slider.cc	2011-11-05 18:50:31 +0000
@@ -245,12 +245,18 @@
 		m_pressed = false;
 
 		//  cursor position: align to integer value
-		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);
+		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);
+		}
 
 		update();
 	}
@@ -346,12 +352,16 @@
 	m_cursor_pos = pointer - ofs;
 
 	//  absolute value
-	m_value =
-		static_cast<int32_t>
-			(rint
-			 	(static_cast<double>((m_max_value - m_min_value) * m_cursor_pos)
-			 	 /
-			 	 get_bar_size()));
+	if (get_bar_size() == 0) {
+		m_value = 0;
+	} else {
+		m_value =
+			static_cast<int32_t>
+				(rint
+					(static_cast<double>((m_max_value - m_min_value) * m_cursor_pos)
+					 /
+					 get_bar_size()));
+	}
 
 	//  relative value in bounds
 	if (m_value < m_min_value)

=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2011-11-05 14:55:53 +0000
+++ src/wui/plot_area.cc	2011-11-05 18:50:31 +0000
@@ -89,10 +89,8 @@
 			time_in_ms_ += - (time_in_ms_ % (20 * hours)) + 20 * hours;
 		} else if (time_in_ms_ > 4 * hours) {
 			time_in_ms_ += - (time_in_ms_ % (2 * hours)) + 2 * hours;
-		} else if (time_in_ms_ > 40 * minutes) {
-			time_in_ms_ += - (time_in_ms_ % (20 * minutes)) + 20 * minutes;
 		} else {
-			time_in_ms_ += - (time_in_ms_ % (4 * minutes)) + 5 * minutes;
+			time_in_ms_ += - (time_in_ms_ % (15 * minutes)) + 15 * minutes;
 		}
 		return time_in_ms_;
 	} else {
@@ -149,7 +147,6 @@
  * Draw this. This is the main function
  */
 void WUIPlot_Area::draw(RenderTarget & dst) {
-
 	uint32_t time_in_ms_, how_many_ticks, max_x;
 
 	time_in_ms_ = get_plot_time();

=== modified file 'src/wui/ware_statistics_menu.cc'
--- src/wui/ware_statistics_menu.cc	2011-11-04 22:07:49 +0000
+++ src/wui/ware_statistics_menu.cc	2011-11-05 18:50:31 +0000
@@ -27,6 +27,7 @@
 #include "logic/tribe.h"
 #include "logic/warelist.h"
 #include "plot_area.h"
+#include "waresdisplay.h"
 
 #include "ui_basic/button.h"
 #include "ui_basic/checkbox.h"
@@ -288,60 +289,34 @@
 	RGBColor(255, 255, 255),
 };
 
-/*
- * This class is only needed here, that's
- * why it is defined here.
- *
- * This class is the same as an ordinary
- * checkbox, the only difference is, it has
- * a small rectangle on it with the color
- * of the graph and it needs a picture
- */
-struct WSM_Checkbox : public UI::Checkbox {
-	WSM_Checkbox(UI::Panel *, Point, int32_t id, PictureID picid, RGBColor);
-
-	virtual void draw(RenderTarget &);
-
-private:
-	PictureID  m_pic;
-	RGBColor   m_color;
+
+struct StatisticWaresDisplay : public AbstractWaresDisplay {
+	typedef AbstractWaresDisplay::wdType wdType;
+
+	StatisticWaresDisplay
+		(UI::Panel * const parent,
+		 int32_t const x, int32_t const y,
+		 Widelands::Tribe_Descr const & tribe,
+		 boost::function<void(Widelands::Ware_Index, bool)> callback_function)
+	:
+		 AbstractWaresDisplay(parent, x, y, tribe, WaresDisplay::WARE, true, callback_function)
+	{
+		uint32_t w, h;
+		get_desired_size(w, h);
+		set_size(w, h);
+	}
+protected:
+	std::string info_for_ware(Widelands::Ware_Index const ware) {
+		return "";
+	}
+
+	RGBColor info_color_for_ware(Widelands::Ware_Index const ware)
+	{
+		return colors[static_cast<size_t>(ware)];
+	}
 };
 
 
-WSM_Checkbox::WSM_Checkbox
-	(UI::Panel * const parent,
-	 Point       const p,
-	 int32_t     const id,
-	 PictureID   const picid,
-	 RGBColor    const color)
-:
-UI::Checkbox(parent, p, g_gr->get_picture(PicMod_Game,  WARES_DISPLAY_BG)),
-m_pic       (picid),
-m_color     (color)
-{
-	set_id(id);
-}
-
-/*
- * draw
- */
-void WSM_Checkbox::draw(RenderTarget & dst) {
-	//  First, draw normal.
-	UI::Checkbox::draw(dst);
-
-	//  Now, draw a small box with the color.
-	assert(1 <= get_inner_w());
-	compile_assert(2 <= COLOR_BOX_HEIGHT);
-	dst.fill_rect
-		(Rect(Point(1, 1), get_inner_w() - 1, COLOR_BOX_HEIGHT - 2), m_color);
-
-	//  and the item
-	dst.blit
-		(Point((get_inner_w() - WARE_MENU_PIC_WIDTH) / 2, COLOR_BOX_HEIGHT),
-		 m_pic);
-}
-
-
 Ware_Statistics_Menu::Ware_Statistics_Menu
 	(Interactive_Player & parent, UI::UniqueWindow::Registry & registry)
 :
@@ -353,74 +328,49 @@
 
 	//  First, we must decide about the size.
 	uint8_t const nr_wares = parent.get_player()->tribe().get_nrwares().value();
-	uint32_t wares_per_row = MIN_WARES_PER_LINE;
-	while (nr_wares % wares_per_row && wares_per_row <= MAX_WARES_PER_LINE)
-		++wares_per_row;
-	const uint32_t nr_rows =
-		nr_wares / wares_per_row + (nr_wares % wares_per_row ? 1 : 0);
 
 #define spacing 5
 	Point const offs(spacing, 30);
 	Point       pos (offs);
 
-	set_inner_size
-		(10,
-		 (offs.y + spacing + PLOT_HEIGHT + spacing +
-		  nr_rows * (WARE_MENU_PIC_HEIGHT + spacing) + 100));
-
-
+
+	// Setup Wares selectoin widget first, because the window size depends on it.
+	pos.y += PLOT_HEIGHT + 2 * spacing;
+	pos.x  = spacing;
+
+	StatisticWaresDisplay * swd =
+		new StatisticWaresDisplay
+			(this, spacing, pos.y, parent.get_player()->tribe(),
+			 boost::bind(&Ware_Statistics_Menu::cb_changed_to, boost::ref(*this), _1, _2));
+
+	pos.y += swd->get_h();
+	pos.y += spacing;
+
+	// Setup plot widget
 	m_plot =
 		new WUIPlot_Area
 			(this,
-			 spacing, offs.y + spacing, get_inner_w() - 2 * spacing, PLOT_HEIGHT);
+			 spacing, offs.y + spacing, swd->get_w(), PLOT_HEIGHT);
 	m_plot->set_sample_rate(STATISTICS_SAMPLE_TIME);
 	m_plot->set_plotmode(WUIPlot_Area::PLOTMODE_RELATIVE);
 
-	//  all wares
-	Widelands::Ware_Index::value_t cur_ware = 0;
-	int32_t dposy    = 0;
-	pos.y += PLOT_HEIGHT + 2 * spacing;
-	Widelands::Tribe_Descr const & tribe = parent.get_player()->tribe();
-	for (uint32_t y = 0; y < nr_rows; ++y) {
-		pos.x = spacing;
-		for
-			(uint32_t x = 0;
-			 x < wares_per_row and cur_ware < nr_wares;
-			 ++x, ++cur_ware)
-		{
-			Widelands::Item_Ware_Descr const & ware =
-				*tribe.get_ware_descr(Widelands::Ware_Index(cur_ware));
-			WSM_Checkbox & cb =
-				*new WSM_Checkbox
-					(this, pos, cur_ware, ware.icon(), colors[cur_ware]);
-			cb.set_tooltip(ware.descname().c_str());
-			cb.changedtoid.set(this, &Ware_Statistics_Menu::cb_changed_to);
-			pos.x += cb.get_w() + spacing;
-			dposy = cb.get_h() + spacing;
-			set_inner_size
-				(spacing + (cb.get_w() + spacing) * wares_per_row, get_inner_h());
-			m_plot->register_plot_data
-				(cur_ware,
-				 parent.get_player()->get_ware_production_statistics
-				 	(Widelands::Ware_Index(cur_ware)),
-				 colors[cur_ware]);
-		}
-		pos.y += dposy;
+	for (Widelands::Ware_Index::value_t cur_ware = 0; cur_ware < nr_wares; ++cur_ware) {
+		m_plot->register_plot_data
+			(cur_ware,
+			 parent.get_player()->get_ware_production_statistics
+				(Widelands::Ware_Index(cur_ware)),
+			 colors[cur_ware]);
 	}
 
-	m_plot->set_size(get_inner_w() - 2 * spacing, PLOT_HEIGHT);
-
-	pos.x  = spacing;
-	pos.y += spacing + spacing;
 
 	new WUIPlot_Area_Slider
 		(this, *m_plot,
-		 pos.x, pos.y, get_inner_w() - 2 * spacing, 45,
+		 pos.x, pos.y, swd->get_w(), 45,
 		 g_gr->get_picture(PicMod_UI, "pics/but1.png"));
 
 	pos.y += 45 + spacing;
 
-	set_inner_size(get_inner_w(), pos.y);
+	set_inner_size(swd->get_w() + 2 * spacing, pos.y);
 }
 
 
@@ -433,6 +383,7 @@
 /*
  * Cb has been changed to this state
  */
-void Ware_Statistics_Menu::cb_changed_to(int32_t const id, bool const what) {
-	m_plot->show_plot(id, what);
+void Ware_Statistics_Menu::cb_changed_to(Widelands::Ware_Index id, bool what) {
+	m_plot->show_plot(static_cast<size_t>(id), what);
 }
+

=== modified file 'src/wui/ware_statistics_menu.h'
--- src/wui/ware_statistics_menu.h	2009-05-06 20:54:01 +0000
+++ src/wui/ware_statistics_menu.h	2011-11-05 18:50:31 +0000
@@ -33,7 +33,7 @@
 	WUIPlot_Area       * m_plot;
 
 	void clicked_help();
-	void cb_changed_to(int32_t, bool);
+	void cb_changed_to(Widelands::Ware_Index, bool);
 };
 
 #endif

=== modified file 'src/wui/waresdisplay.cc'
--- src/wui/waresdisplay.cc	2011-09-17 11:33:34 +0000
+++ src/wui/waresdisplay.cc	2011-11-05 18:50:31 +0000
@@ -37,7 +37,9 @@
 	 int32_t const x, int32_t const y,
 	 Widelands::Tribe_Descr const & tribe,
 	 wdType type,
-	 bool selectable)
+	 bool selectable,
+	 boost::function<void(Widelands::Ware_Index, bool)> callback_function,
+	 bool horizontal)
 	:
 	// Size is set when add_warelist is called, as it depends on the m_type.
 	UI::Panel(parent, x, y, 0, 0),
@@ -55,7 +57,9 @@
 	m_hidden
 		(m_type == WORKER ? m_tribe.get_nrworkers()
 	                          : m_tribe.get_nrwares(), false),
-	m_selectable(selectable)
+	m_selectable(selectable),
+	m_horizontal(horizontal),
+	m_callback_function(callback_function)
 {
 	//resize the configuration of our wares if they won't fit in the current window
 	int number = (g_gr->get_yres() - 160) / (WARE_MENU_PIC_HEIGHT + 8 + 3);
@@ -67,6 +71,11 @@
 	for (unsigned int i = 0; i < icons_order().size(); i++)
 		if (icons_order()[i].size() > rows)
 			rows = icons_order()[i].size();
+	if (m_horizontal) {
+		unsigned int s = columns;
+		columns = rows;
+		rows = s;
+	}
 
 	// 25 is height of m_curware text
 	set_desired_size
@@ -121,6 +130,11 @@
 
 	unsigned int i = x / (WARE_MENU_PIC_WIDTH + 4);
 	unsigned int j = y / (WARE_MENU_PIC_HEIGHT + 8 + 3);
+	if (m_horizontal) {
+		unsigned int s = i;
+		i = j;
+		j = s;
+	}
 	if (i < icons_order().size() && j < icons_order()[i].size()) {
 		Widelands::Ware_Index ware = icons_order()[i][j];
 		if (not m_hidden[ware]) {
@@ -190,8 +204,13 @@
 Point AbstractWaresDisplay::ware_position(Widelands::Ware_Index id) const
 {
 	Point p(2, 2);
-	p.x += icons_order_coords()[id].first  * (WARE_MENU_PIC_WIDTH + 3);
-	p.y += icons_order_coords()[id].second * (WARE_MENU_PIC_HEIGHT + 3 + 8);
+	if (m_horizontal) {
+		p.x += icons_order_coords()[id].second  * (WARE_MENU_PIC_WIDTH + 3);
+		p.y += icons_order_coords()[id].first * (WARE_MENU_PIC_HEIGHT + 3 + 8);
+	} else {
+		p.x += icons_order_coords()[id].first  * (WARE_MENU_PIC_WIDTH + 3);
+		p.y += icons_order_coords()[id].second * (WARE_MENU_PIC_HEIGHT + 3 + 8);
+	}
 	return p;
 }
 
@@ -229,7 +248,7 @@
 		 m_tribe.get_ware_descr  (id)->icon());
 	dst.fill_rect
 		(Rect(pos + Point(0, WARE_MENU_PIC_HEIGHT), WARE_MENU_PIC_WIDTH, 8),
-		 RGBColor(0, 0, 0));
+		 info_color_for_ware(id));
 
 	UI::g_fh->draw_text
 		(dst, UI::TextStyle::ui_ultrasmall(),
@@ -293,6 +312,10 @@
 : AbstractWaresDisplay(parent, x, y, tribe, type, selectable)
 {}
 
+RGBColor AbstractWaresDisplay::info_color_for_ware(Widelands::Ware_Index const ware) {
+	return RGBColor(0, 0, 0);
+}
+
 WaresDisplay::~WaresDisplay()
 {
 	remove_all_warelists();

=== modified file 'src/wui/waresdisplay.h'
--- src/wui/waresdisplay.h	2010-11-05 19:36:57 +0000
+++ src/wui/waresdisplay.h	2011-11-05 18:50:31 +0000
@@ -23,6 +23,8 @@
 #include "logic/warelist.h"
 #include "logic/tribe.h"
 
+#include "graphic/graphic.h"
+
 #include "ui_basic/textarea.h"
 
 #include <vector>
@@ -50,7 +52,9 @@
 		 int32_t const x, int32_t const y,
 		 Widelands::Tribe_Descr const &,
 		 wdType type,
-		 bool selectable);
+		 bool selectable,
+		 boost::function<void(Widelands::Ware_Index, bool)> callback_function = NULL,
+		 bool horizontal = true);
 
 	bool handle_mousemove
 		(Uint8 state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff);
@@ -67,6 +71,8 @@
 			unselect_ware(ware);
 		else
 			select_ware(ware);
+		if (m_callback_function)
+			m_callback_function(ware, ware_selected(ware));
 	}
 
 	// Wares may be hidden
@@ -82,6 +88,8 @@
 
 	virtual std::string info_for_ware(Widelands::Ware_Index const) = 0;
 
+	virtual RGBColor info_color_for_ware(Widelands::Ware_Index);
+
 	Widelands::Tribe_Descr::WaresOrder const & icons_order() const;
 	Widelands::Tribe_Descr::WaresOrderCoords const & icons_order_coords() const;
 	virtual Point ware_position(Widelands::Ware_Index) const;
@@ -100,6 +108,8 @@
 	selection_type      m_selected;
 	selection_type      m_hidden;
 	bool                m_selectable;
+	bool                m_horizontal;
+	boost::function<void(Widelands::Ware_Index, bool)> m_callback_function;
 };
 
 /*


Follow ups