diff options
author | frosch <frosch@openttd.org> | 2011-04-02 11:55:54 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-04-02 11:55:54 +0000 |
commit | 004c93f9da1be1f28528979d7ff940da3d089ab9 (patch) | |
tree | 4f955e5d1305e043325f6e64d0d5fc2efeae66ce /src/blitter | |
parent | a980319801448c9c8df2c4e819f5a9ba307f1ca2 (diff) | |
download | openttd-004c93f9da1be1f28528979d7ff940da3d089ab9.tar.xz |
(svn r22288) -Codechange: Deduplicate Blitter_8bppBase::DrawLine() and Blitter_32bppBase::DrawLine() into Blitter::DrawLine().
Diffstat (limited to 'src/blitter')
-rw-r--r-- | src/blitter/32bpp_base.cpp | 50 | ||||
-rw-r--r-- | src/blitter/32bpp_base.hpp | 1 | ||||
-rw-r--r-- | src/blitter/8bpp_base.cpp | 50 | ||||
-rw-r--r-- | src/blitter/8bpp_base.hpp | 1 | ||||
-rw-r--r-- | src/blitter/base.cpp | 74 | ||||
-rw-r--r-- | src/blitter/base.hpp | 13 |
6 files changed, 75 insertions, 114 deletions
diff --git a/src/blitter/32bpp_base.cpp b/src/blitter/32bpp_base.cpp index 23b42fa63..0499f5712 100644 --- a/src/blitter/32bpp_base.cpp +++ b/src/blitter/32bpp_base.cpp @@ -36,56 +36,6 @@ void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colou } while (--height); } -void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour) -{ - 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; - } - - if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour); - 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, colour); - } - } 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, colour); - } - } -} - void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height) { uint32 *dst = (uint32 *)video; diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index 79d097e80..8312b00a5 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -25,7 +25,6 @@ public: /* virtual */ void *MoveTo(const void *video, int x, int y); /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour); /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour); - /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour); /* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height); /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height); /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch); diff --git a/src/blitter/8bpp_base.cpp b/src/blitter/8bpp_base.cpp index 423b0604e..6371e3a8d 100644 --- a/src/blitter/8bpp_base.cpp +++ b/src/blitter/8bpp_base.cpp @@ -41,56 +41,6 @@ void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 colour } while (--height); } -void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour) -{ - 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; - } - - if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour); - 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, colour); - } - } 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, colour); - } - } -} - void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height) { uint8 *dst = (uint8 *)video; diff --git a/src/blitter/8bpp_base.hpp b/src/blitter/8bpp_base.hpp index 926d61739..c1e484679 100644 --- a/src/blitter/8bpp_base.hpp +++ b/src/blitter/8bpp_base.hpp @@ -23,7 +23,6 @@ public: /* virtual */ void *MoveTo(const void *video, int x, int y); /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour); /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour); - /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour); /* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height); /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height); /* virtual */ void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch); diff --git a/src/blitter/base.cpp b/src/blitter/base.cpp new file mode 100644 index 000000000..b18e9c87a --- /dev/null +++ b/src/blitter/base.cpp @@ -0,0 +1,74 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file base.cpp Implementation of the base for all blitters. */ + +#include "../stdafx.h" +#include "base.hpp" + +/** + * Draw a line with a given colour. + * @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 colour A 8bpp mapping colour. + */ +void Blitter::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour) +{ + 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; + } + + if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour); + 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, colour); + } + } 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, colour); + } + } +} diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp index 03898582c..3af376a15 100644 --- a/src/blitter/base.hpp +++ b/src/blitter/base.hpp @@ -101,18 +101,7 @@ public: */ virtual void DrawRect(void *video, int width, int height, uint8 colour) = 0; - /** - * Draw a line with a given colour. - * @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 colour A 8bpp mapping colour. - */ - virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour) = 0; + void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour); /** * Copy from a buffer to the screen. |