← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~borim/widelands/enhanceCharts into lp:widelands

 

Borim has proposed merging lp:~borim/widelands/enhanceCharts into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~borim/widelands/enhanceCharts/+merge/83969

* add an optional line width parameter to the draw_line function from the Surface and RenderTarget class
* use 2 pixel wide lines to draw plot line and diagram
* initialize the start point of the plot line with first data value
-- 
https://code.launchpad.net/~borim/widelands/enhanceCharts/+merge/83969
Your team Widelands Developers is requested to review the proposed merge of lp:~borim/widelands/enhanceCharts into lp:widelands.
=== modified file 'src/graphic/render/gl_surface_screen.cc'
--- src/graphic/render/gl_surface_screen.cc	2011-11-05 15:48:21 +0000
+++ src/graphic/render/gl_surface_screen.cc	2011-11-30 16:00:20 +0000
@@ -230,10 +230,12 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color)
+		 RGBColor color,
+		 uint8_t width)
 {
 	glDisable(GL_BLEND);
 	glDisable(GL_TEXTURE_2D);
+	glLineWidth(width);
 	glBegin(GL_LINES); {
 		glColor3ub(color.r(), color.g(), color.b());
 		glVertex2f(x1 + 0.5f, y1 + 0.5f);

=== modified file 'src/graphic/render/gl_surface_screen.h'
--- src/graphic/render/gl_surface_screen.h	2011-11-05 15:48:21 +0000
+++ src/graphic/render/gl_surface_screen.h	2011-11-30 16:00:20 +0000
@@ -57,7 +57,7 @@
 	virtual void draw_line
 		(int32_t x1, int32_t y1,
 		 int32_t x2, int32_t y2,
-		 RGBColor);
+		 RGBColor, uint8_t width);
 
 	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	2011-11-05 18:23:53 +0000
+++ src/graphic/render/render_sdl.cc	2011-11-30 16:00:20 +0000
@@ -204,7 +204,8 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color)
+		 RGBColor color,
+		 uint8_t width)
 {
 	int32_t dx = x2 - x1;      /* the horizontal distance of the line */
 	int32_t dy = y2 - y1;      /* the vertical distance of the line */
@@ -228,7 +229,9 @@
 			}
 
 			p.x += sdx;
-			set_pixel(p.x, p.y, color.map(format()));
+			for (int32_t w = 0; w < width; ++w) {
+				set_pixel(p.x, p.y + w, color.map(format()));
+			}
 		}
 	else                //  the line is more vertical than horizontal
 		for (uint32_t i = 0; i < dyabs; ++i) {
@@ -240,7 +243,9 @@
 			}
 
 			p.y += sdy;
-			set_pixel(p.x, p.y, color.map(format()));
+			for (int32_t w = 0; w < width; ++w) {
+				set_pixel(p.x + w, p.y, color.map(format()));
+			}
 		}
 }
 

=== modified file 'src/graphic/render/surface_sdl.h'
--- src/graphic/render/surface_sdl.h	2011-11-21 17:18:13 +0000
+++ src/graphic/render/surface_sdl.h	2011-11-30 16:00:20 +0000
@@ -80,7 +80,7 @@
 	void draw_line
 		(int32_t x1, int32_t y1,
 		 int32_t x2, int32_t y2,
-		 RGBColor);
+		 RGBColor, uint8_t width);
 
 	void blit(Point, PictureID, Rect srcrc, Composite cm);
 	void fast_blit(PictureID);

=== modified file 'src/graphic/rendertarget.cc'
--- src/graphic/rendertarget.cc	2011-11-06 02:09:14 +0000
+++ src/graphic/rendertarget.cc	2011-11-30 16:00:20 +0000
@@ -139,11 +139,12 @@
  */
 void RenderTarget::draw_line
 	(int32_t const x1, int32_t const y1, int32_t const x2, int32_t const y2,
-	 RGBColor const color)
+	 RGBColor const color, uint8_t width)
 {
 	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);
+		 x2 + m_offset.x + m_rect.x, y2 + m_offset.y + m_rect.y, color,
+		 width);
 }
 
 /**

=== modified file 'src/graphic/rendertarget.h'
--- src/graphic/rendertarget.h	2011-11-06 02:09:14 +0000
+++ src/graphic/rendertarget.h	2011-11-30 16:00:20 +0000
@@ -61,7 +61,7 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color);
+		 RGBColor color, uint8_t width = 1);
 	void draw_rect(Rect, RGBColor);
 	void fill_rect(Rect, RGBAColor);
 	void brighten_rect(Rect, int32_t factor);

=== modified file 'src/graphic/surface.h'
--- src/graphic/surface.h	2011-11-21 17:18:13 +0000
+++ src/graphic/surface.h	2011-11-30 16:00:20 +0000
@@ -62,7 +62,7 @@
 		 int32_t y1,
 		 int32_t x2,
 		 int32_t y2,
-		 RGBColor color)
+		 RGBColor color, uint8_t width = 1)
 	{
 		throw wexception("draw_line() not implemented");
 	}

=== modified file 'src/wui/differential_plot_area.cc'
--- src/wui/differential_plot_area.cc	2011-11-09 19:57:23 +0000
+++ src/wui/differential_plot_area.cc	2011-11-30 16:00:20 +0000
@@ -43,7 +43,7 @@
 		 yoffset,
 		 get_inner_w() - space_at_right - xline_length,
 		 yoffset,
-		 ZERO_LINE_COLOR);
+		 ZERO_LINE_COLOR, 2);
 
 	// How many do we take together when relative ploting
 	const int32_t how_many = calc_how_many(time_in_ms_);

=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc	2011-11-29 15:47:18 +0000
+++ src/wui/plot_area.cc	2011-11-30 16:00:20 +0000
@@ -258,6 +258,19 @@
 	return how_many;
 }
 
+
+/**
+ * scale value down to the available space, which is specifiey by
+ * the length of the y axis and the highest scale.
+ */
+float WUIPlot_Area::scale_value
+	(float const yline_length, uint32_t const highest_scale,
+	 int32_t const value)
+{
+	return yline_length / (static_cast<float>(highest_scale) / static_cast<float>(value));
+}
+
+
 /**
  * scale the values from dataset down to the available space and draw a single plot line
  * \param dataset the y values of the line
@@ -272,22 +285,24 @@
 
 	int32_t lx = get_inner_w() - space_at_right;
 	int32_t ly = yoffset;
+	//init start point of the plot line with the first data value.
+	//this prevent that the plot start always at zero
+	if (int32_t value = (*dataset)[dataset->size() - 1]) {
+		ly -= static_cast<int32_t>(scale_value(yline_length, highest_scale, value));
+	}
+
 	for (int32_t i = dataset->size() - 1; i > 0 and posx > spacing; --i) {
 		int32_t const curx = static_cast<int32_t>(posx);
 		int32_t       cury = yoffset;
 
 		//scale the line to the available space
 		if (int32_t value = (*dataset)[i]) {
-			const float length_y =
-				yline_length
-				/
-				(static_cast<float>(highest_scale) / static_cast<float>(value));
+			const float length_y = scale_value(yline_length, highest_scale, value);
+
 			cury -= static_cast<int32_t>(length_y);
 		}
 
-		//TODO create a draw_line function with parameter line width
-		//     and draw a 2 px wide line
-		dst.draw_line(lx, ly, curx, cury, color);
+		dst.draw_line(lx, ly, curx, cury, color, 2);
 
 		posx -= sub;
 
@@ -342,22 +357,22 @@
 	dst.draw_line
 		(spacing,                        get_inner_h() - space_at_bottom,
 		 get_inner_w() - space_at_right, get_inner_h() - space_at_bottom,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 	// Arrow
 	dst.draw_line
 		(spacing,     get_inner_h() - space_at_bottom,
 		 spacing + 5, get_inner_h() - space_at_bottom - 3,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 	dst.draw_line
 		(spacing,     get_inner_h() - space_at_bottom,
 		 spacing + 5, get_inner_h() - space_at_bottom + 3,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 	//  Y Axis
 	dst.draw_line
 		(get_inner_w() - space_at_right, spacing,
 		 get_inner_w() - space_at_right,
 		 get_inner_h() - space_at_bottom,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 	//  No Arrow here, since this doesn't continue.
 
 	//  draw xticks
@@ -371,7 +386,7 @@
 		dst.draw_line
 			(static_cast<int32_t>(posx), get_inner_h() - space_at_bottom,
 			 static_cast<int32_t>(posx), get_inner_h() - space_at_bottom + 3,
-			 LINE_COLOR);
+			 LINE_COLOR, 2);
 
 		snprintf
 			(buffer, sizeof(buffer),
@@ -391,13 +406,13 @@
 	dst.draw_line
 		(get_inner_w() - space_at_right,    spacing,
 		 get_inner_w() - space_at_right -3, spacing,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 	dst.draw_line
 		(get_inner_w() - space_at_right,
 		 spacing + ((get_inner_h() - space_at_bottom) - spacing) / 2,
 		 get_inner_w() - space_at_right - 3,
 		 spacing + ((get_inner_h() - space_at_bottom) - spacing) / 2,
-		 LINE_COLOR);
+		 LINE_COLOR, 2);
 
 	//  print the used unit
 	UI::g_fh->draw_text

=== modified file 'src/wui/plot_area.h'
--- src/wui/plot_area.h	2011-11-29 21:36:49 +0000
+++ src/wui/plot_area.h	2011-11-30 16:00:20 +0000
@@ -123,6 +123,10 @@
 	int32_t                 m_plotmode;
 
 private:
+	float scale_value
+		(float const yline_length, uint32_t const highest_scale,
+		 int32_t const value);
+
 	uint32_t get_game_time();
 	uint32_t get_plot_time();
 	void calc_game_time_id();