mirror of https://github.com/OpenTTD/OpenTTD
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
parent
c31ff284c3
commit
09879ea308
|
@ -32,6 +32,55 @@ void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 color
|
||||||
} while (--height);
|
} while (--height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color)
|
||||||
|
{
|
||||||
|
int dy;
|
||||||
|
int dx;
|
||||||
|
int stepx;
|
||||||
|
int stepy;
|
||||||
|
int frac;
|
||||||
|
|
||||||
|
dy = (y2 - y) * 2;
|
||||||
|
if (dy < 0) {
|
||||||
|
dy = -dy;
|
||||||
|
stepy = -1;
|
||||||
|
} else {
|
||||||
|
stepy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dx = (x2 - x) * 2;
|
||||||
|
if (dx < 0) {
|
||||||
|
dx = -dx;
|
||||||
|
stepx = -1;
|
||||||
|
} else {
|
||||||
|
stepx = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->SetPixel(video, x, y, color);
|
||||||
|
if (dx > dy) {
|
||||||
|
frac = dy - (dx / 2);
|
||||||
|
while (x != x2) {
|
||||||
|
if (frac >= 0) {
|
||||||
|
y += stepy;
|
||||||
|
frac -= dx;
|
||||||
|
}
|
||||||
|
x += stepx;
|
||||||
|
frac += dy;
|
||||||
|
if (x > 0 && y > 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
frac = dx - (dy / 2);
|
||||||
|
while (y != y2) {
|
||||||
|
if (frac >= 0) {
|
||||||
|
x += stepx;
|
||||||
|
frac -= dy;
|
||||||
|
}
|
||||||
|
y += stepy;
|
||||||
|
frac += dx;
|
||||||
|
if (x > 0 && y > 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
|
void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
|
||||||
{
|
{
|
||||||
int direction = (height < 0) ? -1 : 1;
|
int direction = (height < 0) ? -1 : 1;
|
||||||
|
|
|
@ -17,6 +17,7 @@ public:
|
||||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
|
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
|
||||||
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
|
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
|
||||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
|
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
|
||||||
|
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color);
|
||||||
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
|
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
|
||||||
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
|
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
|
||||||
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
|
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
|
||||||
|
|
|
@ -36,6 +36,56 @@ void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 color)
|
||||||
} while (--height);
|
} while (--height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color)
|
||||||
|
{
|
||||||
|
int dy;
|
||||||
|
int dx;
|
||||||
|
int stepx;
|
||||||
|
int stepy;
|
||||||
|
int frac;
|
||||||
|
|
||||||
|
dy = (y2 - y) * 2;
|
||||||
|
if (dy < 0) {
|
||||||
|
dy = -dy;
|
||||||
|
stepy = -1;
|
||||||
|
} else {
|
||||||
|
stepy = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dx = (x2 - x) * 2;
|
||||||
|
if (dx < 0) {
|
||||||
|
dx = -dx;
|
||||||
|
stepx = -1;
|
||||||
|
} else {
|
||||||
|
stepx = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->SetPixel(video, x, y, color);
|
||||||
|
if (dx > dy) {
|
||||||
|
frac = dy - (dx / 2);
|
||||||
|
while (x != x2) {
|
||||||
|
if (frac >= 0) {
|
||||||
|
y += stepy;
|
||||||
|
frac -= dx;
|
||||||
|
}
|
||||||
|
x += stepx;
|
||||||
|
frac += dy;
|
||||||
|
if (x > 0 && y > 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
frac = dx - (dy / 2);
|
||||||
|
while (y != y2) {
|
||||||
|
if (frac >= 0) {
|
||||||
|
x += stepx;
|
||||||
|
frac -= dy;
|
||||||
|
}
|
||||||
|
y += stepy;
|
||||||
|
frac += dx;
|
||||||
|
if (x > 0 && y > 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
|
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch)
|
||||||
{
|
{
|
||||||
int direction = (height < 0) ? -1 : 1;
|
int direction = (height < 0) ? -1 : 1;
|
||||||
|
|
|
@ -17,6 +17,7 @@ public:
|
||||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
|
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color);
|
||||||
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
|
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color);
|
||||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
|
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color);
|
||||||
|
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color);
|
||||||
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
|
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch);
|
||||||
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
|
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch);
|
||||||
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
|
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height);
|
||||||
|
|
|
@ -96,6 +96,19 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void DrawRect(void *video, int width, int height, uint8 color) = 0;
|
virtual void DrawRect(void *video, int width, int height, uint8 color) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a line with a given color.
|
||||||
|
* @param video The destination pointer (video-buffer).
|
||||||
|
* @param x The x coordinate from where the line starts.
|
||||||
|
* @param y The y coordinate from where the line starts.
|
||||||
|
* @param x2 The x coordinate to where the line goes.
|
||||||
|
* @param y2 The y coordinate to where the lines goes.
|
||||||
|
* @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 color A 8bpp mapping color.
|
||||||
|
*/
|
||||||
|
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy from a buffer to the screen.
|
* Copy from a buffer to the screen.
|
||||||
* @param video The destionation pointer (video-buffer).
|
* @param video The destionation pointer (video-buffer).
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color) {};
|
/* virtual */ void SetPixel(void *video, int x, int y, uint8 color) {};
|
||||||
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color) {};
|
/* virtual */ void SetPixelIfEmpty(void *video, int x, int y, uint8 color) {};
|
||||||
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color) {};
|
/* virtual */ void DrawRect(void *video, int width, int height, uint8 color) {};
|
||||||
|
/* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) {};
|
||||||
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) {};
|
/* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) {};
|
||||||
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
|
/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) {};
|
||||||
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height) {};
|
/* virtual */ void MoveBuffer(void *video_dst, const void *video_src, int width, int height) {};
|
||||||
|
|
80
src/gfx.cpp
80
src/gfx.cpp
|
@ -161,79 +161,23 @@ void GfxFillRect(int left, int top, int right, int bottom, int color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GfxSetPixel(int x, int y, int color)
|
|
||||||
{
|
|
||||||
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
|
||||||
const DrawPixelInfo *dpi = _cur_dpi;
|
|
||||||
|
|
||||||
if ((x -= dpi->left) < 0 || x >= dpi->width || (y -= dpi->top) < 0 || y >= dpi->height) return;
|
|
||||||
blitter->SetPixel(dpi->dst_ptr, x, y, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
||||||
{
|
{
|
||||||
int dy;
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
||||||
int dx;
|
DrawPixelInfo *dpi = _cur_dpi;
|
||||||
int stepx;
|
|
||||||
int stepy;
|
|
||||||
int frac;
|
|
||||||
|
|
||||||
/* Check clipping first */
|
x -= dpi->left;
|
||||||
{
|
x2 -= dpi->left;
|
||||||
DrawPixelInfo *dpi = _cur_dpi;
|
y -= dpi->top;
|
||||||
int t;
|
y2 -= dpi->top;
|
||||||
|
|
||||||
if (x < dpi->left && x2 < dpi->left) return;
|
/* Check clipping */
|
||||||
|
if (x < 0 && x2 < 0) return;
|
||||||
|
if (y < 0 && y2 < 0) return;
|
||||||
|
if (x > dpi->width && x2 > dpi->width) return;
|
||||||
|
if (y > dpi->height && y2 > dpi->height) return;
|
||||||
|
|
||||||
if (y < dpi->top && y2 < dpi->top) return;
|
blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color);
|
||||||
|
|
||||||
t = dpi->left + dpi->width;
|
|
||||||
if (x > t && x2 > t) return;
|
|
||||||
|
|
||||||
t = dpi->top + dpi->height;
|
|
||||||
if (y > t && y2 > t) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dy = (y2 - y) * 2;
|
|
||||||
if (dy < 0) {
|
|
||||||
dy = -dy;
|
|
||||||
stepy = -1;
|
|
||||||
} else {
|
|
||||||
stepy = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dx = (x2 - x) * 2;
|
|
||||||
if (dx < 0) {
|
|
||||||
dx = -dx;
|
|
||||||
stepx = -1;
|
|
||||||
} else {
|
|
||||||
stepx = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
GfxSetPixel(x, y, color);
|
|
||||||
if (dx > dy) {
|
|
||||||
frac = dy - (dx >> 1);
|
|
||||||
while (x != x2) {
|
|
||||||
if (frac >= 0) {
|
|
||||||
y += stepy;
|
|
||||||
frac -= dx;
|
|
||||||
}
|
|
||||||
x += stepx;
|
|
||||||
frac += dy;
|
|
||||||
GfxSetPixel(x, y, color);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
frac = dx - (dy >> 1);
|
|
||||||
while (y != y2) {
|
|
||||||
if (frac >= 0) {
|
|
||||||
x += stepx;
|
|
||||||
frac -= dy;
|
|
||||||
}
|
|
||||||
y += stepy;
|
|
||||||
frac += dx;
|
|
||||||
GfxSetPixel(x, y, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue