OpenTTD
32bpp_anim.hpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef BLITTER_32BPP_ANIM_HPP
13 #define BLITTER_32BPP_ANIM_HPP
14 
15 #include "32bpp_optimized.hpp"
16 
19 protected:
20  uint16 *anim_buf;
21  void *anim_alloc;
26 
27 public:
29  anim_buf(NULL),
30  anim_alloc(NULL),
31  anim_buf_width(0),
32  anim_buf_height(0),
33  anim_buf_pitch(0)
34  {
35  this->palette = _cur_palette;
36  }
37 
39 
40  /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom);
41  /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal);
42  /* virtual */ void SetPixel(void *video, int x, int y, uint8 colour);
43  /* virtual */ void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash);
44  /* virtual */ void DrawRect(void *video, int width, int height, uint8 colour);
45  /* virtual */ void CopyFromBuffer(void *video, const void *src, int width, int height);
46  /* virtual */ void CopyToBuffer(const void *video, void *dst, int width, int height);
47  /* virtual */ void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y);
48  /* virtual */ int BufferSize(int width, int height);
49  /* virtual */ void PaletteAnimate(const Palette &palette);
51 
52  /* virtual */ const char *GetName() { return "32bpp-anim"; }
53  /* virtual */ int GetBytesPerPixel() { return 6; }
54  /* virtual */ void PostResize();
55 
59  inline Colour LookupColourInPalette(uint index)
60  {
61  return this->palette.palette[index];
62  }
63 
64  inline int ScreenToAnimOffset(const uint32 *video)
65  {
66  int raw_offset = video - (const uint32 *)_screen.dst_ptr;
67  if (_screen.pitch == this->anim_buf_pitch) return raw_offset;
68  int lines = raw_offset / _screen.pitch;
69  int across = raw_offset % _screen.pitch;
70  return across + (lines * this->anim_buf_pitch);
71  }
72 
73  template <BlitterMode mode> void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
74 };
75 
78 public:
79  FBlitter_32bppAnim() : BlitterFactory("32bpp-anim", "32bpp Animation Blitter (palette animation)") {}
80  /* virtual */ Blitter *CreateInstance() { return new Blitter_32bppAnim(); }
81 };
82 
83 #endif /* BLITTER_32BPP_ANIM_HPP */
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Colour LookupColourInPalette(uint index)
Look up the colour in the current palette.
Definition: 32bpp_anim.hpp:59
Information about the currently used palette.
Definition: gfx_type.h:309
void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
Draw a colourtable to the screen.
Definition: 32bpp_anim.cpp:274
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
Definition: gfx_type.h:310
void PostResize()
Post resize event.
Definition: 32bpp_anim.cpp:529
uint16 * anim_buf
In this buffer we keep track of the 8bpp indexes so we can do palette animation.
Definition: 32bpp_anim.hpp:20
int BufferSize(int width, int height)
Calculate how much memory there is needed for an image of this size in the video-buffer.
Definition: 32bpp_anim.cpp:483
void * anim_alloc
The raw allocated buffer, not necessarily aligned correctly.
Definition: 32bpp_anim.hpp:21
How all blitters should look like.
Definition: base.hpp:30
The optimised 32 bpp blitter with palette animation.
Definition: 32bpp_anim.hpp:18
void DrawRect(void *video, int width, int height, uint8 colour)
Make a single horizontal line in a single colour on the video-buffer.
Definition: 32bpp_anim.cpp:343
int anim_buf_height
The height of the animation buffer.
Definition: 32bpp_anim.hpp:23
Parameters related to blitting.
Definition: base.hpp:33
const char * GetName()
Get the name of the blitter, the same as the Factory-instance returns.
Definition: 32bpp_anim.hpp:52
int anim_buf_pitch
The pitch of the animation buffer (width rounded up to 16 byte boundary).
Definition: 32bpp_anim.hpp:24
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom)
Draw an image to the screen, given an amount of params defined above.
Definition: 32bpp_anim.cpp:256
Blitter * CreateInstance()
Create an instance of this Blitter-class.
Definition: 32bpp_anim.hpp:80
Palette _cur_palette
Current palette.
Definition: gfx.cpp:49
int GetBytesPerPixel()
Get how many bytes are needed to store a pixel.
Definition: 32bpp_anim.hpp:53
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
int anim_buf_width
The width of the animation buffer.
Definition: 32bpp_anim.hpp:22
Palette palette
The current palette.
Definition: 32bpp_anim.hpp:25
Factory for the 32bpp blitter with animation.
Definition: 32bpp_anim.hpp:77
void CopyToBuffer(const void *video, void *dst, int width, int height)
Copy from the screen to a buffer.
Definition: 32bpp_anim.cpp:410
Blitter::PaletteAnimation UsePaletteAnimation()
Check if the blitter uses palette animation at all.
Definition: 32bpp_anim.cpp:524
void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
Scroll the videobuffer some &#39;x&#39; and &#39;y&#39; value.
Definition: 32bpp_anim.cpp:432
void PaletteAnimate(const Palette &palette)
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
Definition: 32bpp_anim.cpp:488
Structure to access the alpha, red, green, and blue channels from a 32 bit number.
Definition: gfx_type.h:164
Optimized 32 bpp blitter.
BlitterMode
The modes of blitting we can do.
Definition: base.hpp:19
PaletteAnimation
Types of palette animation.
Definition: base.hpp:51
void SetPixel(void *video, int x, int y, uint8 colour)
Draw a pixel with a given colour on the video-buffer.
Definition: 32bpp_anim.cpp:315
void CopyFromBuffer(void *video, const void *src, int width, int height)
Copy from a buffer to the screen.
Definition: 32bpp_anim.cpp:370
The base factory, keeping track of all blitters.
Definition: factory.hpp:28
void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour, int width, int dash)
Draw a line with a given colour.
Definition: 32bpp_anim.cpp:325
The optimised 32 bpp blitter (without palette animation).