summaryrefslogtreecommitdiff
path: root/src/blitter
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-10-23 19:41:20 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-10-23 19:41:20 +0000
commit89b7afbac89eb3aac8871a9853cf12a0d6141dab (patch)
treee059a94a03773edad3542dbbce7901ac2c3d2dd4 /src/blitter
parentf528d2c59246cb76c5d84dfac04e84e1368ea650 (diff)
downloadopenttd-89b7afbac89eb3aac8871a9853cf12a0d6141dab.tar.xz
(svn r25911) -Add: Support for drawing dashed lines.
Diffstat (limited to 'src/blitter')
-rw-r--r--src/blitter/base.cpp11
-rw-r--r--src/blitter/base.hpp3
2 files changed, 10 insertions, 4 deletions
diff --git a/src/blitter/base.cpp b/src/blitter/base.cpp
index bb8b9f234..d30f4054b 100644
--- a/src/blitter/base.cpp
+++ b/src/blitter/base.cpp
@@ -13,7 +13,7 @@
#include "base.hpp"
#include "../core/math_func.hpp"
-void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width)
+void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
{
int dy;
int dx;
@@ -59,6 +59,9 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
}
}
+ int gap = dash;
+ if (dash == 0) dash = 1;
+ int dash_count = 0;
if (dx > dy) {
int y_low = y;
int y_high = y;
@@ -76,7 +79,7 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
x2 += stepx;
while (x != x2) {
- if (x >= 0 && x < screen_width) {
+ if (dash_count < dash && 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);
}
@@ -92,6 +95,7 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
x += stepx;
frac_low += dy;
frac_high += dy;
+ if (++dash_count >= dash + gap) dash_count = 0;
}
} else {
int x_low = x;
@@ -110,7 +114,7 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
y2 += stepy;
while (y != y2) {
- if (y >= 0 && y < screen_height) {
+ if (dash_count < dash && 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);
}
@@ -126,6 +130,7 @@ void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_wid
y += stepy;
frac_low += dx;
frac_high += dx;
+ if (++dash_count >= dash + gap) dash_count = 0;
}
}
}
diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp
index 91ff68c3b..00851eeef 100644
--- a/src/blitter/base.hpp
+++ b/src/blitter/base.hpp
@@ -118,8 +118,9 @@ public:
* @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.
+ * @param dash Length of dashes for dashed lines. 0 means solid line.
*/
- virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width);
+ virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0);
/**
* Copy from a buffer to the screen.