summaryrefslogtreecommitdiff
path: root/src/blitter
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-04-02 16:39:30 +0000
committerfrosch <frosch@openttd.org>2011-04-02 16:39:30 +0000
commitb18211bb9d1f8f758e814a5b5f6dc74e78183c51 (patch)
tree1fa7d4f5b289ca68bb97d0e167b36a80ee9b4eae /src/blitter
parent7659575cfa52b6fd9eea9c1256b325f84261e29f (diff)
downloadopenttd-b18211bb9d1f8f758e814a5b5f6dc74e78183c51.tar.xz
(svn r22291) -Add: a linewidth argument to GfxDrawLine() and Blitter::DrawLine().
Diffstat (limited to 'src/blitter')
-rw-r--r--src/blitter/base.cpp83
-rw-r--r--src/blitter/base.hpp2
2 files changed, 68 insertions, 17 deletions
diff --git a/src/blitter/base.cpp b/src/blitter/base.cpp
index 9b2d007bf..312ec1025 100644
--- a/src/blitter/base.cpp
+++ b/src/blitter/base.cpp
@@ -11,6 +11,7 @@
#include "../stdafx.h"
#include "base.hpp"
+#include "../core/math_func.hpp"
/**
* Draw a line with a given colour.
@@ -22,14 +23,14 @@
* @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows).
* @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows).
* @param colour A 8bpp mapping colour.
+ * @param width Line width.
*/
-void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour)
+void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width)
{
int dy;
int dx;
int stepx;
int stepy;
- int frac;
dy = (y2 - y) * 2;
if (dy < 0) {
@@ -47,29 +48,79 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
stepx = 1;
}
+ int frac_diff = width * max(dx, dy);
+ if (width > 1) {
+ int frac_sq = width * width * (dx * dx + dy * dy);
+ while (frac_diff * frac_diff < frac_sq) frac_diff++;
+ }
+
if (dx > dy) {
- frac = dy - (dx / 2);
- x2 += stepx; // Make x2 the first column to not draw to
+ int y_low = y;
+ int y_high = y;
+ int frac_low = dy - frac_diff / 2;
+ int frac_high = dy + frac_diff / 2;
+
+ while (frac_low + dx / 2 < 0) {
+ frac_low += dx;
+ y_low -= stepy;
+ }
+ while (frac_high - dx / 2 > 0) {
+ frac_high -= dx;
+ y_high += stepy;
+ }
+ x2 += stepx;
+
while (x != x2) {
- if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour);
- if (frac >= 0) {
- y += stepy;
- frac -= dx;
+ if (x >= 0 && x < screen_width) {
+ for (int y = y_low; y != y_high; y += stepy) {
+ if (y >= 0 && y < screen_height) this->SetPixel(video, x, y, colour);
+ }
+ }
+ if (frac_low >= 0) {
+ y_low += stepy;
+ frac_low -= dx;
+ }
+ if (frac_high >= 0) {
+ y_high += stepy;
+ frac_high -= dx;
}
x += stepx;
- frac += dy;
+ frac_low += dy;
+ frac_high += dy;
}
} else {
- frac = dx - (dy / 2);
- y2 += stepy; // Make y2 the first row to not draw to
+ int x_low = x;
+ int x_high = x;
+ int frac_low = dx - frac_diff / 2;
+ int frac_high = dx + frac_diff / 2;
+
+ while (frac_low + dy / 2 < 0) {
+ frac_low += dy;
+ x_low -= stepx;
+ }
+ while (frac_high - dy / 2 > 0) {
+ frac_high -= dy;
+ x_high += stepx;
+ }
+ y2 += stepy;
+
while (y != y2) {
- if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour);
- if (frac >= 0) {
- x += stepx;
- frac -= dy;
+ if (y >= 0 && y < screen_height) {
+ for (int x = x_low; x != x_high; x += stepx) {
+ if (x >= 0 && x < screen_width) this->SetPixel(video, x, y, colour);
+ }
+ }
+ if (frac_low >= 0) {
+ x_low += stepx;
+ frac_low -= dy;
+ }
+ if (frac_high >= 0) {
+ x_high += stepx;
+ frac_high -= dy;
}
y += stepy;
- frac += dx;
+ frac_low += dx;
+ frac_high += dx;
}
}
}
diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp
index 3af376a15..cb76f856e 100644
--- a/src/blitter/base.hpp
+++ b/src/blitter/base.hpp
@@ -101,7 +101,7 @@ public:
*/
virtual void DrawRect(void *video, int width, int height, uint8 colour) = 0;
- void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour);
+ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);
/**
* Copy from a buffer to the screen.