Changeset - r6985:c27a9a2405aa
[Not reviewed]
master
0 11 0
truelight - 17 years ago 2007-06-21 12:36:46
truelight@openttd.org
(svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
-Codechange: added CopyImageToBuffer, which produces a readable buffer for screenshots
-Fix: 32bpp-anim now holds animation on transparent objects to avoid strange graphical effects
-Fix: 32bpp-anim now works correct on mouse-movement (it holds the palette animation correctly)
11 files changed with 156 insertions and 63 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_anim.cpp
Show inline comments
 
@@ -70,24 +70,61 @@ void Blitter_32bppAnim::Draw(Blitter::Bl
 
						else               *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst);
 
						*anim = src->m;
 
					}
 
					break;
 
			}
 
			dst++;
 
			anim++;
 
			src += ScaleByZoom(1, zoom);
 
		}
 
	}
 
}
 

	
 
void Blitter_32bppAnim::DrawColorMappingRect(void *dst, int width, int height, int pal)
 
{
 
	uint32 *udst = (uint32 *)dst;
 
	uint8 *anim;
 

	
 
	anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr);
 

	
 
	if (pal == PALETTE_TO_TRANSPARENT) {
 
		do {
 
			for (int i = 0; i != width; i++) {
 
				*udst = MakeTransparent(*udst, 60);
 
				*anim = 0;
 
				udst++;
 
				anim++;
 
			}
 
			udst = udst - width + _screen.pitch;
 
			anim = anim - width + this->anim_buf_width;
 
		} while (--height);
 
		return;
 
	}
 
	if (pal == PALETTE_TO_STRUCT_GREY) {
 
		do {
 
			for (int i = 0; i != width; i++) {
 
				*udst = MakeGrey(*udst);
 
				*anim = 0;
 
				udst++;
 
				anim++;
 
			}
 
			udst = udst - width + _screen.pitch;
 
			anim = anim - width + this->anim_buf_width;
 
		} while (--height);
 
		return;
 
	}
 

	
 
	DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this color table ('%d')", pal);
 
}
 

	
 
void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 color)
 
{
 
	*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color);
 
	/* Set the color in the anim-buffer too */
 
	this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = color;
 
}
 

	
 
void Blitter_32bppAnim::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
 
{
 
	uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
 
	if (*dst == 0) {
 
		*dst = LookupColourInPalette(color);
 
@@ -110,24 +147,67 @@ void Blitter_32bppAnim::DrawRect(void *v
 
		for (int i = width; i > 0; i--) {
 
			*dst = color32;
 
			/* Set the color in the anim-buffer too */
 
			*anim = color;
 
			dst++;
 
			anim++;
 
		}
 
		video = (uint32 *)video + _screen.pitch;
 
		anim_line += this->anim_buf_width;
 
	} while (--height);
 
}
 

	
 
void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, int height)
 
{
 
	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
 
	uint32 *dst = (uint32 *)video;
 
	uint32 *usrc = (uint32 *)src;
 
	uint8 *anim_line;
 

	
 
	anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf;
 

	
 
	for (; height > 0; height--) {
 
		memcpy(dst, usrc, width * sizeof(uint32));
 
		usrc += width;
 
		dst += _screen.pitch;
 
		/* Copy back the anim-buffer */
 
		memcpy(anim_line, usrc, width * sizeof(uint8));
 
		usrc = (uint32 *)((uint8 *)usrc + width);
 
		anim_line += this->anim_buf_width;
 
	}
 

	
 
	/* We update the palette (or the pixels that do animation) immediatly, to avoid graphical glitches */
 
	this->PaletteAnimate(217, _use_dos_palette ? 38 : 28);
 
}
 

	
 
void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, int height)
 
{
 
	assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch);
 
	uint32 *udst = (uint32 *)dst;
 
	uint32 *src = (uint32 *)video;
 
	uint8 *anim_line;
 

	
 
	anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf;
 

	
 
	for (; height > 0; height--) {
 
		memcpy(udst, src, width * sizeof(uint32));
 
		src += _screen.pitch;
 
		udst += width;
 
		/* Copy the anim-buffer */
 
		memcpy(udst, anim_line, width * sizeof(uint8));
 
		udst = (uint32 *)((uint8 *)udst + width);
 
		anim_line += this->anim_buf_width;
 
	}
 
}
 

	
 
void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
 
{
 
	uint8 *dst, *src;
 

	
 
	/* We need to scroll the anim-buffer too */
 
	if (scroll_y > 0) {
 
		dst = this->anim_buf + left + (top + height - 1) * this->anim_buf_width;
 
		src = dst - scroll_y * this->anim_buf_width;
 

	
 
		/* Adjust left & width */
 
		if (scroll_x >= 0) dst += scroll_x;
 
		else               src -= scroll_x;
src/blitter/32bpp_anim.hpp
Show inline comments
 
@@ -13,27 +13,30 @@ private:
 
	uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
 
	int anim_buf_width;
 
	int anim_buf_height;
 

	
 
public:
 
	Blitter_32bppAnim() :
 
		anim_buf(NULL),
 
		anim_buf_width(0),
 
		anim_buf_height(0)
 
	{}
 

	
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 
	/* virtual */ void SetPixel(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 CopyFromBuffer(void *video, const void *src, int width, int height);
 
	/* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
 
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
 
	/* virtual */ void PaletteAnimate(uint start, uint count);
 
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
 
};
 

	
 
class FBlitter_32bppAnim: public BlitterFactory<FBlitter_32bppAnim> {
 
public:
 
	/* virtual */ const char *GetName() { return "32bpp-anim"; }
 
	/* virtual */ const char *GetDescription() { return "32bpp Animation Blitter (palette animation)"; }
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); }
 
};
 

	
src/blitter/32bpp_base.cpp
Show inline comments
 
@@ -72,61 +72,58 @@ void Blitter_32bppBase::DrawLine(void *v
 
		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 direction = (height < 0) ? -1 : 1;
 
	uint32 *dst = (uint32 *)video;
 
	uint32 *usrc = (uint32 *)src;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(dst, usrc, width * sizeof(uint32));
 
		usrc += src_pitch * direction;
 
		dst += _screen.pitch * direction;
 
		usrc += width;
 
		dst += _screen.pitch;
 
	}
 
}
 

	
 
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint32 *udst = (uint32 *)dst;
 
	uint32 *src = (uint32 *)video;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(udst, src, width * sizeof(uint32));
 
		src += _screen.pitch * direction;
 
		udst += dst_pitch * direction;
 
		src += _screen.pitch;
 
		udst += width;
 
	}
 
}
 

	
 
void Blitter_32bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
 
void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
{
 
	uint32 *dst = (uint32 *)video_dst;
 
	uint32 *src = (uint32 *)video_src;
 
	uint32 *udst = (uint32 *)dst;
 
	uint32 *src = (uint32 *)video;
 

	
 
	for (; height > 0; height--) {
 
		memmove(dst, src, width * sizeof(uint32));
 
		memcpy(udst, src, width * sizeof(uint32));
 
		src += _screen.pitch;
 
		dst += _screen.pitch;
 
		udst += dst_pitch;
 
	}
 
}
 

	
 
void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
 
{
 
	const uint32 *src;
 
	uint32 *dst;
 

	
 
	if (scroll_y > 0) {
 
		/*Calculate pointers */
 
		dst = (uint32 *)video + left + (top + height - 1) * _screen.pitch;
 
		src = dst - scroll_y * _screen.pitch;
 
@@ -137,48 +134,55 @@ void Blitter_32bppBase::ScrollBuffer(voi
 
		assert(height > 0);
 

	
 
		/* Adjust left & width */
 
		if (scroll_x >= 0) {
 
			dst += scroll_x;
 
			left += scroll_x;
 
			width -= scroll_x;
 
		} else {
 
			src -= scroll_x;
 
			width += scroll_x;
 
		}
 

	
 
		/* Negative height as we want to copy from bottom to top */
 
		this->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
 
		for (int h = height; h > 0; h--) {
 
			memcpy(dst, src, width * sizeof(uint32));
 
			src -= _screen.pitch;
 
			dst -= _screen.pitch;
 
		}
 
	} else {
 
		/* Calculate pointers */
 
		dst = (uint32 *)video + left + top * _screen.pitch;
 
		src = dst - scroll_y * _screen.pitch;
 

	
 
		/* Decrese height. (scroll_y is <=0). */
 
		height += scroll_y;
 
		assert(height > 0);
 

	
 
		/* Adjust left & width */
 
		if (scroll_x >= 0) {
 
			dst += scroll_x;
 
			left += scroll_x;
 
			width -= scroll_x;
 
		} else {
 
			src -= scroll_x;
 
			width += scroll_x;
 
		}
 

	
 
		/* the y-displacement may be 0 therefore we have to use memmove,
 
		 * because source and destination may overlap */
 
		this->MoveBuffer(dst, src, width, height);
 
		for (int h = height; h > 0; h--) {
 
			memmove(dst, src, width * sizeof(uint32));
 
			src += _screen.pitch;
 
			dst += _screen.pitch;
 
		}
 
	}
 
}
 

	
 
int Blitter_32bppBase::BufferSize(int width, int height)
 
{
 
	return width * height * sizeof(uint32);
 
}
 

	
 
void Blitter_32bppBase::PaletteAnimate(uint start, uint count)
 
{
 
	/* By default, 32bpp doesn't have palette animation */
 
}
src/blitter/32bpp_base.hpp
Show inline comments
 
@@ -9,27 +9,27 @@
 

	
 
class Blitter_32bppBase : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 32; }
 
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
//	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 
	/* virtual */ void *MoveTo(const void *video, int x, int y);
 
	/* virtual */ void SetPixel(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 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 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 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);
 
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
 
	/* virtual */ int BufferSize(int width, int height);
 
	/* virtual */ void PaletteAnimate(uint start, uint count);
 
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
 

	
 
	/**
 
	 * Compose a colour based on RGB values.
 
	 */
 
	static inline uint ComposeColour(uint a, uint r, uint g, uint b)
 
	{
 
		return (((a) << 24) & 0xFF000000) | (((r) << 16) & 0x00FF0000) | (((g) << 8) & 0x0000FF00) | ((b) & 0x000000FF);
 
	}
src/blitter/8bpp_base.cpp
Show inline comments
 
@@ -77,61 +77,57 @@ void Blitter_8bppBase::DrawLine(void *vi
 
		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 direction = (height < 0) ? -1 : 1;
 
	uint8 *dst = (uint8 *)video;
 
	uint8 *usrc = (uint8 *)src;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(dst, usrc, width);
 
		usrc += src_pitch * direction;
 
		dst += _screen.pitch * direction;
 
		memcpy(dst, usrc, width * sizeof(uint8));
 
		usrc += width;
 
		dst += _screen.pitch;
 
	}
 
}
 

	
 
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
 
{
 
	int direction = (height < 0) ? -1 : 1;
 
	uint8 *udst = (uint8 *)dst;
 
	uint8 *src = (uint8 *)video;
 

	
 
	height = abs(height);
 
	for (; height > 0; height--) {
 
		memcpy(udst, src, width);
 
		src += _screen.pitch * direction;
 
		udst += dst_pitch * direction;
 
		memcpy(udst, src, width * sizeof(uint8));
 
		src += _screen.pitch;
 
		udst += width;
 
	}
 
}
 

	
 
void Blitter_8bppBase::MoveBuffer(void *video_dst, const void *video_src, int width, int height)
 
void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
 
{
 
	uint8 *dst = (uint8 *)video_dst;
 
	uint8 *src = (uint8 *)video_src;
 
	uint8 *udst = (uint8 *)dst;
 
	uint8 *src = (uint8 *)video;
 

	
 
	for (; height > 0; height--) {
 
		memmove(dst, src, width);
 
		memcpy(udst, src, width * sizeof(uint8));
 
		src += _screen.pitch;
 
		dst += _screen.pitch;
 
		udst += dst_pitch;
 
	}
 
}
 

	
 
void Blitter_8bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
 
{
 
	const uint8 *src;
 
	uint8 *dst;
 

	
 
	if (scroll_y > 0) {
 
		/*Calculate pointers */
 
		dst = (uint8 *)video + left + (top + height - 1) * _screen.pitch;
 
		src = dst - scroll_y * _screen.pitch;
 
@@ -142,48 +138,55 @@ void Blitter_8bppBase::ScrollBuffer(void
 
		assert(height > 0);
 

	
 
		/* Adjust left & width */
 
		if (scroll_x >= 0) {
 
			dst += scroll_x;
 
			left += scroll_x;
 
			width -= scroll_x;
 
		} else {
 
			src -= scroll_x;
 
			width += scroll_x;
 
		}
 

	
 
		/* Negative height as we want to copy from bottom to top */
 
		this->CopyFromBuffer(dst, src, width, -height, _screen.pitch);
 
		for (int h = height; h > 0; h--) {
 
			memcpy(dst, src, width * sizeof(uint8));
 
			src -= _screen.pitch;
 
			dst -= _screen.pitch;
 
		}
 
	} else {
 
		/* Calculate pointers */
 
		dst = (uint8 *)video + left + top * _screen.pitch;
 
		src = dst - scroll_y * _screen.pitch;
 

	
 
		/* Decrese height. (scroll_y is <=0). */
 
		height += scroll_y;
 
		assert(height > 0);
 

	
 
		/* Adjust left & width */
 
		if (scroll_x >= 0) {
 
			dst += scroll_x;
 
			left += scroll_x;
 
			width -= scroll_x;
 
		} else {
 
			src -= scroll_x;
 
			width += scroll_x;
 
		}
 

	
 
		/* the y-displacement may be 0 therefore we have to use memmove,
 
		 * because source and destination may overlap */
 
		this->MoveBuffer(dst, src, width, height);
 
		for (int h = height; h > 0; h--) {
 
			memmove(dst, src, width * sizeof(uint8));
 
			src += _screen.pitch;
 
			dst += _screen.pitch;
 
		}
 
	}
 
}
 

	
 
int Blitter_8bppBase::BufferSize(int width, int height)
 
{
 
	return width * height;
 
}
 

	
 
void Blitter_8bppBase::PaletteAnimate(uint start, uint count)
 
{
 
	/* Video backend takes care of the palette animation */
 
}
src/blitter/8bpp_base.hpp
Show inline comments
 
@@ -9,22 +9,22 @@
 

	
 
class Blitter_8bppBase : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 8; }
 
//	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal);
 
//	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 
	/* virtual */ void *MoveTo(const void *video, int x, int y);
 
	/* virtual */ void SetPixel(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 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 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 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);
 
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
 
	/* virtual */ int BufferSize(int width, int height);
 
	/* virtual */ void PaletteAnimate(uint start, uint count);
 
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation();
 
};
 

	
 
#endif /* BLITTER_8BPP_BASE_HPP */
src/blitter/base.hpp
Show inline comments
 
@@ -112,46 +112,47 @@ public:
 
	 * @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.
 
	 * @param video The destionation pointer (video-buffer).
 
	 * @param src The buffer from which the data will be read.
 
	 * @param width The width of the buffer.
 
	 * @param height The height of the buffer.
 
	 * @param src_pitch The pitch (byte per line) of the source buffer.
 
	 * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!
 
	 */
 
	virtual void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) = 0;
 
	virtual void CopyFromBuffer(void *video, const void *src, int width, int height) = 0;
 

	
 
	/**
 
	 * Copy from the screen to a buffer.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param dst The buffer in which the data will be stored.
 
	 * @param width The width of the buffer.
 
	 * @param height The height of the buffer.
 
	 * @param dst_pitch The pitch (byte per line) of the destination buffer.
 
	 * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too!
 
	 */
 
	virtual void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
 
	virtual void CopyToBuffer(const void *video, void *dst, int width, int height) = 0;
 

	
 
	/**
 
	 * Move the videobuffer some places (via memmove).
 
	 * @param video_dst The destination pointer (video-buffer).
 
	 * @param video_src The source pointer (video-buffer).
 
	 * @param width The width of the buffer to move.
 
	 * @param height The height of the buffer to move.
 
	 * Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
 
	 * @param video The destination pointer (video-buffer).
 
	 * @param dst The buffer in which the data will be stored.
 
	 * @param width The width of the buffer.
 
	 * @param height The height of the buffer.
 
	 * @param dst_pitch The pitch (byte per line) of the destination buffer.
 
	 */
 
	virtual void MoveBuffer(void *video_dst, const void *video_src, int width, int height) = 0;
 
	virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
 

	
 
	/**
 
	 * Scroll the videobuffer some 'x' and 'y' value.
 
	 * @param video The buffer to scroll into.
 
	 * @param left The left value of the screen to scroll.
 
	 * @param top The top value of the screen to scroll.
 
	 * @param width The width of the screen to scroll.
 
	 * @param height The height of the screen to scroll.
 
	 * @param scroll_x How much to scroll in X.
 
	 * @param scroll_y How much to scroll in Y.
 
	 */
 
	virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) = 0;
src/blitter/null.hpp
Show inline comments
 
@@ -10,27 +10,27 @@
 

	
 
class Blitter_Null : public Blitter {
 
public:
 
	/* virtual */ uint8 GetScreenDepth() { return 0; }
 
	/* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) {};
 
	/* virtual */ void DrawColorMappingRect(void *dst, int width, int height, int pal) {};
 
	/* virtual */ Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator);
 
	/* virtual */ void *MoveTo(const void *video, int x, int y) { return NULL; };
 
	/* virtual */ void SetPixel(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 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 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 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) {};
 
	/* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) {};
 
	/* virtual */ int BufferSize(int width, int height) { return 0; };
 
	/* virtual */ void PaletteAnimate(uint start, uint count) { };
 
	/* virtual */ Blitter::PaletteAnimation UsePaletteAnimation() { return Blitter::PALETTE_ANIMATION_NONE; };
 
};
 

	
 
class FBlitter_Null: public BlitterFactory<FBlitter_Null> {
 
public:
 
	/* virtual */ const char *GetName() { return "null"; }
 
	/* virtual */ const char *GetDescription() { return "Null Blitter (does nothing)"; }
 
	/* virtual */ Blitter *CreateInstance() { return new Blitter_Null(); }
 
};
src/gfx.cpp
Show inline comments
 
@@ -827,25 +827,25 @@ void ScreenSizeChanged()
 
	if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
 
	if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
 

	
 
	/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
 
	_cursor.visible = false;
 
}
 

	
 
void UndrawMouseCursor()
 
{
 
	if (_cursor.visible) {
 
		Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
		_cursor.visible = false;
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
 
		_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 
	}
 
}
 

	
 
void DrawMouseCursor()
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	int x;
 
	int y;
 
	int w;
 
	int h;
 

	
 
@@ -874,25 +874,25 @@ void DrawMouseCursor()
 
	if (y < 0) {
 
		h += y;
 
		y = 0;
 
	}
 
	if (h > _screen.height - y) h = _screen.height - y;
 
	if (h <= 0) return;
 
	_cursor.draw_pos.y = y;
 
	_cursor.draw_size.y = h;
 

	
 
	assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
 

	
 
	/* Make backup of stuff below cursor */
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y, _cursor.draw_size.x);
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
 

	
 
	/* Draw cursor on screen */
 
	_cur_dpi = &_screen;
 
	DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y);
 

	
 
	_video_driver->make_dirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
 

	
 
	_cursor.visible = true;
 
	_cursor.dirty = false;
 
}
 

	
 
#if defined(_DEBUG)
src/screenshot.cpp
Show inline comments
 
@@ -476,25 +476,25 @@ const char *GetScreenshotFormatDesc(int 
 

	
 
void SetScreenshotFormat(int i)
 
{
 
	_cur_screenshot_format = i;
 
	strcpy(_screenshot_format_name, _screenshot_formats[i].extension);
 
}
 

	
 
/* screenshot generator that dumps the current video buffer */
 
static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
 
{
 
	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
 
	void *src = blitter->MoveTo(_screen.dst_ptr, 0, y);
 
	blitter->CopyToBuffer(src, buf, _screen.width, n, pitch);
 
	blitter->CopyImageToBuffer(src, buf, _screen.width, n, pitch);
 
}
 

	
 
/* generate a large piece of the world */
 
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
 
{
 
	ViewPort *vp = (ViewPort *)userdata;
 
	DrawPixelInfo dpi, *old_dpi;
 
	int wx, left;
 

	
 
	old_dpi = _cur_dpi;
 
	_cur_dpi = &dpi;
 

	
src/texteff.cpp
Show inline comments
 
@@ -46,25 +46,25 @@ struct TextMessage {
 
};
 

	
 
static TextEffect _text_effect_list[MAX_TEXT_MESSAGES];
 
static TextMessage _textmsg_list[MAX_CHAT_MESSAGES];
 
TileIndex _animated_tile_list[MAX_ANIMATED_TILES];
 

	
 
static bool _textmessage_dirty = false;
 
static bool _textmessage_visible = false;
 

	
 
/* The chatbox grows from the bottom so the coordinates are pixels from
 
 * the left and pixels from the bottom. The height is the maximum height */
 
static const Oblong _textmsg_box = {10, 30, 500, 150};
 
static uint8 _textmessage_backup[150 * 500 * 4]; // (height * width)
 
static uint8 _textmessage_backup[150 * 500 * 5]; // (height * width)
 

	
 
static inline uint GetTextMessageCount()
 
{
 
	uint i;
 

	
 
	for (i = 0; i < MAX_CHAT_MESSAGES; i++) {
 
		if (_textmsg_list[i].message[0] == '\0') break;
 
	}
 

	
 
	return i;
 
}
 

	
 
@@ -154,25 +154,25 @@ void UndrawTextMessage()
 
		int height = _textmsg_box.height;
 
		if (y < 0) {
 
			height = max(height + y, min(_textmsg_box.height, _screen.height));
 
			y = 0;
 
		}
 
		if (x + width >= _screen.width) {
 
			width = _screen.width - x;
 
		}
 
		if (width <= 0 || height <= 0) return;
 

	
 
		_textmessage_visible = false;
 
		/* Put our 'shot' back to the screen */
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 
		blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height);
 
		/* And make sure it is updated next time */
 
		_video_driver->make_dirty(x, y, width, height);
 

	
 
		_textmessage_dirty = true;
 
	}
 
}
 

	
 
/** Check if a message is expired every day */
 
void TextMessageDailyLoop()
 
{
 
	uint i;
 

	
 
@@ -214,26 +214,28 @@ void DrawTextMessage()
 
	int y      = _screen.height - _textmsg_box.y - _textmsg_box.height;
 
	int width  = _textmsg_box.width;
 
	int height = _textmsg_box.height;
 
	if (y < 0) {
 
		height = max(height + y, min(_textmsg_box.height, _screen.height));
 
		y = 0;
 
	}
 
	if (x + width >= _screen.width) {
 
		width = _screen.width - x;
 
	}
 
	if (width <= 0 || height <= 0) return;
 

	
 
	assert(blitter->BufferSize(width, height) < (int)sizeof(_textmessage_backup));
 

	
 
	/* Make a copy of the screen as it is before painting (for undraw) */
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height, _textmsg_box.width);
 
	blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _textmessage_backup, width, height);
 

	
 
	_cur_dpi = &_screen; // switch to _screen painting
 

	
 
	/* Paint a half-transparent box behind the text messages */
 
	GfxFillRect(
 
			_textmsg_box.x,
 
			_screen.height - _textmsg_box.y - count * 13 - 2,
 
			_textmsg_box.x + _textmsg_box.width - 1,
 
			_screen.height - _textmsg_box.y - 2,
 
			PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE) // black, but with some alpha for background
 
		);
 

	
0 comments (0 inline, 0 general)