|
1 /* $Id$ */ |
|
2 |
|
3 #ifndef BLITTER_BASE_HPP |
|
4 #define BLITTER_BASE_HPP |
|
5 |
|
6 #include "../spritecache.h" |
|
7 #include "../spriteloader/spriteloader.hpp" |
|
8 |
|
9 enum BlitterMode { |
|
10 BM_NORMAL, |
|
11 BM_COLOUR_REMAP, |
|
12 BM_TRANSPARENT, |
|
13 }; |
|
14 |
|
15 /** |
|
16 * How all blitters should look like. Extend this class to make your own. |
|
17 */ |
|
18 class Blitter { |
|
19 public: |
|
20 struct BlitterParams { |
|
21 const void *sprite; ///< Pointer to the sprite how ever the encoder stored it |
|
22 const byte *remap; ///< XXX -- Temporary storage for remap array |
|
23 |
|
24 int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst) |
|
25 int width, height; ///< The width and height in pixels that needs to be drawn to dst |
|
26 int sprite_width; ///< Real width of the sprite |
|
27 int sprite_height; ///< Real height of the sprite |
|
28 int left, top; ///< The offset in the 'dst' in pixels to start drawing |
|
29 |
|
30 void *dst; ///< Destination buffer |
|
31 int pitch; ///< The pitch of the destination buffer |
|
32 }; |
|
33 |
|
34 typedef void *AllocatorProc(size_t size); |
|
35 |
|
36 /** |
|
37 * Get the screen depth this blitter works for. |
|
38 * This is either: 8, 16, 24 or 32. |
|
39 */ |
|
40 virtual uint8 GetScreenDepth() = 0; |
|
41 |
|
42 /** |
|
43 * Draw an image to the screen, given an amount of params defined above. |
|
44 */ |
|
45 virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0; |
|
46 |
|
47 /** |
|
48 * Draw a colortable to the screen. This is: the color of the screen is read |
|
49 * and is looked-up in the palette to match a new color, which then is put |
|
50 * on the screen again. |
|
51 * @param dst the destination pointer (video-buffer). |
|
52 * @param width the width of the buffer. |
|
53 * @param height the height of the buffer. |
|
54 * @param pal the palette to use. |
|
55 */ |
|
56 virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0; |
|
57 |
|
58 /** |
|
59 * Convert a sprite from the loader to our own format. |
|
60 */ |
|
61 virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0; |
|
62 |
|
63 /** |
|
64 * Move the destination pointer the requested amount x and y, keeping in mind |
|
65 * any pitch and bpp of the renderer. |
|
66 * @param video The destination pointer (video-buffer) to scroll. |
|
67 * @param x How much you want to scroll to the right. |
|
68 * @param y How much you want to scroll to the bottom. |
|
69 * @return A new destination pointer moved the the requested place. |
|
70 */ |
|
71 virtual void *MoveTo(const void *video, int x, int y) = 0; |
|
72 |
|
73 /** |
|
74 * Draw a pixel with a given color on the video-buffer. |
|
75 * @param video The destination pointer (video-buffer). |
|
76 * @param x The x position within video-buffer. |
|
77 * @param y The y position within video-buffer. |
|
78 * @param color A 8bpp mapping color. |
|
79 */ |
|
80 virtual void SetPixel(void *video, int x, int y, uint8 color) = 0; |
|
81 |
|
82 /** |
|
83 * Draw a pixel with a given color on the video-buffer if there is currently a black pixel. |
|
84 * @param video The destination pointer (video-buffer). |
|
85 * @param x The x position within video-buffer. |
|
86 * @param y The y position within video-buffer. |
|
87 * @param color A 8bpp mapping color. |
|
88 */ |
|
89 virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0; |
|
90 |
|
91 /** |
|
92 * Make a single horizontal line in a single color on the video-buffer. |
|
93 * @param video The destination pointer (video-buffer). |
|
94 * @param width The lenght of the line. |
|
95 * @param color A 8bpp mapping color. |
|
96 */ |
|
97 virtual void SetHorizontalLine(void *video, int width, uint8 color) = 0; |
|
98 |
|
99 /** |
|
100 * Copy from a buffer to the screen. |
|
101 * @param video The destionation pointer (video-buffer). |
|
102 * @param src The buffer from which the data will be read. |
|
103 * @param width The width of the buffer. |
|
104 * @param height The height of the buffer. |
|
105 * @param src_pitch The pitch (byte per line) of the source buffer. |
|
106 */ |
|
107 virtual void CopyFromBuffer(void *video, const void *src, int width, int height, int src_pitch) = 0; |
|
108 |
|
109 /** |
|
110 * Copy from the screen to a buffer. |
|
111 * @param video The destination pointer (video-buffer). |
|
112 * @param dst The buffer in which the data will be stored. |
|
113 * @param width The width of the buffer. |
|
114 * @param height The height of the buffer. |
|
115 * @param dst_pitch The pitch (byte per line) of the destination buffer. |
|
116 */ |
|
117 virtual void CopyToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0; |
|
118 |
|
119 /** |
|
120 * Move the videobuffer some places (via memmove). |
|
121 * @param video_dst The destination pointer (video-buffer). |
|
122 * @param video_src The source pointer (video-buffer). |
|
123 * @param width The width of the buffer to move. |
|
124 * @param height The height of the buffer to move. |
|
125 */ |
|
126 virtual void MoveBuffer(void *video_dst, const void *video_src, int width, int height) = 0; |
|
127 |
|
128 /** |
|
129 * Calculate how much memory there is needed for an image of this size in the video-buffer. |
|
130 * @param width The width of the buffer-to-be. |
|
131 * @param height The height of the buffer-to-be. |
|
132 * @return The size needed for the buffer. |
|
133 */ |
|
134 virtual int BufferSize(int width, int height) = 0; |
|
135 |
|
136 virtual ~Blitter() { } |
|
137 }; |
|
138 |
|
139 #endif /* BLITTER_BASE_HPP */ |