richk@6720: /* $Id$ */ richk@6720: richk@6720: #ifndef BLITTER_BASE_HPP richk@6720: #define BLITTER_BASE_HPP richk@6720: richk@6720: #include "../spritecache.h" richk@6720: #include "../spriteloader/spriteloader.hpp" richk@6720: richk@6720: enum BlitterMode { richk@6720: BM_NORMAL, richk@6720: BM_COLOUR_REMAP, richk@6720: BM_TRANSPARENT, richk@6720: }; richk@6720: richk@6720: /** richk@6720: * How all blitters should look like. Extend this class to make your own. richk@6720: */ richk@6720: class Blitter { richk@6720: public: richk@6720: struct BlitterParams { richk@6720: const void *sprite; ///< Pointer to the sprite how ever the encoder stored it richk@6720: const byte *remap; ///< XXX -- Temporary storage for remap array richk@6720: richk@6720: int skip_left, skip_top; ///< How much pixels of the source to skip on the left and top (based on zoom of dst) richk@6720: int width, height; ///< The width and height in pixels that needs to be drawn to dst richk@6720: int sprite_width; ///< Real width of the sprite richk@6720: int sprite_height; ///< Real height of the sprite richk@6720: int left, top; ///< The offset in the 'dst' in pixels to start drawing richk@6720: richk@6720: void *dst; ///< Destination buffer richk@6720: int pitch; ///< The pitch of the destination buffer richk@6720: }; richk@6720: richk@6720: enum PaletteAnimation { richk@6720: PALETTE_ANIMATION_NONE, ///< No palette animation richk@6720: PALETTE_ANIMATION_VIDEO_BACKEND, ///< Palette animation should be done by video backend (8bpp only!) richk@6720: PALETTE_ANIMATION_BLITTER, ///< The blitter takes care of the palette animation richk@6720: }; richk@6720: richk@6720: typedef void *AllocatorProc(size_t size); richk@6720: richk@6720: /** richk@6720: * Get the screen depth this blitter works for. richk@6720: * This is either: 8, 16, 24 or 32. richk@6720: */ richk@6720: virtual uint8 GetScreenDepth() = 0; richk@6720: richk@6720: /** richk@6720: * Draw an image to the screen, given an amount of params defined above. richk@6720: */ richk@6720: virtual void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) = 0; richk@6720: richk@6720: /** richk@6720: * Draw a colortable to the screen. This is: the color of the screen is read richk@6720: * and is looked-up in the palette to match a new color, which then is put richk@6720: * on the screen again. richk@6720: * @param dst the destination pointer (video-buffer). richk@6720: * @param width the width of the buffer. richk@6720: * @param height the height of the buffer. richk@6720: * @param pal the palette to use. richk@6720: */ richk@6720: virtual void DrawColorMappingRect(void *dst, int width, int height, int pal) = 0; richk@6720: richk@6720: /** richk@6720: * Convert a sprite from the loader to our own format. richk@6720: */ richk@6720: virtual Sprite *Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) = 0; richk@6720: richk@6720: /** richk@6720: * Move the destination pointer the requested amount x and y, keeping in mind richk@6720: * any pitch and bpp of the renderer. richk@6720: * @param video The destination pointer (video-buffer) to scroll. richk@6720: * @param x How much you want to scroll to the right. richk@6720: * @param y How much you want to scroll to the bottom. richk@6720: * @return A new destination pointer moved the the requested place. richk@6720: */ richk@6720: virtual void *MoveTo(const void *video, int x, int y) = 0; richk@6720: richk@6720: /** richk@6720: * Draw a pixel with a given color on the video-buffer. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param x The x position within video-buffer. richk@6720: * @param y The y position within video-buffer. richk@6720: * @param color A 8bpp mapping color. richk@6720: */ richk@6720: virtual void SetPixel(void *video, int x, int y, uint8 color) = 0; richk@6720: richk@6720: /** richk@6720: * Draw a pixel with a given color on the video-buffer if there is currently a black pixel. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param x The x position within video-buffer. richk@6720: * @param y The y position within video-buffer. richk@6720: * @param color A 8bpp mapping color. richk@6720: */ richk@6720: virtual void SetPixelIfEmpty(void *video, int x, int y, uint8 color) = 0; richk@6720: richk@6720: /** richk@6720: * Make a single horizontal line in a single color on the video-buffer. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param width The lenght of the line. richk@6720: * @param color A 8bpp mapping color. richk@6720: */ richk@6720: virtual void DrawRect(void *video, int width, int height, uint8 color) = 0; richk@6720: richk@6720: /** richk@6720: * Draw a line with a given color. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param x The x coordinate from where the line starts. richk@6720: * @param y The y coordinate from where the line starts. richk@6720: * @param x2 The x coordinate to where the line goes. richk@6720: * @param y2 The y coordinate to where the lines goes. richk@6720: * @param screen_width The width of the screen you are drawing in (to avoid buffer-overflows). richk@6720: * @param screen_height The height of the screen you are drawing in (to avoid buffer-overflows). richk@6720: * @param color A 8bpp mapping color. richk@6720: */ richk@6720: virtual void DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) = 0; richk@6720: richk@6720: /** richk@6720: * Copy from a buffer to the screen. richk@6720: * @param video The destionation pointer (video-buffer). richk@6720: * @param src The buffer from which the data will be read. richk@6720: * @param width The width of the buffer. richk@6720: * @param height The height of the buffer. richk@6720: * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too! richk@6720: */ richk@6720: virtual void CopyFromBuffer(void *video, const void *src, int width, int height) = 0; richk@6720: richk@6720: /** richk@6720: * Copy from the screen to a buffer. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param dst The buffer in which the data will be stored. richk@6720: * @param width The width of the buffer. richk@6720: * @param height The height of the buffer. richk@6720: * @note You can not do anything with the content of the buffer, as the blitter can store non-pixel data in it too! richk@6720: */ richk@6720: virtual void CopyToBuffer(const void *video, void *dst, int width, int height) = 0; richk@6720: richk@6720: /** richk@6720: * Copy from the screen to a buffer in a palette format for 8bpp and RGBA format for 32bpp. richk@6720: * @param video The destination pointer (video-buffer). richk@6720: * @param dst The buffer in which the data will be stored. richk@6720: * @param width The width of the buffer. richk@6720: * @param height The height of the buffer. richk@6720: * @param dst_pitch The pitch (byte per line) of the destination buffer. richk@6720: */ richk@6720: virtual void CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) = 0; richk@6720: richk@6720: /** richk@6720: * Scroll the videobuffer some 'x' and 'y' value. richk@6720: * @param video The buffer to scroll into. richk@6720: * @param left The left value of the screen to scroll. richk@6720: * @param top The top value of the screen to scroll. richk@6720: * @param width The width of the screen to scroll. richk@6720: * @param height The height of the screen to scroll. richk@6720: * @param scroll_x How much to scroll in X. richk@6720: * @param scroll_y How much to scroll in Y. richk@6720: */ richk@6720: virtual void ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) = 0; richk@6720: richk@6720: /** richk@6720: * Calculate how much memory there is needed for an image of this size in the video-buffer. richk@6720: * @param width The width of the buffer-to-be. richk@6720: * @param height The height of the buffer-to-be. richk@6720: * @return The size needed for the buffer. richk@6720: */ richk@6720: virtual int BufferSize(int width, int height) = 0; richk@6720: richk@6720: /** richk@6720: * Called when the 8bpp palette is changed; you should redraw all pixels on the screen that richk@6720: * are equal to the 8bpp palette indexes 'start' to 'start + count'. richk@6720: * @param start The start index in the 8bpp palette. richk@6720: * @param count The amount of indexes that are (possible) changed. richk@6720: */ richk@6720: virtual void PaletteAnimate(uint start, uint count) = 0; richk@6720: richk@6720: /** richk@6720: * Check if the blitter uses palette animation at all. richk@6720: * @return True if it uses palette animation. richk@6720: */ richk@6720: virtual Blitter::PaletteAnimation UsePaletteAnimation() = 0; richk@6720: richk@6720: /** richk@6720: * Get the naem of the blitter, the same as the Factory-instance returns. richk@6720: */ richk@6720: virtual const char *GetName() = 0; richk@6720: richk@6720: virtual ~Blitter() { } richk@6720: }; richk@6720: richk@6720: #endif /* BLITTER_BASE_HPP */