Feature: Ctrl-click to remove fully autoreplaced vehicles from list (#9639)
[openttd-github.git] / src / blitter / 32bpp_anim.hpp
blob230b7e834215222b5e22206802f75071ff553869
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 <http://www.gnu.org/licenses/>.
6 */
8 /** @file 32bpp_anim.hpp A 32 bpp blitter with animation support. */
10 #ifndef BLITTER_32BPP_ANIM_HPP
11 #define BLITTER_32BPP_ANIM_HPP
13 #include "32bpp_optimized.hpp"
15 /** The optimised 32 bpp blitter with palette animation. */
16 class Blitter_32bppAnim : public Blitter_32bppOptimized {
17 protected:
18 uint16 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation
19 void *anim_alloc; ///< The raw allocated buffer, not necessarily aligned correctly
20 int anim_buf_width; ///< The width of the animation buffer.
21 int anim_buf_height; ///< The height of the animation buffer.
22 int anim_buf_pitch; ///< The pitch of the animation buffer (width rounded up to 16 byte boundary).
23 Palette palette; ///< The current palette.
25 public:
26 Blitter_32bppAnim() :
27 anim_buf(nullptr),
28 anim_alloc(nullptr),
29 anim_buf_width(0),
30 anim_buf_height(0),
31 anim_buf_pitch(0)
33 this->palette = _cur_palette;
36 ~Blitter_32bppAnim();
38 void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
39 void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) override;
40 void SetPixel(void *video, int x, int y, uint8 colour) override;
41 void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash) override;
42 void DrawRect(void *video, int width, int height, uint8 colour) override;
43 void CopyFromBuffer(void *video, const void *src, int width, int height) override;
44 void CopyToBuffer(const void *video, void *dst, int width, int height) override;
45 void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) override;
46 int BufferSize(int width, int height) override;
47 void PaletteAnimate(const Palette &palette) override;
48 Blitter::PaletteAnimation UsePaletteAnimation() override;
50 const char *GetName() override { return "32bpp-anim"; }
51 int GetBytesPerPixel() override { return 6; }
52 void PostResize() override;
54 /**
55 * Look up the colour in the current palette.
57 inline Colour LookupColourInPalette(uint index)
59 return this->palette.palette[index];
62 inline int ScreenToAnimOffset(const uint32 *video)
64 int raw_offset = video - (const uint32 *)_screen.dst_ptr;
65 if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
66 int lines = raw_offset / _screen.pitch;
67 int across = raw_offset % _screen.pitch;
68 return across + (lines * this->anim_buf_pitch);
71 template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
74 /** Factory for the 32bpp blitter with animation. */
75 class FBlitter_32bppAnim : public BlitterFactory {
76 public:
77 FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
78 Blitter *CreateInstance() override { return new Blitter_32bppAnim(); }
81 #endif /* BLITTER_32BPP_ANIM_HPP */