mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 02:19:41 +00:00
(svn r25911) -Add: Support for drawing dashed lines.
This commit is contained in:
parent
f528d2c592
commit
89b7afbac8
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
13
src/gfx.cpp
13
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user