OpenTTD Source 20261123-master-g1c55c72fd0
base.hpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef BLITTER_BASE_HPP
11#define BLITTER_BASE_HPP
12
14
24
28class Blitter : public SpriteEncoder {
29public:
32 const void *sprite;
33 const uint8_t *remap;
34
37 int width;
38 int height;
41 int left;
42 int top;
43
44 void *dst;
45 int pitch;
46 };
47
49 enum class PaletteAnimation : uint8_t {
53 };
54
60 virtual uint8_t GetScreenDepth() = 0;
61
62 bool Is32BppSupported() override
63 {
64 return this->GetScreenDepth() > 8;
65 }
66
73 virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0;
74
84 virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) = 0;
85
94 virtual void *MoveTo(void *video, int x, int y) = 0;
95
103 virtual void SetPixel(void *video, int x, int y, PixelColour colour) = 0;
104
112 virtual void DrawRect(void *video, int width, int height, PixelColour colour) = 0;
113
127 virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash = 0) = 0;
128
137 virtual void CopyFromBuffer(void *video, const void *src, int width, int height) = 0;
138
147 virtual void CopyToBuffer(const void *video, void *dst, int width, int height) = 0;
148
157 virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0;
158
169 virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) = 0;
170
177 virtual size_t BufferSize(uint width, uint height) = 0;
178
184 virtual void PaletteAnimate(const Palette &palette) = 0;
185
191
196 virtual bool NeedsAnimationBuffer()
197 {
198 return false;
199 }
200
205 virtual std::string_view GetName() = 0;
206
210 virtual void PostResize() { };
211
212 template <typename SetPixelT> void DrawLineGeneric(int x, int y, int x2, int y2, int screen_width, int screen_height, int width, int dash, SetPixelT set_pixel);
213
214 template <typename T> static void MovePixels(const T *src, T *dst, size_t width, size_t height, ptrdiff_t pitch);
215};
216
217#endif /* BLITTER_BASE_HPP */
BlitterMode
The modes of blitting we can do.
Definition base.hpp:16
@ Transparent
Perform transparency darkening remapping.
Definition base.hpp:19
@ CrashRemap
Perform a crash remapping.
Definition base.hpp:21
@ BlackRemap
Perform remapping to a completely blackened sprite.
Definition base.hpp:22
@ Normal
Perform the simple blitting.
Definition base.hpp:17
@ TransparentRemap
Perform transparency colour remapping.
Definition base.hpp:20
@ ColourRemap
Perform a colour remapping.
Definition base.hpp:18
How all blitters should look like.
Definition base.hpp:28
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
virtual size_t BufferSize(uint width, uint height)=0
Calculate how much memory there is needed for an image of this size in the video-buffer.
virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, PixelColour colour, int width, int dash=0)=0
Draw a line with a given colour.
virtual bool NeedsAnimationBuffer()
Does this blitter require a separate animation buffer from the video backend?
Definition base.hpp:196
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
virtual void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)=0
Draw a colourtable to the screen.
virtual void SetPixel(void *video, int x, int y, PixelColour colour)=0
Draw a pixel with a given colour on the video-buffer.
virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)=0
Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp.
virtual void PaletteAnimate(const Palette &palette)=0
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)=0
Draw an image to the screen, given an amount of params defined above.
virtual std::string_view GetName()=0
Get the name of the blitter, the same as the Factory-instance returns.
bool Is32BppSupported() override
Can the sprite encoder make use of RGBA sprites?
Definition base.hpp:62
virtual void CopyToBuffer(const void *video, void *dst, int width, int height)=0
Copy from the screen to a buffer.
PaletteAnimation
Types of palette animation.
Definition base.hpp:49
@ None
No palette animation.
Definition base.hpp:50
@ VideoBackend
Palette animation should be done by video backend (8bpp only!).
Definition base.hpp:51
virtual void DrawRect(void *video, int width, int height, PixelColour colour)=0
Make a single horizontal line in a single colour on the video-buffer.
virtual void CopyFromBuffer(void *video, const void *src, int width, int height)=0
Copy from a buffer to the screen.
virtual void PostResize()
Post resize event.
Definition base.hpp:210
virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)=0
Scroll the videobuffer some 'x' and 'y' value.
Interface for something that can encode a sprite.
#define T
Climate temperate.
Definition engines.h:91
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
Base for loading sprites.
Parameters related to blitting.
Definition base.hpp:31
int skip_top
How much pixels of the source to skip on the top (based on zoom of dst).
Definition base.hpp:36
int sprite_height
Real height of the sprite.
Definition base.hpp:40
void * dst
Destination buffer.
Definition base.hpp:44
int left
The left offset in the 'dst' in pixels to start drawing.
Definition base.hpp:41
int pitch
The pitch of the destination buffer.
Definition base.hpp:45
int sprite_width
Real width of the sprite.
Definition base.hpp:39
int skip_left
How much pixels of the source to skip on the left (based on zoom of dst).
Definition base.hpp:35
int height
The height in pixels that needs to be drawn to dst.
Definition base.hpp:38
const uint8_t * remap
XXX – Temporary storage for remap array.
Definition base.hpp:33
int width
The width in pixels that needs to be drawn to dst.
Definition base.hpp:37
const void * sprite
Pointer to the sprite how ever the encoder stored it.
Definition base.hpp:32
int top
The top offset in the 'dst' in pixels to start drawing.
Definition base.hpp:42
Colour for pixel/line drawing.
Definition gfx_type.h:307
ZoomLevel
All zoom levels we know.
Definition zoom_type.h:20