diff options
author | fonsinchen <fonsinchen@openttd.org> | 2013-10-23 19:41:20 +0000 |
---|---|---|
committer | fonsinchen <fonsinchen@openttd.org> | 2013-10-23 19:41:20 +0000 |
commit | 89b7afbac89eb3aac8871a9853cf12a0d6141dab (patch) | |
tree | e059a94a03773edad3542dbbce7901ac2c3d2dd4 /src | |
parent | f528d2c59246cb76c5d84dfac04e84e1368ea650 (diff) | |
download | openttd-89b7afbac89eb3aac8871a9853cf12a0d6141dab.tar.xz |
(svn r25911) -Add: Support for drawing dashed lines.
Diffstat (limited to 'src')
-rw-r--r-- | src/blitter/base.cpp | 11 | ||||
-rw-r--r-- | src/blitter/base.hpp | 3 | ||||
-rw-r--r-- | src/gfx.cpp | 13 | ||||
-rw-r--r-- | src/gfx_func.h | 2 |
4 files changed, 18 insertions, 11 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. diff --git a/src/gfx.cpp b/src/gfx.cpp index aa81f99f8..ecb2e7643 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -162,8 +162,9 @@ void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectM * @param screen_height Height of the screen to check clipping against. * @param colour Colour of the line. * @param width Width of the line. + * @param dash Length of dashes for dashed lines. 0 means solid line. */ -static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width) +static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash = 0) { Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); @@ -174,7 +175,7 @@ static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int blitter->DrawLine(video, Clamp(x, 0, screen_width), y, Clamp(x2, 0, screen_width), y2, - screen_width, screen_height, colour, width); + screen_width, screen_height, colour, width, dash); return; } if (x2 == x) { @@ -182,7 +183,7 @@ static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int blitter->DrawLine(video, x, Clamp(y, 0, screen_height), x2, Clamp(y2, 0, screen_height), - screen_width, screen_height, colour, width); + screen_width, screen_height, colour, width, dash); return; } @@ -212,7 +213,7 @@ static inline void GfxDoDrawLine(void *video, int x, int y, int x2, int y2, int * of rounding errors so much additional code has to be run here that in * the general case the effect is not noticable. */ - blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width); + blitter->DrawLine(video, x, y, x2, y2, screen_width, screen_height, colour, width, dash); } /** @@ -241,11 +242,11 @@ static inline bool GfxPreprocessLine(DrawPixelInfo *dpi, int &x, int &y, int &x2 return true; } -void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width) +void GfxDrawLine(int x, int y, int x2, int y2, int colour, int width, int dash) { DrawPixelInfo *dpi = _cur_dpi; if (GfxPreprocessLine(dpi, x, y, x2, y2, width)) { - GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width); + GfxDoDrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, colour, width, dash); } } diff --git a/src/gfx_func.h b/src/gfx_func.h index 709fc2cc9..69d2e4570 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -118,7 +118,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, void DrawCharCentered(uint32 c, int x, int y, TextColour colour); void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE); -void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1); +void GfxDrawLine(int left, int top, int right, int bottom, int colour, int width = 1, int dash = 0); void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL); |